Skip navigation
Currently Being Moderated

How to refer text frame on master page on specific layer[JS CS5]

Jan 30, 2012 3:47 AM

Hi All,

 

It is very simple find change stuff getting head storming after but unable to figure it out why script won't find any text in specific layer on Master Page.

 

I want to find some grep on specific layer which exist only on Master page here is my script code:

 

 

var Doc = app.activeDocument;
 
var curLayer = Doc.layers.item("myLayer");
app.findChangeGrepOptions.includeMasterPages = true; 
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = "\\d+"; 
 app.changeGrepPreferences.changeTo = "some text to change";
curLayer.textFrames.itemByName("PromoFrame").changeGrep();
 app.findGrepPreferences = app.changeGrepPreferences = null;

 

I am getting the error "Object is invalid". Could someone help me to figure it out?

 

 

Thanks

Mac

 
Replies
  • Currently Being Moderated
    Jan 30, 2012 5:35 AM   in reply to Mac_06

    curLayer.textFrames.itemByName("PromoFrame").changeGrep();

     

    you've referening the "PromoFrame" textframe objects does not exist on the document.  Check on the frame label name.

     
    |
    Mark as:
  • Currently Being Moderated
    Jan 30, 2012 8:26 AM   in reply to Mac_06
     
    |
    Mark as:
  • Currently Being Moderated
    Jan 31, 2012 1:22 AM   in reply to Mac_06

    Could you refer me the post where it accutly discussed?

    Here's the post and here's a solution.

    I use this function:

    function GetItemFromCollection(label, collection) {
         for (var i = 0; i < collection.length; i++) {
              if (label == collection[i].label) return collection[i];
         }
         return null;
    }
    
     
    |
    Mark as:
  • Currently Being Moderated
    Jan 31, 2012 6:49 AM   in reply to Mac_06

    Or you could just name your "PromoFrame" frame in the Layers palette instead of with a script label and continue to use .itemByName()...

     
    |
    Mark as:
  • Currently Being Moderated
    Jan 31, 2012 10:27 AM   in reply to Mac_06

    Okay, I think maybe I see. I think you have two problems. The layer.textFrames collection won't include master page items. See this thread. However to my knowledge this was not new in CS5.

     

    On to the second problem. You write:

     

    absqua wrote...

    Or you could just name your "PromoFrame" frame in the Layers palette instead of with a script label and continue to use .itemByName()...

     

    This is same I'm using in please refer my first thread.

     

    However just before that you say:

     

    In my case there may be multiple text frame with same label name but must be on different layer...

     

    Your use of .itemByName() here:

     

    curLayer.textFrames.itemByName("PromoFrame").changeGrep();
    

     

    leads me to believe that you're expecting the CS4 behavior, where the item name was the script label and you would get a collective object back from it. It might be worth looking back through the thread Jongware linked.

     

    I think with your combination of requirements—targeting master page items on specific layers, that is—the only real option is to loop through your master page text frames and check each one's itemLayer and label (or name!) and do multiple changeGrep()s:

     

    var doc = app.activeDocument,
         masterTextFrames = doc.masterSpreads.everyItem().textFrames.everyItem().getElements(),
         curLayer = doc.layers.item("mylayer"),
         label = "PromoFrame",
         i, l, frame;
     
    app.findChangeGrepOptions.includeMasterPages = true;
    app.findGrepPreferences = app.changeGrepPreferences = null;
    app.findGrepPreferences.findWhat = "\\d+";
    app.changeGrepPreferences.changeTo = "some text to change";
     
    for (i = 0, l = masterTextFrames.length; i < l; i++) {
         frame = masterTextFrames[i];
         if (frame.itemLayer === curLayer && frame.label === label) {
                frame.changeGrep();
         }
    }
     
    app.findGrepPreferences = app.changeGrepPreferences = null;
    
     
    |
    Mark as:
  • Currently Being Moderated
    Feb 1, 2012 8:07 AM   in reply to Mac_06

    Mac_06 wrote:

     

    Perfect catch that worked. So lesson learnt Frame.Layeritem works but Layer.Frameitem doesn't work on master page. Please correct me if I am wrong.

     

    Thanks a ton all.

    Mac

     

    Your wording is a little jumbled, but I think you get the idea. To be clear, I hope: you can always check the frame.itemLayer property, whether the frame appears on a master or regular page. layer.textFrames (or layer.pageItems, or layer.rectangles, etc.) is a collection (that enables you to call a method, e.g. changeGrep(), on a number of items at once) that will not include any master page items.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points