4 Replies Latest reply on Jun 28, 2017 2:29 PM by pixxxel schubser

    Renaming Sub-Layer

    PrepressPro1 Adobe Community Professional

      I have this tiny script to rename a Sub-layer which works the first time I use it, then it adds to the existing sub-layer name when I run it after the first time.

       

       

      var docRef = activeDocument;   
      var sel = docRef.selection;   
      for (var i=0; i < sel.length; i++)   
           sel[i].name = "CUTTER_B" + sel[i].name;

       

       

      Any way to get this to consistently rename the sub-layer?

        • 1. Re: Renaming Sub-Layer
          pixxxel schubser Level 5

          Hi PrepressPro1

          your code only works with page items - not with sublayers.

           

          Unfortunately you didn't answer one month ago.

          select by layer name

          "… is this "sublayer" really a sublayer? Or a grouped item instead? …"

          Same question again.

           

          For selected page items you can do something like this

          var docRef = activeDocument;
          var sel = docRef.selection;
          for (var i=0; i < sel.length; i++) {
              var nme = sel[i].name.replace("CUTTER_B","");
              sel[i].name = "CUTTER_B" + nme;
          }
          

           

          Have fun

           

          • 2. Re: Renaming Sub-Layer
            PrepressPro1 Adobe Community Professional

            It is an object on a sub-layer. Sorry for the hiatus in my posting. Projects get back burnered with the press of production work.  Thank you for your reply.

            • 3. Re: Renaming Sub-Layer
              PrepressPro1 Adobe Community Professional

              Here is the sub-layer before running the scrip with the object selected.

               

               

              Screen Shot 2017-06-28 at 2.07.30 PM.png

               

              After the script is run.

               

              Screen Shot 2017-06-28 at 2.08.00 PM.png

               

              It still adds the name instead of replacing the name.

              • 4. Re: Renaming Sub-Layer
                pixxxel schubser Level 5

                That makes no difference. Same procedere as for page items

                var docRef = activeDocument;
                var sel = docRef.activeLayer;
                //var sel = docRef.selection;
                //for (var i=0; i < sel.length; i++) {
                    //var nme = sel[i].name.replace("CUTTER_B","");
                    var nme = sel.name.replace("CUTTER_B","");
                    sel.name = "CUTTER_B" + nme;
                    //sel[i].name = "CUTTER_B" + nme;
                //}
                

                 

                Have fun

                 

                 

                Or if I understood you wrong: Would you replace the whole name with Cutter_B?

                Then: sel.name = "CUTTER_B"