[JW Lua] FCPageTexts - Retrieve Item at a specific index
Finale at web.yosound.com
Finale at web.yosound.com
Fri Nov 28 22:03:01 CET 2014
Hi Jari,
I am trying to iterate through all of the Page Text items in order to either
update them or add them if they are missing in a document. This is in order
to give a standard look to all the charts I write for my big band. I think
what I should be using is GetItemAt, but am stuck trying to implement it.
My process is to first iterate through all of them and modify a table with a
flag to indicate that it exists by inserting an ID. I thought that ItemCmper
and ItemInci were what I should use, but was wondering if there is an easier
way. Here is the code I'm using to modify existing entries:
-- Table of Page Text links.
-- Each record consists of:
-- [1] - Textinsert Start
-- [2] - First Page
-- [3] - Record ID, -1 for missing
-- [4] - Subrecord ID
-- [5] - LineSpacingIsPercent
-- The index values are included only to reduce the risk of errors.
local PageTextLinks =
{
[2] = {"^title()",1,-1,-1,true},
[3] = {"^subtitle()",1,-1,-1,true},
[4] = {"^partname()",1,-1,-1,true},
[5] = {"^composer()",1,-1,-1,false},
[6] = {"^lyricist()",1,-1,-1,true},
[7] = {"^arranger()",1,-1,-1,true},
[8] = {"^copyright()",1,-1,-1},false,
[9] = {"^title()",2,-1,-1,true},
[10] = {"^partname()",2,-1,-1,true},
[11] = {"^page(0)",2,-1,-1,true},
[12] = {"^partname()",2,-1,-1,true},
[13] = {"^title()",2,-1,-1,true},
}
-- Set the line spacing
pagetexts = finale.FCPageTexts()
pagetexts:LoadAll()
pagetext = pagetexts:GetItemAt(PageTextLinks[idx][4] + 2 *
PageTextLinks[idx][3], PageTextLinks[idx][3])
local TextString = pagetext:CreateTextString()
FontInfo = TextString:CreateLastFontInfo()
local TextBlock = pagetext:CreateTextBlock()
print (TextString.LuaString)
if not PageTextLinks[idx][5] then
print (" Change Line Spacing", not PageTextLinks[idx][5],
"Index", idx)
TextBlock.LineSpacingIsPercent = false
TextBlock.LineSpacing = FontInfo.Size * 4
TextBlock:Save()
end
-- Modify the PageText
TextString.LuaString = k
print("Existing Item", TextString.LuaString)
pagetext:SaveNewTextBlock(TextString)
set_data(pagetext, v)
pagetext:Save()
The first issue is that I can't start at Index 1 because it gives me an
indexing error. I'm probably referencing the table incorrectly but don't
know the right syntax apparently. I was unable to get any help from the Lua
documentation on this. What am I doing wrong?
The second issue is when I then start adding new items, that the indices
seem to change, so they get added using the wrong information because the
indexes have shifted.
Here's the code for that part:
-- New
if PageTextLinks[idx][3] == -1 then
local new_item = finale.FCPageText()
local str = new_item:CreateTextString()
str.LuaString = k
print("New Item", str.LuaString)
new_item:SaveNewTextBlock(str)
set_data(new_item, v)
new_item:SaveNew(1)
So that now the pairs iteration seems to get lost and only some of the
missing items get added. What am I doing wrong?
Here is the whole code block for the final pass:
local idx = 2
for k, v in pairs(PageTextData) do
-- New
if PageTextLinks[idx][3] == -1 then
local new_item = finale.FCPageText()
local str = new_item:CreateTextString()
str.LuaString = k
print("New Item", str.LuaString)
new_item:SaveNewTextBlock(str)
set_data(new_item, v)
new_item:SaveNew(1)
-- Existing
else
-- Set the line spacing
pagetexts = finale.FCPageTexts()
pagetexts:LoadAll()
pagetext = pagetexts:GetItemAt(PageTextLinks[idx][4] + 2 *
PageTextLinks[idx][3], PageTextLinks[idx][3])
local TextString = pagetext:CreateTextString()
FontInfo = TextString:CreateLastFontInfo()
local TextBlock = pagetext:CreateTextBlock()
print (TextString.LuaString)
if not PageTextLinks[idx][5] then
print (" Change Line Spacing", not PageTextLinks[idx][5],
"Index", idx)
TextBlock.LineSpacingIsPercent = false
TextBlock.LineSpacing = FontInfo.Size * 4
TextBlock:Save()
end
-- Modify the PageText
TextString.LuaString = k
print("Existing Item", TextString.LuaString)
pagetext:SaveNewTextBlock(TextString)
set_data(pagetext, v)
pagetext:Save()
end
-- pagetexts:SaveAll()
idx = idx + 1
end
Thanks so much for any light you can shed on the error in my ways.
Bruce
--
Olson Sound Design, LLC
Bruce C. Olson
8717 Humboldt Avenue North
Brooklyn Park, MN 55444-1320
+1 (763) 493-5835 Office
+1 (763) 300-3893 Cell
Web Page: http://www.OlsonSound.com
Business: mailto:BCOlson at OlsonSound.com
Big Band: http://www.BRBB.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://jwmusic.nu/pipermail/jwlua_jwmusic.nu/attachments/20141128/6e90f5c4/attachment.htm>
More information about the JWLua
mailing list