Copy link to clipboard
Copied
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
1 Correct answer
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
...Copy link to clipboard
Copied
Please always add why your script is "not working". Do you get an error? Does it do something else instead?
Copy link to clipboard
Copied
thank you Jongware
the erro came from
var cObjectsTextFrame = mMasters.textFrames.everyItem().getElements();
how to define .textFrames.everyItem().getElements(); ?
thanks
John
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
thank you Man,
my question is how to define
.everyItem().getElements(); ?
how come my script always not working on .everyItem().getElements();
thanks
regard
John
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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;
Copy link to clipboard
Copied
thank Hopkins
thank so much.
I got the rule.
John
Copy link to clipboard
Copied
thank you Sunil
thank you so much.
John

