Copy link to clipboard
Copied
I have multiple master pages and I want to activate one by one to edit the content of text frames.
My master pages already have names.
1 Correct answer
Responding coherently to Manan's suggestions would have been more useful than simply repeating your questions several times. Anyway.
> I have multiple master pages and I want to activate one by one to edit the content of text frames.
In scripting you typically don't select page items, you talk to them directly. You select things only when you really have to.
Manan already suggested code to process a single master. To process text frames on all masters, you could use something like this:
master
...
Copy link to clipboard
Copied
I did not fully understand your question. But the following code should give you a starting point
var ms = app.documents[0].masterSpreads.itemByName("A-Master")
if(!ms.isValid)
exit()
var tfs = ms.textFrames
Here change the name of the masterpage from A-Master to whatever your page name is, the variable tfs would contain the textframes contained on this master page you can process them as you want.
-Manan
Copy link to clipboard
Copied
I have a master page called "COVER" and inside a text frame called "DATE" (inside a layer called "1_EXTRA")
I want to be able to select it to edit its content.
How can I do it?
Thanks in advance.
Copy link to clipboard
Copied
You could use the layers palette to quickly do what you need intend to do, I am not sure if the script will be any more helpful. However, a sample script would be something like the following. Change the name of the master page as per your document I used a random prefix for the page name
var ms = app.documents[0].masterSpreads.itemByName("C-COVER")
if(!ms.isValid)
exit()
var tfs = ms.textFrames
for(var i = 0; i < tfs.length; i++)
{
if(tfs[i].name == "DATE" && tfs[i].itemLayer.name == "1_EXTRA")
app.select(tfs[i], SelectionOptions.ADD_TO)
}
This will select all the DATE name textframes on the layre named 1_EXTRA that are placed over on a master page named c-COVER
-Manan
Copy link to clipboard
Copied
I have multiple master pages and I want to activate one by one to edit the content of text frames.
Master pages already have names.
Copy link to clipboard
Copied
Once you have selected the master page, you select objects as you do on a document page. However, if you have based that master page on another master page, you could either override the item by Cmd/Ctrl+Shift-clicking OR you could make the change on that master's parent master page.
Copy link to clipboard
Copied
My question is programming a script 🤔
Copy link to clipboard
Copied
Always a good idea to mention Scripting in the text of your request. It's easy to miss topics at the bottom.
In the past we had a separate Scripting forum where this of course wasn't necessary.
Copy link to clipboard
Copied
Responding coherently to Manan's suggestions would have been more useful than simply repeating your questions several times. Anyway.
> I have multiple master pages and I want to activate one by one to edit the content of text frames.
In scripting you typically don't select page items, you talk to them directly. You select things only when you really have to.
Manan already suggested code to process a single master. To process text frames on all masters, you could use something like this:
masters = app.activeDocument.masterSpreads.everyItem().getElements();
for (i = 1; i < masters.length; i++) {
frames = masters[i].textFrames.everyItem().getElements();
for (j = 0; j < frames.length; j++) {
// doSomething() to be defined
doSomething (frames[j]);
}
}
And if what you do with frames depends on the name of the masters, then you would wrap Manan's code inside my code:
masters = app.activeDocument.masterSpreads.everyItem().getElements();
for (i = 1; i < masters.length; i++) {
frames = masters[i].textFrames.everyItem().getElements();
// doThis() and doThat() to be defined
switch (masters[i].name) {
case 'A-TitlePage': doThis (frames);
case 'B-Copyright': doThat (frames);
// etc.
}
}
P.

