<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=us-ascii"><meta name=Generator content="Microsoft Word 14 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Tahoma;
panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
p.Comments, li.Comments, div.Comments
{mso-style-name:Comments;
mso-style-link:"Comments Char";
margin:0in;
margin-bottom:.0001pt;
border:none;
padding:0in;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
color:#E36C0A;}
span.CommentsChar
{mso-style-name:"Comments Char";
mso-style-link:Comments;
font-family:"Calibri","sans-serif";
color:#E36C0A;}
span.EmailStyle19
{mso-style-type:personal-compose;
font-family:"Calibri","sans-serif";
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri","sans-serif";}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-US link=blue vlink=purple><div class=WordSection1><p class=MsoNormal>Hi Jari,<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>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.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>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:<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>-- Table of Page Text links. <o:p></o:p></p><p class=MsoNormal>-- Each record consists of:<o:p></o:p></p><p class=MsoNormal>-- [1] - Textinsert Start<o:p></o:p></p><p class=MsoNormal>-- [2] - First Page<o:p></o:p></p><p class=MsoNormal>-- [3] - Record ID, -1 for missing <o:p></o:p></p><p class=MsoNormal>-- [4] - Subrecord ID<o:p></o:p></p><p class=MsoNormal>-- [5] - LineSpacingIsPercent<o:p></o:p></p><p class=MsoNormal>-- The index values are included only to reduce the risk of errors.<o:p></o:p></p><p class=MsoNormal>local PageTextLinks =<o:p></o:p></p><p class=MsoNormal>{ <o:p></o:p></p><p class=MsoNormal> [2] = {"^title()",1,-1,-1,true},<o:p></o:p></p><p class=MsoNormal> [3] = {"^subtitle()",1,-1,-1,true},<o:p></o:p></p><p class=MsoNormal> [4] = {"^partname()",1,-1,-1,true},<o:p></o:p></p><p class=MsoNormal> [5] = {"^composer()",1,-1,-1,false},<o:p></o:p></p><p class=MsoNormal> [6] = {"^lyricist()",1,-1,-1,true},<o:p></o:p></p><p class=MsoNormal> [7] = {"^arranger()",1,-1,-1,true},<o:p></o:p></p><p class=MsoNormal> [8] = {"^copyright()",1,-1,-1},false,<o:p></o:p></p><p class=MsoNormal> [9] = {"^title()",2,-1,-1,true},<o:p></o:p></p><p class=MsoNormal> [10] = {"^partname()",2,-1,-1,true},<o:p></o:p></p><p class=MsoNormal> [11] = {"^page(0)",2,-1,-1,true},<o:p></o:p></p><p class=MsoNormal> [12] = {"^partname()",2,-1,-1,true},<o:p></o:p></p><p class=MsoNormal> [13] = {"^title()",2,-1,-1,true},<o:p></o:p></p><p class=MsoNormal>}<o:p></o:p></p><p class=MsoNormal> -- Set the line spacing<o:p></o:p></p><p class=MsoNormal> pagetexts = finale.FCPageTexts()<o:p></o:p></p><p class=MsoNormal> pagetexts:LoadAll()<o:p></o:p></p><p class=MsoNormal> pagetext = pagetexts:GetItemAt(PageTextLinks[idx][4] + 2 * PageTextLinks[idx][3], PageTextLinks[idx][3])<o:p></o:p></p><p class=MsoNormal> local TextString = pagetext:CreateTextString()<o:p></o:p></p><p class=MsoNormal> FontInfo = TextString:CreateLastFontInfo()<o:p></o:p></p><p class=MsoNormal> local TextBlock = pagetext:CreateTextBlock()<o:p></o:p></p><p class=MsoNormal> print (TextString.LuaString)<o:p></o:p></p><p class=MsoNormal> if not PageTextLinks[idx][5] then<o:p></o:p></p><p class=MsoNormal> print (" Change Line Spacing", not PageTextLinks[idx][5], "Index", idx)<o:p></o:p></p><p class=MsoNormal> TextBlock.LineSpacingIsPercent = false<o:p></o:p></p><p class=MsoNormal> TextBlock.LineSpacing = FontInfo.Size * 4<o:p></o:p></p><p class=MsoNormal> TextBlock:Save()<o:p></o:p></p><p class=MsoNormal> end<o:p></o:p></p><p class=MsoNormal> <o:p></o:p></p><p class=MsoNormal> -- Modify the PageText<o:p></o:p></p><p class=MsoNormal> TextString.LuaString = k<o:p></o:p></p><p class=MsoNormal> print("Existing Item", TextString.LuaString)<o:p></o:p></p><p class=MsoNormal> pagetext:SaveNewTextBlock(TextString)<o:p></o:p></p><p class=MsoNormal> set_data(pagetext, v)<o:p></o:p></p><p class=MsoNormal> pagetext:Save() <o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>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?<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>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.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Here’s the code for that part:<o:p></o:p></p><p class=MsoNormal> -- New<o:p></o:p></p><p class=MsoNormal> if PageTextLinks[idx][3] == -1 then<o:p></o:p></p><p class=MsoNormal> local new_item = finale.FCPageText()<o:p></o:p></p><p class=MsoNormal> local str = new_item:CreateTextString()<o:p></o:p></p><p class=MsoNormal> str.LuaString = k<o:p></o:p></p><p class=MsoNormal> print("New Item", str.LuaString)<o:p></o:p></p><p class=MsoNormal> new_item:SaveNewTextBlock(str)<o:p></o:p></p><p class=MsoNormal> set_data(new_item, v)<o:p></o:p></p><p class=MsoNormal> new_item:SaveNew(1)<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>So that now the pairs iteration seems to get lost and only some of the missing items get added. What am I doing wrong?<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Here is the whole code block for the final pass:<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>local idx = 2 <o:p></o:p></p><p class=MsoNormal>for k, v in pairs(PageTextData) do<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal> -- New<o:p></o:p></p><p class=MsoNormal> if PageTextLinks[idx][3] == -1 then<o:p></o:p></p><p class=MsoNormal> local new_item = finale.FCPageText()<o:p></o:p></p><p class=MsoNormal> local str = new_item:CreateTextString()<o:p></o:p></p><p class=MsoNormal> str.LuaString = k<o:p></o:p></p><p class=MsoNormal> print("New Item", str.LuaString)<o:p></o:p></p><p class=MsoNormal> new_item:SaveNewTextBlock(str)<o:p></o:p></p><p class=MsoNormal> set_data(new_item, v)<o:p></o:p></p><p class=MsoNormal> new_item:SaveNew(1)<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal> -- Existing<o:p></o:p></p><p class=MsoNormal> else<o:p></o:p></p><p class=MsoNormal> -- Set the line spacing<o:p></o:p></p><p class=MsoNormal> pagetexts = finale.FCPageTexts()<o:p></o:p></p><p class=MsoNormal> pagetexts:LoadAll()<o:p></o:p></p><p class=MsoNormal> pagetext = pagetexts:GetItemAt(PageTextLinks[idx][4] + 2 * PageTextLinks[idx][3], PageTextLinks[idx][3])<o:p></o:p></p><p class=MsoNormal> local TextString = pagetext:CreateTextString()<o:p></o:p></p><p class=MsoNormal> FontInfo = TextString:CreateLastFontInfo()<o:p></o:p></p><p class=MsoNormal> local TextBlock = pagetext:CreateTextBlock()<o:p></o:p></p><p class=MsoNormal> print (TextString.LuaString)<o:p></o:p></p><p class=MsoNormal> if not PageTextLinks[idx][5] then<o:p></o:p></p><p class=MsoNormal> print (" Change Line Spacing", not PageTextLinks[idx][5], "Index", idx)<o:p></o:p></p><p class=MsoNormal> TextBlock.LineSpacingIsPercent = false<o:p></o:p></p><p class=MsoNormal> TextBlock.LineSpacing = FontInfo.Size * 4<o:p></o:p></p><p class=MsoNormal> TextBlock:Save()<o:p></o:p></p><p class=MsoNormal> end<o:p></o:p></p><p class=MsoNormal> <o:p></o:p></p><p class=MsoNormal> -- Modify the PageText<o:p></o:p></p><p class=MsoNormal> TextString.LuaString = k<o:p></o:p></p><p class=MsoNormal> print("Existing Item", TextString.LuaString)<o:p></o:p></p><p class=MsoNormal> pagetext:SaveNewTextBlock(TextString)<o:p></o:p></p><p class=MsoNormal> set_data(pagetext, v)<o:p></o:p></p><p class=MsoNormal> pagetext:Save()<o:p></o:p></p><p class=MsoNormal> <o:p></o:p></p><p class=MsoNormal> end<o:p></o:p></p><p class=MsoNormal> <o:p></o:p></p><p class=MsoNormal>-- pagetexts:SaveAll() <o:p></o:p></p><p class=MsoNormal> idx = idx + 1<o:p></o:p></p><p class=MsoNormal>end<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Thanks so much for any light you can shed on the error in my ways.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Bruce<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'><o:p> </o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif";color:black'>-- <o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif";color:black'>Olson Sound Design, LLC<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif";color:black'>Bruce C. Olson<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif";color:black'>8717 Humboldt Avenue North<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif";color:black'>Brooklyn Park, MN 55444-1320<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif";color:black'><o:p> </o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif";color:black'>+1 (763) 493-5835 Office<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif";color:black'>+1 (763) 300-3893 Cell<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif";color:black'><o:p> </o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif";color:black'>Web Page: http://www.OlsonSound.com<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif";color:black'>Business: mailto:BCOlson@OlsonSound.com<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif";color:black'>Big Band: http://www.BRBB.org<o:p></o:p></span></p><p class=MsoNormal><o:p> </o:p></p></div></body></html>