9 Replies Latest reply: Feb 1, 2012 8:07 AM by absqua RSS

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

    Mac_06 Community Member

      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

        • 1. Re: How to refer text frame on master page on specific layer[JS CS5]
          Nagaraj Muthu Community Member

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

           

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

          • 3. Re: How to refer text frame on master page on specific layer[JS CS5]
            Mac_06 Community Member

            Thanks for reply Jongware but I don't see any discussion regarding this issue in CS5 things have changed.

             

            Did something really got changed in this context? Could you refer me the post where it accutly discussed?

             

            Mac

            • 4. Re: How to refer text frame on master page on specific layer[JS CS5]
              Kasyan Servetsky Community Member

              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;
              }
              
              • 5. Re: How to refer text frame on master page on specific layer[JS CS5]
                absqua Community Member

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

                • 6. Re: How to refer text frame on master page on specific layer[JS CS5]
                  Mac_06 Community Member

                  Kasyan Servetsky wrote:

                   

                  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;
                  }

                   

                  This could be surely a workaround but as I emphasized in my initial thread it doesn't  work on Master Pages and only on Master Page, In my case there may be multiple text frame with same label name but must be on different layer so I need do find/replace on specific layer and on Master page only but it seems in CS5 something got changed where it won't allow to change on specific layer on Master page.

                   

                  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.

                   

                  Thanks for taking interest in this issue.

                  Mac

                  • 7. Re: How to refer text frame on master page on specific layer[JS CS5]
                    absqua Community Member

                    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;
                    
                    • 8. Re: How to refer text frame on master page on specific layer[JS CS5]
                      Mac_06 Community Member

                      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

                      • 9. Re: How to refer text frame on master page on specific layer[JS CS5]
                        absqua Community Member

                        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.