[JW Lua] FCMusicRegion:ForEachStaff - how to use ?

Jari Williamsson jari.williamsson at mailbox.swipnet.se
Mon Aug 11 07:45:48 CEST 2014


On 2014-08-11 00:31, Jan Angermüller wrote:

> I am trying to do a for ... loop on all staves from the selected region.
> Could you please give an example on how to use
> FCMusicRegion:ForEachStaff ?
> Is it possible to integrate this in a simple for ... loop ?
> Or do I have to work with an FCIteratorHandler class ?

ForEachStaff() in FCMusicRegion is not supported by JW Lua and it will 
never be. The same with the FCIteratorHandler class. These 2 are very 
C++ specific.

For JW Lua, the existing iterators for Lua or JW Lua are used.

In this case, the standard Lua "for" loop would work, such as:

---
local region = finenv.Region()
if not region:IsEmpty() then
	for slot = region.StartSlot, region.EndSlot do
		local staffid = region:CalcStaffNumber(slot)
		local staff = finale.FCStaff()
		staff:Load(staffid)
	end
end
---

The reason why the script checks IsEmpty() for the region is because 
StartSlot and EndSlot are equal but illegal if the region is empty. An 
alternative approach would be to check if the calculated staffid really 
is non-zero.

It's important that the conversion is made from slot numbers to staves, 
since there is no guarantee that the staves ID exist or are in order in 
a document.


Best regards,

Jari Williamsson





More information about the JWLua mailing list