<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    >Jan, describe the direct support in RGP Lua you are imagining.<br>
    Maybe a static RGP Lua function with the content below that one can
    add to the end of a Lua script?<br>
    <br>
    Then you don't have to add this function below to your own code.<br>
    <br>
    Finally, add a reminder to the SetWidth documentation. Something
    like:<br>
    "When using SetWidth in linked parts, make sure to add the static
    ... function to the end of your Lua script. <br>
    It will maintain the correct measure width in the score when calling
    undo and then redo after applying the plug-in."<br>
    <br>
    Jan<br>
    <br>
    <div class="moz-cite-prefix">Am 04.04.2024 um 13:47 schrieb Robert
      Patterson:<br>
    </div>
    <blockquote type="cite"
cite="mid:CAACncesAB=63sD7zhaXSOFV5GYuNRfJBJvvmah3ZUhcopSCT9w@mail.gmail.com">
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <div dir="ltr">
        <div>ViewInDocument should not be necessary. (When I was working
          with your test case, I removed it to see if it made any
          difference: it did not.) In fact, ViewInDocument is a
          significant performance hit, and it may cause visual artifacts
          as well.<br>
        </div>
        <div><br>
        </div>
        <div>Steve, I believe you have my plugins. I always make a copy
          of my score before beginning the parts layout. I can then copy
          the measure widths and spacing from my score copy back to the
          score using Mass Copy as needed. (I tend to need it.) But I am
          going to add Jan's workaround to the Note Spacing plugin, and
          that could possibly eliminate the need to do this, provided I
          always use the Note Spacing plugin for spacing (which I do).<br>
        </div>
        <div><br>
        </div>
        <div>Jan, describe the direct support in RGP Lua you are
          imagining. I am not eager to add it to "SetWidth" on
          FCMeasure, because who knows what it might do in future Finale
          release. Plus, Jari seems to have kept the properties pretty
          clean as straight pass-thrus to PDK structs. (I have been a
          little lax in that, but mostly I try to follow the pattern.)</div>
        <div><br>
        </div>
      </div>
      <br>
      <div class="gmail_quote">
        <div dir="ltr" class="gmail_attr">On Thu, Apr 4, 2024 at 1:42 AM
          Jan Angermüller <<a href="mailto:jan@angermueller.com"
            moz-do-not-send="true" class="moz-txt-link-freetext">jan@angermueller.com</a>>
          wrote:<br>
        </div>
        <blockquote class="gmail_quote"
