3 Replies Latest reply on Oct 29, 2014 2:21 AM by pixxxel schubser

    Change containing layer

    Nik Ska Level 1

      I want to change a containing layer for any given layer. More generally, parent N layers to one containing layer. How do I do this?

        • 1. Re: Change containing layer
          pixxxel schubser Level 5

          Hi Nik Ska,

          do you mean something like this?

          // LayersToSublayers.jsx
          
          // https://forums.adobe.com/thread/1620567
          // quick&dirty (but only for the first top level layer)
          // use it on your own risk
          // regards pixxxelschubser
          var aDoc = app.activeDocument;
          var theLayers = aDoc.layers;
          var newTopLevel = aDoc.layers.add();
          newTopLevel.name = "Top level"
          
          var sublayer = newTopLevel.layers.add();
          sublayer.name = theLayers[1].name;
          theLayers[1].visible = true;
          theLayers[1].locked = false;
          
          pI = theLayers[1].pageItems;
          
          for (k=pI.length-1; k>=0;k--) {
          pI[k].visible = true;
          pI[k].locked = false;
          pI[k].move(sublayer, ElementPlacement.PLACEATBEGINNING);
          }
          
          // remove the empty layer
          theLayers[1].remove();
          
          
          
          

           

          Note: all page items will be visible and unlocked

           

          Layers2Sublayers_1.png

           

          Layers2Sublayers_2.png

           

          Have fun

           

           

          (Otherwise two screenshots of your layers palette please (before and after))

          • 2. Re: Change containing layer
            Nik Ska Level 1

            Thank you! Illustrator Scripting reference is really poor and lacking examples, so I'm having a hard time getting in.

            • 3. Re: Re: Change containing layer
              pixxxel schubser Level 5

              Hi,

              You're welcome.


              But yesterday I was thinking too complicated.

              You can move the layers directly:

              // LayersToSublayers_better.jsx
              
              // https://forums.adobe.com/thread/1620567
              // quick&dirty (but only for the first top level layer)
              // use it on your own risk
              // regards pixxxelschubser
              var aDoc = app.activeDocument;
              var theLayers = aDoc.layers;
              var count = theLayers.length;
              var newTopLevel = aDoc.layers.add();
              newTopLevel.name = "Top level";
              
              theLayers[1].move(newTopLevel, ElementPlacement.PLACEATBEGINNING);
              

               

              Have fun