4 Replies Latest reply on Dec 20, 2012 8:54 AM by ScriptingRules

    Move pageItems from one layer to another

    ScriptingRules

      I am working on a script to standardize layers and I need to move all the pageItems from a layer called "PART_NUMBER" to a layer named "STATIC".

       

      Can someone help me straighten out the following code at the arrow please...

       

      I am using "test" to troubleshoot the move.

       

      standardizeLayerNames()

      // This function verifies that the Layer names conform to the standard Layer names.
           function standardizeLayerNames()
           {
                      var myDoc7=app.activeDocument
                      var myLayerCount7 = myDoc7.layers.length

                      for(var myCounter7 = 0; myCounter7 < myLayerCount7; myCounter7++){
                              var selectLayer7 = myDoc7.layers[myCounter7]

                                  if(selectLayer7.name.substr(0,11) == "PART_NUMBER"){
                                      for(var test = selectLayer7.pageItems.length ; test >= 0 ; test --){
                                      var test1 =  selectLayer7.layers.pageItems[test]   //<----------------------------------
                                      //selectLayer7.pathItems[myCounter7].move(app.activeDocument.layers["STATIC"], ElementPlacement.PLACEATBEGINNING )
                                      }
                                  }
                      }
           }

        • 1. Re: Move pageItems from one layer to another
          Larry G. Schneider Adobe Community Professional & MVP

          You're mixing pageItems and pathItems in the last couple of lines.

          • 2. Re: Move pageItems from one layer to another
            CarlosCanto Adobe Community Professional & MVP
            var test1 =  selectLayer7.layers.pageItems[test]   //<------

             

             

            couple of things, if you have 3 objects, test = 3, but your items indexes are 0,1,2, you have to target your elements 1 less than the count.

            var test1 =  selectLayer7.layers.pageItems[test-1]

             

            however, you have an extra layer that needs to be removed

            var test1 =  selectLayer7.pageItems[test-1];

            • 3. Re: Move pageItems from one layer to another
              ScriptingRules Level 1

              I agree that the line that is commented out needs to be adjusted.

               

              The test1 line is the line is what I will use to adjust the last line.

               

              The error I'm getting is "No Such Element" on the line:

               

              var test1 =  selectLayer7.pageItems[test-1];

              I have been having this problem from the get go and it seems like the structure is wrong.

              • 4. Re: Move pageItems from one layer to another
                ScriptingRules Level 1

                Ok, after spending a few more seconds troubleshooting, the for statement needed only a greater than symbol instead of >=  the final solution is as follows.  Thanks for the indexing help I appreciate it...

                 

                     function standardizeLayerNames()
                     {
                                var myDoc7=app.activeDocument
                                var myLayerCount7 = myDoc7.layers.length

                                for(var myCounter7 = 0; myCounter7 < myLayerCount7; myCounter7++){
                                        var selectLayer7 = myDoc7.layers[myCounter7]
                                            if(selectLayer7.name.substr(0,11) == "PART_NUMBER"){
                                                for(var test = selectLayer7.pageItems.length ; test > 0 ; test --){
                                                var test1 =  selectLayer7.pageItems[test-1];
                                                selectLayer7.pageItems[test-1].move(app.activeDocument.layers["STATIC"], ElementPlacement.PLACEATBEGINNING )
                                                }
                                            }
                                 }
                     }