[JW Lua] PageText not playing ball
Herbert van Essen
hpvanessen at gmail.com
Fri Oct 18 10:36:53 CEST 2013
Hello Jari and all,
I am following you since LUA started and now I am trying something myself.
How about placing text on the page that is selected?
Or place text on many or all pages?
Here is an example of placing text on a given page:
function plugindef()
-- This function and the 'finaleplugin' namespace
-- are both reserved for the plug-in definition.
finaleplugin.Author = "Herbert van Essen"
finaleplugin.CategoryTags = "Text, Page, System, UI"
return "Place text on page X", "Place text on page X",
"Creates a predefined text on page X."
end
-- Show user dialog box
local dialog = finenv.UserValueInput()
dialog.Title = "Place text"
dialog:SetTypes("Number")
dialog:SetDescriptions("page number:")
dialog:SetInitValues(1)
local returnvalues = dialog:Execute()
if not returnvalues then return end
local currentprocesspage = returnvalues[1]
if currentprocesspage < 1 then
print ("Input error: Invalid start page number.")
return
end
local pages = finale.FCPages()
local pageprocesscounter = 0
-- Get the collection of PageText objects
local pageTexts = finale.FCPageTexts()
-- Create a new PageText object
local newText = finale.FCPageText()
-- Here I'm wildly setting properties in case one of them is missing and
essential!
newText.FirstPage = 0
newText.LastPage = 0
newText.PageAssignment = currentprocesspage
newText.VerticalPos = -72
newText.HorizontalPos = 1
-- newText.HorizontalAlignment = 0 -- Calling this crashes Finale
newText.VerticalAlignment = 0
newText.PageEdgeRef = true
-- Create a new string object, set it to the desired text, with Enigma tags
for font, size and nfx (whatever that is)
local textObject = finale.FCString()
textObject:AppendLuaString("^font(Arial Black,4096)^size(24)^nfx(0)It
Works!")
-- Set the string as the TextBlock on the new Page Text object (and check
that it has via the console)
print(newText:SaveNewTextBlock(textObject))
newText:SaveNew(1)
It doesn't work like that; Can you give me a hint to get this right?
How can I get the PageAssignment to load at the currentprocesspage?
And what are setting properties for? They are doing nothing as far as I can
see.
Thanks,
Herbert
2013/10/17 Dave Foster <fozder at me.com>
> Hi Jari and all,
>
> Many thanks for your tips, especially on optimising my string
> concatenation and using dot properties. I'm still struggling to get my new
> PageText object to show up, either on screen or in the FCPageTexts
> collection - here's where I'm at:
>
> -- Get the collection of PageText objects
> local pageTexts = finale.FCPageTexts()
>
> -- Create a new PageText object
> local newText = finale.FCPageText()
>
> -- Here I'm wildly setting properties in case one of them is missing and
> essential!
> newText.FirstPage = 1
> newText.LastPage = 1
> newText.VerticalPos = -72
> newText.HorizontalPos = 1
> -- newText.HorizontalAlignment = 0 -- Calling this crashes Finale
> newText.VerticalAlignment = 0
> newText.PageEdgeRef = true
>
> -- Create a new string object, set it to the desired text, with Enigma
> tags for font, size and nfx (whatever that is)
> local textObject = finale.FCString()
> textObject:AppendLuaString("^font(Arial Black,4096)^size(24)^nfx(0)It
> Works!")
>
> -- Set the string as the TextBlock on the new Page Text object (and check
> that it has via the console)
> print(newText:SaveNewTextBlock(textObject))
>
> newText:saveNew(1)
>
> So I get the error
>
> -- This function and ..."]:41: attempt to call method 'saveNew' (a nil
> value)
>
> so looks like I'm not using saveNew() in the correct way - I've tried
> using it on the collection (i.e. pageTexts:saveNew(newText)) but that's not
> it either. Any ideas?
>
> Cheers,
>
> Dave
>
>
>
> On 16 Oct 2013, at 11:00, jwlua-request at jwmusic.nu wrote:
>
> >> Next challenge - create some text - this doesn't seem to get anything
> to show up, either on the page or in the FCPageTexts:
> >>
> >> local newText = finale.FCPageText()
> >> newText:SetFirstPage(1)
> >> newText:SetLastPage(1)
> >> newText:SetVerticalPos(-72)
> >> newText:SetHorizontalPos(1)
> >> local textObject = newText:CreateTextString()
> >> textObject:AppendLuaString("^font(Arial Black,4096)^size(24)^nfx(0)It
> Works!")
> >> newText:SaveTextBlock(textObject)
> >>
> >> Any thoughts?
> >
> > 1. If you do "print(newText:SaveTextBlock(textObject))", you'll see that
> > it returns false. Replace "SaveTextBlock" with "SaveNewTextBlock". Since
> > you're creating a new page text, you cannot replace a text pool item
> > that doesn't exist. You should even be able to do "local textObject =
> > finale.FCString()" in this case as well, since "CreateTextString()" will
> > never return any text.
> > 2. After the Enigma text block has been saved, save the page text
> > object. Add "newText:SaveNew(1)" at the end and the text will appear.
>
>
> _______________________________________________
> 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/20131018/e3b2f910/attachment.htm>
More information about the JWLua
mailing list