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

How to select objects on a master page? (Scripting)

Explorer ,
Aug 30, 2021 Aug 30, 2021

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.

Carpe diem
TOPICS
How to , Scripting
616
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 , Aug 31, 2021 Aug 31, 2021

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
...
Translate
Community Expert ,
Aug 30, 2021 Aug 30, 2021

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

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
Explorer ,
Aug 30, 2021 Aug 30, 2021

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.

Carpe diem
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 ,
Aug 30, 2021 Aug 30, 2021

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

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
Explorer ,
Aug 30, 2021 Aug 30, 2021

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.

Carpe diem
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 ,
Aug 30, 2021 Aug 30, 2021

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.

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
Explorer ,
Aug 30, 2021 Aug 30, 2021

My question is programming a script 🤔

Carpe diem
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 ,
Aug 30, 2021 Aug 30, 2021

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.

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 ,
Aug 31, 2021 Aug 31, 2021
LATEST

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.

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