[JW Lua] Copy/Paste With FCMusicRegion()
Robert Patterson
robert at robertgpatterson.com
Tue Dec 15 16:34:26 CET 2020
Before doing your work, make a copy of the current sel region (if any).
Then restore it using sel_region::SetInDocument().
On Tue, Dec 15, 2020 at 5:30 AM Martin Marris <mmarris at notecraft.com> wrote:
> Hi Robert,
>
>
>
> Problem solved.
>
>
>
> You have to specify the source and destination **staves** not just the
> measures. This seems obvious but I had overlooked it. (Perhaps it is only
> necessary if there is more than one staff; I have not checked.)
>
>
>
> Also staff and measure numbers must be valid. Otherwise you will get that
> same strange error Message Box I mentioned before, about a missing TMP file
> (instead of an error message in the console).
>
>
>
> After copying from one staff to another, you must also change the clef, if
> the destination instrument uses a different one. Other instrument-specific
> data of the destination staff, such as the default transposition of the
> destination staff, seem to be preserved -- which is excellent.
>
>
>
> After the script has run, the last-defined MusicRegion remains highlighted
> in blue. I have not yet figured out how to de-highlight it programmatically.
>
>
>
> We are now “cooking with gas.” The easy copying of music between staves,
> programmatically and not via human user selection, is at the heart of what
> I am trying to do, on a massive scale.
>
>
>
> Thanks for your help! Example script (this one has almost no validity
> checking, it is just a proof of concept):
>
>
>
> local musicregion = finale.FCMusicRegion()
>
>
>
> --copy music from source (Flute) staff
>
> musicregion:SetStartStaff(1)
>
> musicregion:SetEndStaff(1)
>
> musicregion:SetStartMeasure(1)
>
> musicregion:SetEndMeasure(16)
>
> musicregion:CopyMusic()
>
>
>
> --set the destination (Bassoon) staff region
>
> musicregion:SetStartStaff(3)
>
> musicregion:SetEndStaff(3)
>
> musicregion:SetStartMeasure(1)
>
> musicregion:SetEndMeasure(16)
>
>
>
> --get the original clef index of the destination instrument (Bassoon)
>
> local cell = finale.FCCell(1, 3)
>
> local clefIndex = cell:CalcClefIndexAt(0)
>
>
>
> --paste music into destination staff
>
> musicregion:PasteMusic()
>
>
>
> --change the clef of the pasted music to bassoon clef (BC) index 3
>
> local cells = finale.FCCells()
>
> cells:ApplyRegion(musicregion)
>
> for cell in each(cells) do
>
> local cellFrameHold = finale.FCCellFrameHold()
>
> cellFrameHold:ConnectCell(cell)
>
> if cellFrameHold:Load() then
>
> cellFrameHold.ClefIndex = clefIndex
>
> cellFrameHold:Save()
>
> end
>
> end
>
>
>
> --release the music
>
> musicregion:ReleaseMusic()
>
> -- I thought the following might de-highlight the blue region but it does
> not
>
> musicregion:SetInDocument()
>
>
>
> Martin
>
>
>
> *From:* JWLua <jwlua-bounces at jwmusic.nu> *On Behalf Of *Robert Patterson
> *Sent:* Monday, December 14, 2020 20:11
> *To:* The JW Lua script plug-in. <jwlua at jwmusic.nu>
> *Subject:* Re: [JW Lua] Copy/Paste With FCMusicRegion()
>
>
>
> I don't know what you are planning to do, but transferring the notes
> individually is possible. It is also potentially quite complicated. In
> addition to notes, you have to copy all the other stuff in the Mass Edit
> filter window. (Or as much of it as you need.) If you go that route, you
> will know Finale programming inside and out by the end of the project.
>
>
>
> On Mon, Dec 14, 2020 at 2:07 PM Martin Marris <mmarris at notecraft.com>
> wrote:
>
> Thanks Robert. So close, yet so far.
>
>
>
> Will investigate.
>
>
>
> Meanwhile: I assume the other way to copy/paste is to bypass the Region
> approach altogether and to use note cells instead. I have messed around
> with several alternatives but got nowhere, but what do I know?
>
>
>
> Martin
>
>
>
> *From:* JWLua <jwlua-bounces at jwmusic.nu> *On Behalf Of *Robert Patterson
> *Sent:* Monday, December 14, 2020 20:00
> *To:* The JW Lua script plug-in. <jwlua at jwmusic.nu>
> *Subject:* Re: [JW Lua] Copy/Paste With FCMusicRegion()
>
>
>
> Unfortunately, this may be a bug in either JW Lua or Finale. It may also
> be limited to Windows Finale. I have no personal experience with it,
> because I have never used the underlying API calls in the PDK. It is
> unfortunate that the PDK Framework does not provide a way to call the
> Copy/Paste menu items in the Edit menu. This is what I would do if
> programming directly to the PDK. (I don't trust the Copy/Paste APIs because
> I don't think they get much use, and they use clip files.)
>
>
>
> You could try creating the directory it wants to write the clip files in.
> Maybe that would help. IDK.
>
>
>
>
>
> On Mon, Dec 14, 2020 at 1:47 PM Martin Marris <mmarris at notecraft.com>
> wrote:
>
> Hi Robert,
>
>
>
> Do you mean like this? It’s not working, I get a variant of the same
> message box error notification:
>
>
>
> local musicregion = finale.FCMusicRegion()
>
>
>
> musicregion.StartMeasure = 1
>
> musicregion.EndMeasure = 2
>
> musicregion:SetInDocument()
>
> musicregion:CopyMusic()
>
>
>
> musicregion.StartMeasure = 3
>
> musicregion.EndMeasure = 4
>
> musicregion:SetInDocument()
>
> musicregion:PasteMusic()
>
>
>
> musicregion:ReleaseMusic()
>
>
>
> Martin
>
>
>
> *From:* JWLua <jwlua-bounces at jwmusic.nu> *On Behalf Of *Robert Patterson
> *Sent:* Monday, December 14, 2020 19:36
> *To:* The JW Lua script plug-in. <jwlua at jwmusic.nu>
> *Subject:* Re: [JW Lua] Copy/Paste With FCMusicRegion()
>
>
>
> Try calling musicregion:SetInDocument() after setting the start and end
> measures (both times).
>
>
>
> On Mon, Dec 14, 2020 at 1:18 PM Martin Marris <mmarris at notecraft.com>
> wrote:
>
> I am trying to create a Region programmatically (rather than through user
> interaction).
>
>
>
> Then, copy/paste between regions.
>
>
>
> But if I run the following simple script:
>
>
>
> local musicregion = finale.FCMusicRegion()
>
> musicregion.StartMeasure = 1
>
> musicregion.EndMeasure = 2
>
> musicregion:CopyMusic()
>
> musicregion.StartMeasure = 3
>
> musicregion.EndMeasure = 4
>
> musicregion:PasteMusic()
>
> musicregion:ReleaseMusic()
>
>
>
> I get this result:
>
>
>
> Message box: Title “Finale” and text “Cannot read library
> c:\users\myusername\AppDate\LocalLow\Fin33B.tmp”.
>
>
>
> Why?
>
>
>
> Martin
>
>
>
> _______________________________________________
> JWLua mailing list
> JWLua at jwmusic.nu
> http://jwmusic.nu/mailman/listinfo/jwlua_jwmusic.nu
>
> _______________________________________________
> JWLua mailing list
> JWLua at jwmusic.nu
> http://jwmusic.nu/mailman/listinfo/jwlua_jwmusic.nu
>
> _______________________________________________
> JWLua mailing list
> JWLua at jwmusic.nu
> http://jwmusic.nu/mailman/listinfo/jwlua_jwmusic.nu
>
> _______________________________________________
> JWLua mailing list
> JWLua at jwmusic.nu
> http://jwmusic.nu/mailman/listinfo/jwlua_jwmusic.nu
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://jwmusic.nu/pipermail/jwlua_jwmusic.nu/attachments/20201215/ce896c57/attachment.htm>
More information about the JWLua
mailing list