style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
          <div> I can now confirm that the workaround seems to solve the
            measure width undo/redo problem in Perfect Layout. I have
            also added the code to another plug-in and it fixed the
            problem too.<br>
            <br>
            Probably it makes sense to add this code to all plug-ins
            that change the measure width in parts.<br>
            Maybe it makes sense to even support this directly through
            RGP Lua?<br>
            <br>
            Below is the full code that I used.<br>
            <br>
            Robert, I was wondering about one thing:<br>
            according to my notes changing the FCMeasure object works
            best when the part has the focus with part:ViewInDocument().<br>
            In a first attempt I had also added p:ViewInDocument() to my
            code below when the plug-in was applied to the part only and
            the measure width had to be corrected in the invisible score
            (see commented line below).<br>
            However, the workaround also worked fine when I removed
            ViewInDocument.<br>
            Is FCMeasure safe without ViewInDocument? <br>
            Or is it because of the Finale bug that this weird
            workaround even works without ViewInDocument?<br>
            <br>
            Jan<br>
            <br>
            <br>
            -- add to the beginning of the code<br>
            local parts=finale.FCParts()<br>
            parts:LoadAll()<br>
            local NumParts=parts.Count<br>
            local part=finale.FCPart(finale.PARTID_CURRENT)<br>
            local CurrentPartIsScore=part:IsScore()<br>
            <br>
            function FixMeasureWidthInScore(region)<br>
                if NumParts>1 then<br>
                    local p<br>
                    if not CurrentPartIsScore then<br>
                        p=finale.FCPart(0)<br>
                        p:SwitchTo()<br>
                        --p:ViewInDocument()  --seems to be not
            necessary<br>
                    end<br>
                    if region==nil then<br>
                        region=finale.FCMusicRegion()<br>
                        region:SetFullDocument()<br>
                    end<br>
                    local i<br>
                    for i=region.StartMeasure, region.EndMeasure do<br>
                        local meas=finale.FCMeasure()<br>
                        meas:Load(i)<br>
                        meas.Width=meas.Width+1<br>
                        meas:Save()<br>
                        meas.Width=meas.Width-1<br>
                        meas:Save()<br>
                    end<br>
                    if not CurrentPartIsScore then<br>
                        p:SwitchBack()<br>
                        --add code for ViewInDocument of original part 
            -> but seems to be not necessary<br>
                    end<br>
                end<br>
            end<br>
            <br>
            ...<br>
            <br>
            FixMeasureWidthInScore(region)  --add this line at the very
            end of the script<br>
            <br>
            <br>
            <br>
            <br>
            <br>
            <br>
            <div>Am 03.04.2024 um 16:34 schrieb Robert Patterson:<br>
            </div>
            <blockquote type="cite">
              <div dir="ltr">
                <div>I saw an additional issue, which is that the Undo
                  does not undo the part width setting. I found some
                  notes about this in my Patterson Plugins code, so the
                  problem has been around a while.</div>
                <div><br>
                </div>
                <div>Glad you found a workaround.<br>
                </div>
              </div>
              <br>
              <div class="gmail_quote">
                <div dir="ltr" class="gmail_attr">On Wed, Apr 3, 2024 at
                  9:29 AM Jan Angermüller <<a
                    href="mailto:jan@angermueller.com" target="_blank"
                    moz-do-not-send="true" class="moz-txt-link-freetext">jan@angermueller.com</a>>
                  wrote:<br>
                </div>
                <blockquote class="gmail_quote"
style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
                  <div> Thank you for the quick response, Robert!<br>
                    I found a workaround which at least works in the
                    test case below:<br>
                    When I (re-)save the measure width in the score
                    afterwards, it is still the same bug.<br>
                    BUT:<br>
                    When I slightly change the measure width in the
                    score, save it, then restore the original value and
                    save it again, both the measure width in the score
                    and in the parts seem to have the correct value.<br>
                    It seems to set a flag in Finale that the measure
                    width in the score has indeed changed.<br>
                    <br>
                    I will have to check if this also solves the problem
                    in Perfect Layout.<br>
                    <br>
                    Here is the new test code with the additional lines
                    in bold:<br>
                    <br>
                    --Show measure 1 width from score<br>
                    local meas=finale.FCMeasure(1)<br>
                    meas:Load(1)<br>
                    print("Measure Width in Score",meas.Width)<br>
                    <br>
                    --Load Part 3 and change<br>
                    local p=finale.FCPart(3)<br>
                    p:SwitchTo(); <br>
                        p:ViewInDocument()<br>
                        meas=finale.FCMeasure(1)<br>
                        meas:Load(1)<br>
                        print("Measure Width in Part ",p.ID,meas.Width)<br>
                        meas.Width=360<br>
                        meas:Save()<br>
                        print("Measure Width after change",meas.Width)<br>
                    p:SwitchBack(); <br>
                    <br>
                    --Go back to score and show measure 1 width<br>
                    p=finale.FCPart(0)<br>
                    p:ViewInDocument()<br>
                    meas=finale.FCMeasure(1)<br>
                    meas:Load(1)<br>
                    <b>meas.Width=meas.Width+1<br>
                      meas:Save()<br>
                      meas.Width=meas.Width-1<br>
                      meas:Save()</b><br>
                    print("Measure Width in Score",meas.Width)<br>
                    <br>
                    Jan<br>
                    <br>
                    <br>
                    <br>
                    <div>Am 03.04.2024 um 15:34 schrieb Robert
                      Patterson:<br>
                    </div>
                    <blockquote type="cite">
                      <div dir="ltr">This is a bug in Finale. I doubt it
                        will be fixed. But you could send it to them if
                        you wish.<br>
                      </div>
                      <br>
                      <div class="gmail_quote">
                        <div dir="ltr" class="gmail_attr">On Wed, Apr 3,
                          2024 at 7:53 AM Jan Angermüller <<a
                            href="mailto:jan@angermueller.com"
                            target="_blank" moz-do-not-send="true"
                            class="moz-txt-link-freetext">jan@angermueller.com</a>>
                          wrote:<br>
                        </div>
                        <blockquote class="gmail_quote"
