4 Replies Latest reply on Apr 30, 2009 10:11 AM by lewis_cooper

    Move all objects assigned an Object Style to a specific layer?

    lewis_cooper

      Hi all,

       

      I've just posted this in the regular InDesign forum but thought you scripters may have some clever solutions too:

       

      I'm working on a long document in InDesign (believe it or not!) in which I have lots of shots of models and still life images as this is a women's fashion catalogue. I work solely in InDesign as all Photoshop work is undertaken by our repro house, off site. At present the way in which I communicate any comp work that needs to be done is by placing a solid magenta or cyan box over the image for maximum visibility. I have of course got an object style applied to these boxes and I also like to keep them all on a separate layer away from the artwork so that they may be switched off come print time.

       

      Often I forget to move a box to the correct layer or sometimes it just slows me down to do so. What I would ideally like to do is assign a layer to the object style, but seeing as this is not possible I wondered if there's another a solution to getting all those boxes on one layer in one foul swoop and thus saving me a chunk of time.

       

      Thanks in advance!

        • 1. Re: Move all objects assigned an Object Style to a specific layer?
          Dave Saunders Level 4

          I don't know about a foul swoop, but a script can certainly do this. Assuming all the objects are free-standing on their pages -- if they're not then you can't change their layer without changing whatever is containing them:

           

          myDoc = app.documents[0];

          myPIs = myDoc.pageItems.everyItem().getElements();

          for (var j = myPIs.length - 1; j >= 0; j--) {

               if (myPIs[j].appliedObjectStyle.name === "MyOstyleName") {

                    myPIs[j].itemLayer = "myOlayer";

               }

          }

           

          You just need to edit the two names to match your names.

           

          Save the file as a JavaScript in your Scripts Panel folder, open the document and run the script and that should get the job done in one swell foop.

           

          Dave

          1 person found this helpful
          • 2. Re: Move all objects assigned an Object Style to a specific layer?
            lewis_cooper Level 1

            Hi Dave,

             

            Thanks for helping me out on this. I'm not having much luck with the sample script you suggested though. I've attached a screen grab of my layer and object style windows to show the file names I've used as well as the error message I'm recieving. This is the script after my changes:

             

            myDoc = app.documents[0];

            myPIs = myDoc.pageItems.everyItem().getElements();

            for (var j = myPIs.length - 1; j >= 0; j--) {

                 if (myPIs[j].appliedObjectStyle.name === "Repro Note") {

                      myPIs[j].itemLayer = "Repro Notes";

                 }

            }

             

            Thanks again,

            Lewis

            • 3. Re: Move all objects assigned an Object Style to a specific layer?
              Dave Saunders Level 4

              Ah, sorry about that. The script makes the unfounded assumption that every object has an object style applied to it.

               

              Try this variant:

               

              myDoc = app.documents[0];

              myPIs = myDoc.pageItems.everyItem().getElements();

              for (var j = myPIs.length - 1; j >= 0; j--) {

                   try {

                        if (myPIs[j].appliedObjectStyle.name === "Repro Note") {

                             myPIs[j].itemLayer = "Repro Notes";

                        }

                   } catch(e) {}; // ignore items that have no object style

              }

               

               

              Dave

              • 4. Re: Move all objects assigned an Object Style to a specific layer?
                lewis_cooper Level 1

                Thank you so much Dave, that worked an absolute treat.

                 

                As expected the ones that were in a group were not detected, but they are few and far between enough to not be a problem.

                 

                Thanks again!