[JW Lua] Help with understanding an error message needed

Robert Wildling robertwildling at gmail.com
Sat May 14 13:09:44 CEST 2016


Hi,

a script loops over all staves of a score and logs some message to the
console about found attributes, among them the staff's full name. But 2
weird things happen:

1. it lists empty entries and I have no idea, where they come from. In one
case, there was an instrument change (and it seems this script cannot read
a staff name of an instrument change staff...) and two others from a
multi-staff instrument (harp). But still there are 5 more logs of staves
that have no name and are not in the score. I even tried to DeepDelete
them, but to no avail...
Is it possible that Finale remembers staves that were in the score at some
earlier stage, but were deleted via ScoreManager at a later point?

2. The function is called like this: loadStaves(30). Depending on whether
there is an attribute sent along, the script decides if it should loop over
all staves (id == nil ... LoadAll() .. ) or over the specific one (
Load(id) ). But the "found id" part of the script throws this error:

    -- This function and ..."]:41: attempt to call method 'Load' (a nil
value)

According to the Class browser, though, the syntax is correct.
Nevertheless, the Load method  will not even accept a number that is
entered manually...

Any ideas what I am doing wrong here?
Thanks!
Robert



This is the script:

****************************
function loadStaves( id )
    local staffNameFull = finale.FCString()
    local staffNameAbbr = finale.FCString()

    if ( id == nil )  then
        print ( "ID = not given, so get all staves")
        local staves = finale.FCStaves()
        staves:LoadAll()

        for staff in each(staves) do
            staffNameFull = staff:CreateTrimmedFullNameString()
            staffNameAbbr = staff:CreateTrimmedAbbreviatedNameString()

            print("ItemNo: ", staff:GetItemNo(),
                    " ---> Staff name full: ", staffNameFull.LuaString,
                    " - abbr: ", staffNameAbbr.LuaString
            )

            if ( staffNameFull.LuaString == ""
                 and staffNameAbbr.LuaString == ""
                 and staff:GetItemNo() == 30)
            then
                print("      empty... delete this... or not?");
                local bool = staff:DeepDeleteData()
                print(bool)
                staves:SaveAll()
            end
        end

   else
       print("ID = ", id, ", process only that staff, type = ", type(id))
       local staff = finale.FCStaves();
       if staff:Load(id) then
           staffNameFull = staff:CreateTrimmedFullNameString()
           staffNameAbbr = staff:CreateTrimmedAbbreviatedNameString()
           print("Staff name full: ", staffNameFull.LuaString, " - abbr: ",
staffNameAbbr.LuaString )
        end
    end
end -- end function loadStaff

loadStaves(29)
************************************
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://jwmusic.nu/pipermail/jwlua_jwmusic.nu/attachments/20160514/ce5a1305/attachment.htm>


More information about the JWLua mailing list