style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
                          <div> Robert,<br>
                            <br>
                            I have noticed several times that undo-ing
                            and re-doing a JW Lua plug-in can change the
                            measure width.<br>
                            Finally, I have created a short
                            reproduceable demo that I can't explain.<br>
                            <br>
                            The script is below.<br>
                            When applied to the score of the attached
                            Finale file, it switches to linked part 3,
                            loads measure 1 and changes its measure
                            width to 360 and then returns to the score.<br>
                            The measure width in the score remains
                            unchanged. So far, everything ok.<br>
                            Then I undo the plug-in in Finale and click
                            on Edit->Redo ...<br>
                            Now the width in measure 1 also changes in
                            the score!<br>
                            <br>
                            Here is a video that shows the effect (with
                            a slightly different version of the score):<br>
                            <a
href="https://www.youtube.com/watch?v=lPJd3sq9zQg" target="_blank"
                              moz-do-not-send="true"
                              class="moz-txt-link-freetext">https://www.youtube.com/watch?v=lPJd3sq9zQg</a><br>
                            <br>
                            In Perfect Layout it makes Finale's
                            Undo-/Redo feature unusuable, because it
                            (nearly) always changes the measure widths
                            in the score for an unknown  reason.<br>
                            Do you have an idea how I can prevent this?<br>
                            <br>
                            Jan<br>
                            <br>
                            --Show measure 1 width from score<br>
                            local meas=finale.FCMeasure(1)<br>
                            meas:Load(1)<br>
                            print("Measure Width in Score",meas.Width)<br>
                            <br>
                            --Load Part 3 and change<br>
                            local p=finale.FCPart(3)<br>
                            p:SwitchTo(); <br>
                                p:ViewInDocument()<br>
                                meas=finale.FCMeasure(1)<br>
                                meas:Load(1)<br>
                                print("Measure Width in Part
                            ",p.ID,meas.Width)<br>
                                meas.Width=360<br>
                                meas:Save()<br>
                                print("Measure Width after
                            change",meas.Width)<br>
                            p:SwitchBack(); <br>
                            <br>
                            --Go back to score and show measure 1 width<br>
                            p=finale.FCPart(0)<br>
                            p:ViewInDocument()<br>
                            meas=finale.FCMeasure(1)<br>
                            meas:Load(1)<br>
                            print("Measure Width in Score",meas.Width)<br>
                          </div>
_______________________________________________<br>
                          JWLua mailing list<br>
                          <a href="mailto:JWLua@jwmusic.nu"
                            target="_blank" moz-do-not-send="true"
                            class="moz-txt-link-freetext">JWLua@jwmusic.nu</a><br>
                          <a
href="http://jwmusic.nu/mailman/listinfo/jwlua_jwmusic.nu"
                            rel="noreferrer" target="_blank"
                            moz-do-not-send="true"
                            class="moz-txt-link-freetext">http://jwmusic.nu/mailman/listinfo/jwlua_jwmusic.nu</a><br>
                        </blockquote>
                      </div>
                      <br>
                      <fieldset></fieldset>
                      <pre>_______________________________________________
JWLua mailing list
<a href="mailto:JWLua@jwmusic.nu" target="_blank" moz-do-not-send="true"
                      class="moz-txt-link-freetext">JWLua@jwmusic.nu</a>
<a href="http://jwmusic.nu/mailman/listinfo/jwlua_jwmusic.nu"
                      target="_blank" moz-do-not-send="true"
                      class="moz-txt-link-freetext">http://jwmusic.nu/mailman/listinfo/jwlua_jwmusic.nu</a>
</pre>
                    </blockquote>
                    <br>
                    <pre cols="72">-- 
Jan Angermüller
Orchideenstieg 13
22297 Hamburg
Tel. 040 - 28 94 84 82
Mobil 0173 - 99 33 904
<a href="http://www.elbsound.studio" target="_blank"
                    moz-do-not-send="true">www.elbsound.studio</a></pre>
                  </div>
                  _______________________________________________<br>
                  JWLua mailing list<br>
                  <a href="mailto:JWLua@jwmusic.nu" target="_blank"
                    moz-do-not-send="true" class="moz-txt-link-freetext">JWLua@jwmusic.nu</a><br>
                  <a
href="http://jwmusic.nu/mailman/listinfo/jwlua_jwmusic.nu"
                    rel="noreferrer" target="_blank"
                    moz-do-not-send="true" class="moz-txt-link-freetext">http://jwmusic.nu/mailman/listinfo/jwlua_jwmusic.nu</a><br>
                </blockquote>
              </div>
              <br>
              <fieldset></fieldset>
              <pre>_______________________________________________
JWLua mailing list
<a href="mailto:JWLua@jwmusic.nu" target="_blank" moz-do-not-send="true"
              class="moz-txt-link-freetext">JWLua@jwmusic.nu</a>
<a href="http://jwmusic.nu/mailman/listinfo/jwlua_jwmusic.nu"
              target="_blank" moz-do-not-send="true"
              class="moz-txt-link-freetext">http://jwmusic.nu/mailman/listinfo/jwlua_jwmusic.nu</a>
</pre>
            </blockquote>
            <br>
            <pre cols="72">-- 
Jan Angermüller
Orchideenstieg 13
22297 Hamburg
Tel. 040 - 28 94 84 82
Mobil 0173 - 99 33 904
<a href="http://www.elbsound.studio" target="_blank"
            moz-do-not-send="true">www.elbsound.studio</a></pre>
          </div>
          _______________________________________________<br>
          JWLua mailing list<br>
          <a href="mailto:JWLua@jwmusic.nu" target="_blank"
            moz-do-not-send="true" class="moz-txt-link-freetext">JWLua@jwmusic.nu</a><br>
          <a href="http://jwmusic.nu/mailman/listinfo/jwlua_jwmusic.nu"
            rel="noreferrer" target="_blank" moz-do-not-send="true"
            class="moz-txt-link-freetext">http://jwmusic.nu/mailman/listinfo/jwlua_jwmusic.nu</a><br>
        </blockquote>
      </div>
      <br>
      <fieldset class="moz-mime-attachment-header"></fieldset>
      <pre class="moz-quote-pre" wrap="">_______________________________________________
JWLua mailing list
<a class="moz-txt-link-abbreviated" href="mailto:JWLua@jwmusic.nu">JWLua@jwmusic.nu</a>
<a class="moz-txt-link-freetext" href="http://jwmusic.nu/mailman/listinfo/jwlua_jwmusic.nu">http://jwmusic.nu/mailman/listinfo/jwlua_jwmusic.nu</a>
</pre>
    </blockquote>
    <br>
    <pre class="moz-signature" cols="72">-- 
Jan Angermüller
Orchideenstieg 13
22297 Hamburg
Tel. 040 - 28 94 84 82
Mobil 0173 - 99 33 904
<a class="moz-txt-link-abbreviated" href="http://www.elbsound.studio">www.elbsound.studio</a></pre>
  </body>
</html>