8 Replies Latest reply on Jun 29, 2011 3:59 AM by dmtetard

    Move all objects to seperate layers

    dmtetard Level 1

      I'm looking for a script that moves every object or group to a separate layer.

      In other words, a file with 50 objects should be turned into a file with 50 layers, each one having one object on it.

       

      With every object on a single layer, i can use this great script from rob day (http://forums.adobe.com/message/2080605) to export every indesign layer to photoshop layer, resulting in a psd with every indesign object on a seperate layer.

       

      Thanks in advance!

        • 1. Re: Move all objects to seperate layers
          TᴀW Adobe Community Professional & MVP

          The general direction would probably be something like:

           

          myItems = app.activeDocument.pageItems.everyItem();

           

          for (aa = 0; aa<myItems.length; aa++){

           

          and then something to move the specific item to a new layer. I can't remember offhand whether you need to first create the layer and then move it, or simply changed it's current applied layer setting. So something like:

           

          myItems(aa).appliedLayer = app.activeDocument.layers.add()

           

          }

           

          But I haven't checked the name of these methods and properties, because I don't remember them offhand without looking it up. E.g. is it appliedLayer, or activeLayer, or just layer? And is layers a property of document (probably). These things will need to be looked up.

           

          So this is just a general direction, I hope.

           

          Thanks,

          Ariel

          • 2. Re: Move all objects to seperate layers
            dmtetard Level 1

            Thanks!

            With your code (below) i get the following message:

             

            Object does not support the property or method 'length'.

             

            myItems = app.activeDocument.pageItems.everyItem();
             for (aa = 0; aa<myItems.length; aa++){
             myItems(aa).appliedLayer = app.activeDocument.layers.add()
            }
            

             

            I'm affraid i don't know javascript, so this is chinese to me...

            • 3. Re: Move all objects to seperate layers
              TᴀW Adobe Community Professional & MVP

              Could be that it's app.activeDocument.allPageItems;

               

              but as I say, this is just a general idea. The real methods and

              properties will have to be looked up and double-checked, because unlike

              some people here, I don't know this stuff by heart. (Unfortunately I

              don't have time now to look this up.)

               

              Bottom line: don't expect the script to work as is.

              • 4. Re: Move all objects to seperate layers
                [Jongware] Most Valuable Participant

                Arïel wrote:

                [...] I haven't checked the name of these methods and properties, because I don't remember them offhand without looking it up. E.g. is it appliedLayer, or activeLayer, or just layer? And is layers a property of document (probably). These things will need to be looked up.

                 

                Here's a quick way. Go to http://jongware.mit.edu/idcsjs5.5 (that's the definitions for CS5.5, the most current, and probably what the OP is using). Scroll to bottom, click Index. Click D to quickly go down the alphabetic list, then choose Document. (Of course I knew beforehand 'activeLayer' is a Document property.) The Document properties show it is actually called activeLayer, so you were almost correct! But not for actual page items, though.

                 

                This is an instance of Layer, so further digging down leads you to the Layer page.

                About halfway down, you can find the list "Element of", and here you see all of the different page items, including PageItem itself, and how the property is called -- it's itemLayer.

                 

                Near the bottom of the Layer page, you can find the "Return" list, which is a list of all functions that return a layer instance. One of these is Layer.add, and since 'itemLayer' is read/write,  I'm guessing your shortcut of moving an item immediately to a newly added layer should work just fine.)

                • 5. Re: Move all objects to seperate layers
                  [Jongware] Most Valuable Participant

                  (That's all online, by the way. You can also download these same HTML pages, or a handy CHM all-in-one solution, from my pages: http://www.jongware.com/idjshelp.html.

                   

                  The CHM version is quite powerful, since the best CHM viewers allow both indexed and full text search!)

                  • 6. Re: Move all objects to seperate layers
                    Marijan Tompa [tomaxxi] Level 4

                    Do you maybe have CHM for InDesign CS5.5?

                     

                    --

                    Marijan

                    • 7. Re: Move all objects to seperate layers
                      dmtetard Level 1

                      Well thanks all, but i still can't get it to work.

                      Sorry about being a total script noob...

                       

                      If anyone could make this script to work, i would greatly appreciate it!

                      I'm on CS5 btw, but i guess this won't matter for this script.

                       

                      Thanks!

                      • 8. Layer order messed up
                        dmtetard Level 1

                        Ok, after some copy-pasting and editing lines from other scripts i ended up with the following working script:

                         

                        for (aa = 0; aa<app.activeDocument.pageItems.length; aa++){
                        
                        currentItem = app.activeDocument.pageItems.item(aa)
                        newLayer = app.activeDocument.layers.add();
                        currentItem.move(newLayer);
                        }
                        
                         alert("Done");
                        

                         

                        However, the layer order doesn't match the original object order. Many object appear behind the background now.

                        I'm not sure how indesign assigns numbers to the objects.

                         

                        Any ideas on that?