<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=utf-8">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    Jari,<br>
    <br>
    I have two issues with changing the key signature on an FCCell
    object with Finale 2014d/Windows7/JW Lua 0.29.<br>
    <br>
    1.) If "Independent Element -> Key Signature" is NOT selected in
    the staff settings,<br>
    the following code <b>may crash </b>Finale. It "may crash", as
    sometimes I have to run the script several times until it crashes,
    so there must be some undefined behaviour. <br>
    Maybe this is by design and the developer has to make sure that it
    is a staff with an independent key signature before calling
    FCCell:GetKeySignature(). But it would be more safe if you inserted
    a quick check into the FCCell:GetKeySignature()-implementation.<br>
    I would expect cell:GetKeySignature() to return nil on a
    non-independent key signature staff.<br>
    That's better than crashing ;-)<br>
    BTW, you have FCCell.HasIndependentTimeSig(). Maybe you could also
    add HasIndependentKeySig().<br>
    <br>
    This is the test code:<br>
    <br>
    --change key signature on first selected measure of first selected
    staff <br>
    if not finenv.Region():IsEmpty() then<br>
        local
    cell=finale.FCCell(finenv.Region().StartMeasure,finenv.Region().StartStaff)
    <br>
        key=cell:GetKeySignature()<br>
        if key ~= nil then<br>
           print("Old alteration:", key.Alteration)<br>
           key:SetMajorKey(5)<br>
           print("New alteration:", key.Alteration)<br>
           key:Save()   --I don't know if this is necessary: same
    behaviour if I keep it in or take it out<br>
           cell:Save()    --this function call crashes Finale<br>
        end<br>
    end<br>
    <br>
    2.) Now if "Independent Element -> Key Signature" IS selected in
    the staff settings and I also add a condition to check that key
    signatures are independent, the code above has the same behaviour:
    it still doesn't change any key signatures, but crashes Finale (if
    not after the first run, then after running it several times).<br>
    This is the test code:<br>
    <br>
    --change key signature on first selected measure of first selected
    staff <br>
    --with independent key signature check<br>
    if not finenv.Region():IsEmpty() then<br>
        local staff=finale.FCStaff()<br>
        staff:Load(finenv.Region().StartStaff)<br>
        if staff.IndependentKeySig then<br>
           local
    cell=finale.FCCell(finenv.Region().StartMeasure,finenv.Region().StartStaff)
    <br>
           key=cell:GetKeySignature()<br>
           if key ~= nil then<br>
              print("Old alteration:", key.Alteration)<br>
              key:SetMajorKey(5)<br>
              print("New alteration:", key.Alteration)<br>
              key:Save()   --I don't know if this is necessary: same
    behaviour if I keep it in or take it out<br>
             cell:Save()    --this function call crashes Finale<br>
           end<br>
        end<br>
    end<br>
    <br>
    What works fine is changing the global key sig using
    FCMeasure:GetKeySignature(), i.e something like:<br>
    local measure=finale.FCMeasure()<br>
    measure:Load(1)<br>
    local key=measure:GetKeySignature()<br>
    key:SetMajorKey(5)  --change key sig in measure 1<br>
    measure:Save()<br>
    <br>
    Any ideas what the independent key sig thingy comes from ?<br>
    <br>
    Best regards,<br>
    Jan<br>
  </body>
</html>