[JW Lua] Sample Script: Sys divider glyph change
Jari Williamsson
jari.williamsson at mailbox.swipnet.se
Tue Sep 9 11:18:24 CEST 2014
Hello All!
I'm attaching a script I did yesterday as a response to a user
suggestion. It replaces the standard system divider glyphs in a score
with some other divider glyph. I tested it with the 3 glyphs in the
SMuFL-compatible Bravura font. For Finale 2012 and later. If you're
using a non-Unicode font, it's probably easier to enter the character
slot as a decimal number.
See the attached picture for details.
Best regards,
Jari Williamsson
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sysdividerglyphchange.png
Type: image/png
Size: 267244 bytes
Desc: not available
URL: <http://jwmusic.nu/pipermail/jwlua_jwmusic.nu/attachments/20140909/68bde159/attachment.png>
-------------- next part --------------
function plugindef()
-- This function and the 'finaleplugin' namespace
-- are both reserved for the plug-in definition.
finaleplugin.MinFinaleVersion = "2012"
finaleplugin.Author = "Jari Williamsson"
finaleplugin.Version = "1.01"
finaleplugin.Date = "September 09, 2014"
return "System Divider: Change Glyph", "Sys Divider: Change Glyph", "Replaces standard Score System Dividers with other glyphs."
end
if finenv.FinaleVersion < 2012 then
print ("Finale 2012 or later versions are required for Unicode features.")
return
end
-- Display dialog box
local dialog = finenv.UserValueInput()
dialog.Title = "System Divider: Change Glyph"
dialog:SetDescriptions("Font Name:", "Font Size (in points):", "Character slot (use U+ for Unicode):", "Vertical Adjustment:")
dialog:SetTypes("String", "Number", "String", "Measurement")
dialog:SetInitValues("", 24, "U+0000", 0)
local dlgresult = dialog:Execute()
if not dlgresult then return end
-- Check that the values are ok:
local fontname = dlgresult[1]
if fontname == "" then
print("Error: A font name must be supplied.")
return
end
local fontsize = dlgresult[2]
if fontsize < 6 or fontsize > 72 then
print("Error: The font size is out of range.")
return
end
local charslot = dlgresult[3]
local vertadjustment = dlgresult[4]
-- Convert the character slot:
local charnumber = 0
local str = finale.FCString()
str.LuaString = charslot
if str:StartsWith("U+") then
-- Unicode as hexadecimal
str:DeleteCharactersAt(0, 2)
charnumber = str:GetHex()
else
-- Character slot as digit
charnumber = str:GetInteger()
end
if charnumber <= 0 then
print ("Illegal character number: ", charslot)
return
end
-- Function: Return true if str contains a system divider raw string.
function ModifyDividerString(str)
-- Create a string copy to work on:
local teststring = finale.FCString()
teststring:SetString(str)
-- Get the font info for the Enigma text:
local fontinfo = teststring:CreateLastFontInfo()
-- Remove all Enigma font info from the raw string:
teststring:TrimEnigmaTags()
-- Check that it's a System Divider character in the string:
if teststring.Length ~= 1 then return false end
if teststring:GetItemAt(0) ~= 187 then return false end
-- Check for 2 versions of the font name:
if (fontinfo.Name ~= "EngraverFontSet") and (fontinfo.Name ~= "Engraver Font Set") then return false end
-- Change the font info:
fontinfo.Name = fontname
fontinfo.Size = fontsize
-- Create new Enigma string info:
local newstring = fontinfo:CreateEnigmaString(nil)
-- Append the new character:
newstring:AppendCharacter(charnumber)
-- Copy back and return:
str:SetString(newstring)
return true
end
-- Process the text blocks:
local counter = 0
local scorepart = finale.FCPart(finale.PARTID_SCORE)
scorepart:SwitchTo()
local texts = finale.FCPageTexts()
texts:LoadAll()
for t in each(texts) do
local str = t:CreateTextString()
if ModifyDividerString(str) then
-- Resave the modified raw string:
t:SaveTextString(str)
-- Save the adjusted vertical position:
t.VerticalPos = t.VerticalPos + vertadjustment
t.VerticalPosRightPage = t.VerticalPosRightPage + vertadjustment
t:Save()
counter = counter + 1
end
end
scorepart:SwitchBack()
-- Display a message box to user:
if counter == 0 then
finenv.UI():AlertError("No standard system dividers were found in the document.", "No Dividers Found")
else
local msg = "" .. counter .. " system divider(s) replaced."
finenv.UI():AlertInfo(msg, "System Dividers Replaced")
end
More information about the JWLua
mailing list