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

Can I override a master page item on a page by using a reference name?

Explorer ,
Aug 08, 2022 Aug 08, 2022

Copy link to clipboard

Copied

Currently I have an item on my page that comes from a master page. It needs to be that way so it is duplicated when placed text creates a text flow which creates new pages.

 

After this I want to colorFill the master page item. I currently achieve that by doing the following:

(1) Get the list of masterPageItems on the page: app.activeDocument.pages[x].masterPageItems

(2) I then loop through the list of masterPageItems and check each item to see if it matches the name I am looking for.
(3) Once found I override the master page item I found and then color fill it.

 

I am wondering if there is an easier way to achieve this? Is there a way to find a masterPageItem on a page using the itemByName("myItem") method? Each page might have a different color so I cannot change the item in the masterSpread.

masterPageItems seems to return an array of pageitems as opposed to the object pageItems that can use the itemByName method.

 

Thank you in advance for any help provided.

 

 

TOPICS
Scripting

Views

80

Likes

Translate

Translate

Report

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

Guide , Aug 08, 2022 Aug 08, 2022

Hi @JO_15 

 

Just to be sure I understand let's go back to the basics:

 

(a) Either the object that you see on your final page is not overridden, in such case it still materially belongs to its MasterSpread and can be identified by myFinalPage.appliedMaster.pageItems.itemByName(myName). This object is known from the very beginning, you don't need to search for it when a new page is created. So just store it once (myRefMasterObj) and call myRefMasterObj.override(myFinalPage) when needed. Note that th

...

Likes

Translate

Translate
Community Expert ,
Aug 08, 2022 Aug 08, 2022

Copy link to clipboard

Copied

You could get the applied master of the page in question and override it. 

Is that what you mean? 

 

var ms = aPage.appliedMaster;
var f = ms.textFrames.itemByName("somename");
fbounds = f.geometricBounds;
f = f.override(aPage);
f.geometricBounds = fbounds;

 

Likes

Translate

Translate

Report

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
Guide ,
Aug 08, 2022 Aug 08, 2022

Copy link to clipboard

Copied

Hi @JO_15 

 

Just to be sure I understand let's go back to the basics:

 

(a) Either the object that you see on your final page is not overridden, in such case it still materially belongs to its MasterSpread and can be identified by myFinalPage.appliedMaster.pageItems.itemByName(myName). This object is known from the very beginning, you don't need to search for it when a new page is created. So just store it once (myRefMasterObj) and call myRefMasterObj.override(myFinalPage) when needed. Note that the array myFinalPage.masterPageItems contains myRefMasterObj as long as it is not overridden, but you don't need that array if you already know myRefMasterObj! Maybe it's worth highlighting that myFinalPage.masterPageItems does not reference any object that belongs to myFinalPage. These are all external references to MasterSpread items.

 

(b) Or, the object that you see on myFinalPage actually belongs to it because it has been overridden (and perhaps even detached.) In such case, this is somehow a copy of myRefMasterObj, but a totally distinct object with its own ID, and you can access it using myFinalPage.pageItems.itemByName(myName) since names are inherited through overridding.

 

Now, there are circumstances where you don't know whether your objects are in state (a) or (b) relative to myFinalPage. Assuming you've used unique names, a fast approach is to check first

 

    myFinalPage.pageItems.itemByName(myName).isValid

 

If true, that's your target object. Otherwise, time to override myRefMasterObj on myFinalPage, which creates the target object. Finally, apply the fillColor, etc.

 

Hope that helps.

 

Best,

Marc

Likes

Translate

Translate

Report

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 08, 2022 Aug 08, 2022

Copy link to clipboard

Copied

LATEST

Thank you for the very detailed explanation Marc! It helped me understand this better. I had not considered accessing it in the route you suggested. That allowed me to not have to use the loop I was using and the code runs much faster that way. Thank you again for taking the time to answer my question clearly and detailed.

Likes

Translate

Translate

Report

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