2 Replies Latest reply on Nov 20, 2013 6:38 AM by florin.popa1986

    moving all layers into a single layer

    florin.popa1986

      Hello,

       

      I'm new in scripting and i need to make a script that moving all layers into a single layer( in Illustrator i press CTRL+A then CTRL+G in layers and works) but i need that in script

      Please could somebody help me?

      Thanks!

        • 1. Re: moving all layers into a single layer
          florin.popa1986 Level 1

          i try this function but is different (ctrl A + ctrl G does something else)

          main();

           

          function main() {

           

                    if ( app.documents.length == 0 ) { return; }

           

                    app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;

           

                    var doc = app.activeDocument;

           

                    var mast = doc.layers.add();

           

                    mast.name = 'original';

           

                    for ( var  i = doc.layers.length-1; i >= 1; i-- ) {

           

                              doc.layers[i].move( mast, ElementPlacement.PLACEATBEGINNING )

           

                    };

                    

          };

          • 2. Re: moving all layers into a single layer
            florin.popa1986 Level 1

            i found the solution

             

            function main() {

             

             

            if ( app.documents.length == 0 ) { return; }

             

             

            app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;

             

             

            var doc = app.activeDocument;

             

             

            var mast = doc.layers.add();

             

             

            mast.name = 'original';

            var grup=mast.groupItems.add();

            //   var pageIt=mast.pageItems.add();

            while (doc.layers.length > 1)

            {

            while (doc.layers[doc.layers.length - 1].pageItems.length)

            doc.layers[doc.layers.length - 1].pageItems[doc.layers[doc.layers.length - 1].pageItems.length - 1].move( grup, ElementPlacement.PLACEATBEGINNING );

            doc.layers[doc.layers.length - 1].remove();

            }

            }