[JW Lua] Hello World

Dave Foster fozder at me.com
Tue Oct 15 18:26:29 CEST 2013


Hi Jari, thanks for your swift response - and hi Charles, glad to join you in celebrating, implementing and challenging Jari's project!

Beta 0.08 is much appreciated - not had chance to mess with the measure numbers yet, but the following (proof of concept) code changes the font and size of all Page Text items (I'll split this into functions to make a tidier API);

--  Edit page text items
local pageTexts = finale.FCPageTexts()
pageTexts:LoadAll()
-- pageText is the PageText object, thisText is the text string attribute 
for pageText in each(pageTexts) do
	print(pageText:GetHorizontalAlignment())
	local thisText = pageText:CreateTextString()
-- enigmaStrings is a collection of Enigma Tags in an FCString object
	local enigmaStrings = thisText:CreateEnigmaStrings(false)
	for enigmaString in each(enigmaStrings) do
--        if (enigmaString:isEnigmaCommand()) then
		local enigmaComps = enigmaString:CreateEnigmaComponents()
		if (enigmaComps) then
			local enigmaTag = enigmaComps:GetItemAt(0)
-- Get current size, use it to make a string to find & replace
			if (enigmaTag:ContainsLuaString("size", nil)) then
			local sizeValue = enigmaComps:GetItemAt(1)
			local oldText = finale.FCString();
			oldText:AppendLuaString("^size(")
			oldText:AppendString(sizeValue)
			oldText:AppendLuaString(")")
			local newText = finale.FCString();
			newText:AppendLuaString("^size(")
			newText:AppendInteger(24)
			newText:AppendLuaString(")")
			thisText:Replace(oldText.LuaString, newText.LuaString)
		end
-- Get current font, use it to make a string to find & replace
		if (enigmaTag:ContainsLuaString("font", nil)) then
			local fontValue = enigmaComps:GetItemAt(1)
			local fontExtraValue = enigmaComps:GetItemAt(2)
			local oldText = finale.FCString();
			oldText:AppendLuaString("^font(")
			oldText:AppendLuaString(fontValue.LuaString)
			oldText:AppendLuaString(",")
			oldText:AppendLuaString(fontExtraValue.LuaString)
			oldText:AppendLuaString(")")
			local newText = finale.FCString();
			newText:AppendLuaString("^font(")
			newText:AppendLuaString("Arial Black")
			newText:AppendLuaString(",")
			newText:AppendLuaString(fontExtraValue.LuaString)
			newText:AppendLuaString(")")
			thisText:Replace(oldText.LuaString, newText.LuaString)
			end
		end
--	end
	end
	enigmaStrings = nil
	enigmaComps = nil
	pageText:SaveTextBlock(thisText)
end

isEnigmaCommand() doesn't seem to work, so is commented out - but passing false to CreateEnigmaStrings should ensure that only appropriate things get passed through. Any suggestions for making the text parsing and editing any slimmer?!

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?

Finally, I see that Finale 2014 is on the way - anybody got any insider knowledge about new scripting abilities that might be coming to make some of this obsolete? I suspect there won't be anything, but would be good to know before I invest too much time…

Thanks again,

Dave

> Message: 3
> Date: Mon, 14 Oct 2013 17:35:18 -0400
> From: "Charles O. Lawrence" <charlesolawrence at bellsouth.net>
> To: "'The JW Lua script plug-in.'" <jwlua at jwmusic.nu>
> Subject: Re: [JW Lua] Hello World
> Message-ID: <001401cec925$48aea0e0$da0be2a0$@bellsouth.net>
> Content-Type: text/plain;	charset="us-ascii"
> 
> Hello Dave Foster (et al),
> 
> Welcome to the world of JWLua.  So far, there has been no one but me, that I
> can recall, who has asked detailed questions and requested features or fixes
> to JWLua.  You will find that Jari is very accommodating and quick to
> respond.  I don't see how he does it.  Many of the updates to JWLua since
> its first rollout to the current 0.07 have been implemented because of an
> almost daily barrage of questions and requests from me.  Jari may think I
> have dropped off the face of the earth, since I have not posted to the list
> in probably almost two weeks now, but I simply have not had time to devote
> to scripting lately.  I have been involved in a Finale engraving project
> that has taken all my time, and I have had to learn a few things about
> Finale I had never run up against before.  It is almost finished, so I will
> have time to play with JWLua some more.  Beta 0.07 implements several
> features and new "hooks" that I am looking forward to implementing in some
> of my scripts and removing clunky workarounds.  You have requested a few
> more.  Jari says that unless we request something, it won't get implemented
> until he needs it in his script work.  That might take a long time.  Keep
> the ideas coming.  I could use that measure number region functionality now.
> 
> Charles Lawrence
> 
> 
> 
> 
> -----Original Message-----
> From: JWLua [mailto:jwlua-bounces at jwmusic.nu] On Behalf Of Jari Williamsson
> Sent: Monday, October 14, 2013 2:52 PM
> To: The JW Lua script plug-in.
> Subject: Re: [JW Lua] Hello World
> 
> On 2013-10-14 18:15, Dave Foster wrote:
>> 1) Access and edit the FCFontInfo property of the FCString object accessed
> using the CreateTextString() method of FCPageText: I can edit the FCFontInfo
> properties, but can't find a way to update them in the FCString. This is as
> far as I can get:
>> [...]
>> but it doesn't update the size. Am I missing a method in FCString which
> updates the FCFontInfo? I can edit the text itself:
> 
> The MakeEnigmaString() method would create an Enigma string based on the
> font info. However, for some reason, I haven't added Lua-support for it (I
> probably wanted to turn it into a CreateEnigmaString method, which would
> make more sense in Lua).
> 
> I'll add a solution for the next update.
> 
>> 2) Edit the Enigma components directly from the FCString object -
> unfortunately trying to call CreateEnigmaStrings() crashes Finale (2012) -
> this is the code that does it for me:
>> 
>> local pageTexts = finale.FCPageTexts()
>> pageTexts:LoadAll()
>> for pageText in each(pageTexts) do
>> 	local thisText = pageText:CreateTextString()
>> 	local enigmaStrings = thisText:CreateEnigmaStrings(false)
>> end
> 
> I now see that I have not included Lua support for the FCStrings collection,
> so that might be what's causing the crash. You need the FCStrings support to
> be able to do anything with the
> CreateEnigmaStrings() result.
> 
> Btw, I think you should send "true" to CreateEnigmaStrings() and then loop
> the created collection. But I need to add the FCStrings functionality
> first...
> 
>> Secondly, I'd love to be able to access and edit the properties
>> of measure number regions - specifically font and position of
>> measure numbers (can't tell you how much time I spend editing
>> them) but notice that the FCMeasureNumberRegion isn't accessible to 
>> JWLua - any plans to add that functionality?
> 
> Sure, I'll add it right away. Just let me know what you need for your own
> projects and I'll try to add Lua support for it as soon as I can. 
> Otherwise, I'll add Lua support when I need the stuff for my projects. ;-)
> 
> 
> Best regards,
> 
> Jari Williamsson
> 
> 
> _______________________________________________
> JWLua mailing list
> JWLua at jwmusic.nu
> http://jwmusic.nu/mailman/listinfo/jwlua_jwmusic.nu
> 




More information about the JWLua mailing list