User Tools

Site Tools


jwlua:quickscripts

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
jwlua:quickscripts [2014/09/01 11:24]
jariw [Move TAB Numbers]
jwlua:quickscripts [2015/07/13 18:07] (current)
jariw [Swap Metatool Key Assignment]
Line 739: Line 739:
         end    ​         end    ​
     end     end
 +end</​code>​
 +
 +----
 +
 +==== Using Unicode ====
 +
 +JW Lua supports Unicode for Finale 2012 and above (as long as the font supports it). Umlauts, cyrillic text, Japanese characters, etc can be mixed with traditional western characters.
 +
 +This sample script sets the composer text insert to include both a cyrillic and western version of the composer'​s name.
 +
 +This script requires beta 0.27 or later.
 +
 +<code lua cyrillictext.lua>​-- Assure that the script exits directly on pre-2012 Finale versions:
 +if finenv.FinaleVersion < 2012 then return end
 +
 +--Set composer text to use both cyrillic and western version
 +-- of the composer'​s name. Put a new line character between.
 +local str = finale.FCString()
 +str.LuaString = "​Сергей Прокофьев\r(Sergei Prokofiev)"​
 +
 +-- Set an save the text insert:
 +local fileinfotext = finale.FCFileInfoText()
 +fileinfotext:​SetText(str)
 +fileinfotext:​SaveAsComposer()</​code>​
 +
 +----
 +
 +==== Align Repeat Brackets ====
 +
 +The following script example aligns the top lines of the repeat brackets within the selected region to the topmost position. It does not look at staves with independently moved bracket positioning.
 +
 +All ending repeat brackets and backward repeat brackets are first scanned for the highest vertical position. The initial "​highest position"​ is set to a extremely low value, to make sure that a true top position is found. After that, all the brackets are set to the highest vertical position found.
 +
 +The script requires beta 0.29 or higher.
 +
 +<code lua alignrepeatbrackets.lua>​local region = finenv.Region()
 +if region:​IsEmpty() then return end
 +
 +-- Scan to find the highest bracket position in the selected measures:
 +local highest = -10000
 +local count = 0
 +for m = region.StartMeasure,​ region.EndMeasure do
 +    local endingrepeat = finale.FCEndingRepeat()
 +    local backwardrepeat = finale.FCBackwardRepeat()
 +    if endingrepeat:​Load(m) then
 +        if endingrepeat.VerticalTopBracketPosition > highest then
 +            highest = endingrepeat.VerticalTopBracketPosition
 +        end
 +        count = count + 1
 +    end
 +    if backwardrepeat:​Load(m) then
 +        if backwardrepeat.TopBracketPosition > highest then
 +            highest = backwardrepeat.TopBracketPosition
 +        end
 +        count = count + 1
 +    end
 +end
 +
 +if count > 1 then
 +    -- Set the new bracket positions:
 +    for m = region.StartMeasure,​ region.EndMeasure do
 +        local endingrepeat = finale.FCEndingRepeat()
 +        local backwardrepeat = finale.FCBackwardRepeat()
 +        if endingrepeat:​Load(m) then
 +            endingrepeat.VerticalTopBracketPosition = highest
 +            endingrepeat:​Save()
 +        end
 +        if backwardrepeat:​Load(m) then
 +            backwardrepeat.TopBracketPosition = highest
 +            backwardrepeat:​Save()
 +        end
 +    end
 +end</​code>​
 +
 +----
 +
 +==== Swap Metatool Key Assignment ====
 +
 +The following script swaps the expression metatool keyboard assignments for the keys '​1'​ and '​2'​. Metatools are saved to the (ASCII) key number, and the Lua ''​string.byte()''​ function is used to find the key number. Simply resaving to the other key number will do a swap of the metatool keys. Beta version 0.40 or later is required for this sample code.
 +
 +<code lua swapmetatools.lua>​-- Load all existing metatool assignments for the Expression Tool
 +local mas = finale.FCMetatoolAssignments()
 +mas:​LoadAllForMode(finale.MTOOLMODE_EXPRESSION)
 +-- Find the current expression metatools for keyboard keys '​1'​ and '​2'​
 +metatool1 = mas:​FindKeystroke(string.byte("​1"​))
 +metatool2 = mas:​FindKeystroke(string.byte("​2"​))
 +-- Swap the keyboard mapping for these 2 objects
 +if (metatool1 ~= nil) then
 +    metatool1:​SaveAsKeystroke(string.byte("​2"​))
 +end
 +if (metatool2 ~= nil) then
 +    metatool2:​SaveAsKeystroke(string.byte("​1"​))
 end</​code>​ end</​code>​
  
  
 ---- ----
jwlua/quickscripts.1409570676.txt.gz · Last modified: 2014/09/01 11:24 by jariw