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

Help for fix script

Contributor ,
Jun 25, 2019 Jun 25, 2019

Hi experts,

my script like this:

var myDocs = app.activeDocument;

var mMasters = myDocs.masterSpreads.everyItem().getElements();

var cObjectsTextFrame = mMasters.textFrames.everyItem().getElements();

if (!cObjectsTextFrame.contents || !cObjectsTextFrame.contents.match(/\S/) ) cObjectsTextFrame.remove();

for remove masterSpreads text frame object.

but not working, could someone please help me to fix it.

thanks

regard

John

TOPICS
Scripting
810
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

Enthusiast , Jun 26, 2019 Jun 26, 2019

In your script the variable mMasters is an array not an object. At this point you need to parse the array to get the cObjects.

var cObjects;

var myDocs = app.activeDocument; 

var mMasters = myDocs.masterSpreads.everyItem().getElements();

for (var i = 0; i < mMasters.length; i++) {

    cObjects = mMasters.textFrames.everyItem().getElements();

    if (cObjects.length > 0) {

    //work with cObjects here

    alert ("cObjects " + cObjects.length);

    }

}

It looks, however, like you may be wanting to get rid

...
Translate
Community Expert ,
Jun 25, 2019 Jun 25, 2019

Please always add why your script is "not working". Do you get an error? Does it do something else instead?

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 ,
Jun 25, 2019 Jun 25, 2019

thank you Jongware

the erro came from

var cObjectsTextFrame = mMasters.textFrames.everyItem().getElements();

how to define .textFrames.everyItem().getElements();  ?

thanks

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 ,
Jun 26, 2019 Jun 26, 2019

Hi John,

In addition to what [Jongware]​ mentioned please try to give as much information as possible so that the suggestions made are more relevant to you. I would suggest you the following

  • Instructions on how to reproduce the issue you are facing
  • Specifics on what errors you get, like specific error message etc
  • Add a meaningful heading to your thread, just naming it something like the current "Help to fix script" does no one any good, as this is so generic a heading that we could rename this whole forum as "Help to fix script". Be specific and short in your heading so that gives an idea about the topic being discussed
  • After someone provides you with any suggestion follow the same steps to provide as much a detailed feedback as you can in cases when you still does not have a resolution. In case you do have a resolution post back the same as well

Hope these points will help you in future to post your issues in a manner that get maximum attention by fellow scripters and get you to a speedy resolution

-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
Advocate ,
Jun 25, 2019 Jun 25, 2019

Hi Johnwhite​,

Try this code for removing blank text frames from master spreads:

//~ var myDoc = app.documents[0];

var myDoc = app.activeDocument;

for(var m = 0 ; m < myDoc.masterSpreads.length; m++){

    for(var t = myDoc.masterSpreads.textFrames.length-1; t >=0 ; t--){

        if(myDoc.masterSpreads.textFrames.contents.replace(/[\s]+/g,'') == ""){

            myDoc.masterSpreads.textFrames.remove();

            }

        }

    }

Best

Sunil

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 ,
Jun 26, 2019 Jun 26, 2019

thank you Man,

my question is how to define

.everyItem().getElements();       ?

how come my script always not working on .everyItem().getElements(); 

thanks

regard

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
Advocate ,
Jun 26, 2019 Jun 26, 2019

Hi Johnwhite​

Everytime you don't need to use everyItem() or .getElement().

We've to understand what we actually need to access and how we are going to reach our goal.

I you want to access individual text frames which are on multiple master spreads.

We have to go down on our variable on by one:

Like this:

First we'll get our document as : app.activeDocument / app.documents[0] / app.documents.item("test") & store it in a variable.

After that we need to access all master spreads one by one, so we'll take master spreads on myDoc as : myDoc.masterSpreads (this will return collection of all master spreads)

So now instead of everyItem(), we should better for for looping through all master spreads like for() loop & find all textframes into those master spreads.

getting those text frames there only we should check for the contents and if it is nothing --- remove that text frame.

Removing that textframe will make your spreads contains less than one text frame, so we should again refresh that text frame variable or we can reverse the loop.

You will achieve that.

Without focusing on everyItem().getElements().

Best

Sunil

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 ,
Jun 26, 2019 Jun 26, 2019

HI,

I think you created a different thread, which I have an answer on for you. you should really only create one thread for your question.

Regads

Malcolm

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
Enthusiast ,
Jun 26, 2019 Jun 26, 2019

In your script the variable mMasters is an array not an object. At this point you need to parse the array to get the cObjects.

var cObjects;

var myDocs = app.activeDocument; 

var mMasters = myDocs.masterSpreads.everyItem().getElements();

for (var i = 0; i < mMasters.length; i++) {

    cObjects = mMasters.textFrames.everyItem().getElements();

    if (cObjects.length > 0) {

    //work with cObjects here

    alert ("cObjects " + cObjects.length);

    }

}

It looks, however, like you may be wanting to get rid of the master text frame. This is now the createPrimaryTextFrame property of document preferences:

var docRef = app.activeDocument;

var docPrefs =  docRef.documentPreferences;

if (docPrefs.createPrimaryTextFrame == true) {

    docPrefs.createPrimaryTextFrame = false;

}

docPrefs.createPrimaryTextFrame;

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 ,
Jun 26, 2019 Jun 26, 2019

thank Hopkins

thank so much.

I got the rule.

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
Contributor ,
Jun 27, 2019 Jun 27, 2019
LATEST

thank you Sunil

thank you 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