Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to defined Threaded text frames

Contributor ,
Apr 13, 2019 Apr 13, 2019

Hi experts,

my script like this:

function movecashline()
    {
    var
        mMsg = {title: "move frames"},
        cMH, cMV, cZP, cRO;
    cash();
    function cash ()
    {
        var
            mTarget = checkSelection().everyItem().getElements(),
            mDoc, cMPages, cPages, cPage;
        mMsg.funName = "Main";
        while (mDoc = mTarget.pop()) {
             doRulesUp(mDoc);
             cMPages = mDoc.masterSpreads.everyItem().pages.everyItem().getElements();
             cPages = mDoc.pages.everyItem().getElements();
             while (cPage = cMPages.pop())
                 moveBar (cPage);
             while (cPage = cPages.pop())
                 moveBar (cPage);
             doRulesDown(mDoc);
            }
        }
    function moveBar (mPage, mStyle)
    {
        var
            cTopMargin = mPage.marginPreferences.top,
            cBottomMargin = mPage.marginPreferences.bottom,
            cBounds = mPage.bounds,
            cPI, cGB,
            cStyleName = "footer",
            cPIs = mPage.textFrames.everyItem().getElements();

            while (cPI = cPIs.pop()) {
                if (!cPI.hasOwnProperty ("texts")) continue;
                if (!cPI.texts[0].characters.length) continue;
                if (!cPI.texts[0].appliedParagraphStyle.name.match(/^footer$/i)) continue;
                cGB = cPI.geometricBounds;
                if (cGB[0] > cBounds[2] - cBottomMargin)
                    cPI.move([cGB[1], cBounds[2] + 25]);
                else
                     cPI.move([cGB[1], -(cGB[2] - cGB[0]) - 25]);
                }
        }
    function doRulesUp(cDoc)
    {
         with (cDoc.viewPreferences) {
             cMH = app.activeDocument.viewPreferences.horizontalMeasurementUnits;
            cMV = app.activeDocument.viewPreferences.verticalMeasurementUnits;
            cRO = app.activeDocument.viewPreferences.rulerOrigin;
            horizontalMeasurementUnits = MeasurementUnits.POINTS;
            verticalMeasurementUnits = MeasurementUnits.POINTS;
            rulerOrigin = RulerOrigin.PAGE_ORIGIN;
            }
        cZP =cDoc.zeroPoint,
        cDoc.zeroPoint = [0,0];
        }
    function doRulesDown(cDoc)
    {
        with (cDoc.viewPreferences) {
            horizontalMeasurementUnits = cMH;
            verticalMeasurementUnits = cMV;
            rulerOrigin = cRO;
            }
        cDoc.zeroPoint = cZP;
        }
    function checkSelection ()
    {
        mMsg.funName = "Check Selection";

        if ( !app.documents.length) {
            mMsg.line = $.line - 1;
            mMsg.text = "No target detected.\nOpen any doc.";
            errorClose (mMsg);
            }
        return app.documents; //
            }
        }

aim to move the text frame, which has text and applied to para style "footer".

but it pop up error on this case:

if there is threaded frames, like this:

擷取01.PNG

and the fame is empty

the error says:

error from this line:

if (!cPI.texts[0].characters.length) continue;

reason:

Object is invalid

could some one tell how to fix, please.

thanks

regard

John

TOPICS
Scripting
590
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Apr 13, 2019 Apr 13, 2019

In case of threaded frames, for 2nd textframe onwards, texts[0] is invalid when the textframe is empty. Hence your code fails, depending upon your use case you could modify your code as follows

if (!cPI.texts[0].isValid || !cPI.texts[0].characters.length) continue;

You could even identify if the textframe is a part of a thread by using the previousTextFrame property.

if(cPI.previousTextFrame != null)

     alert("The textframe is part of a thread and is not the first textframe")

-Manan

Translate
Community Expert ,
Apr 13, 2019 Apr 13, 2019

In case of threaded frames, for 2nd textframe onwards, texts[0] is invalid when the textframe is empty. Hence your code fails, depending upon your use case you could modify your code as follows

if (!cPI.texts[0].isValid || !cPI.texts[0].characters.length) continue;

You could even identify if the textframe is a part of a thread by using the previousTextFrame property.

if(cPI.previousTextFrame != null)

     alert("The textframe is part of a thread and is not the first textframe")

-Manan

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Apr 14, 2019 Apr 14, 2019

Hi Manan

the error says:

Object does not support the property or medthod "isvalid"

after modify you code.

John

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 14, 2019 Apr 14, 2019

Sorry its a typo, its not isvalid but isValid

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Apr 14, 2019 Apr 14, 2019
LATEST

Thank you Man,

thanks so much.

John

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines