2 Replies Latest reply on Sep 17, 2014 7:52 PM by milligramme

    Select only one layer for my Script

    d1y

      Hey there,

       

      I am a newbie and just made this script with the help of other topics:

      it helps me to change the import options of all .ai's (pdfs) in my document

       

      var d = app.activeDocument;

      var g = d.allGraphics;

      app.pdfPlacePreferences.pdfCrop = PDFCrop.CROP_TRIM;

      for (i=0; i<d.allGraphics.length; i++) {

           g = d.allGraphics[i];

           g.absoluteHorizontalScale = 100; // Horizontal Scale

           g.absoluteVerticalScale = 100; // Vertical Scale

           g.place(g.itemLink.filePath);

      }

       

      now i have the problem that i only want to use this on one layer of my document, but he changes every ai.

       

      How can i tell the script which layer he has to change or that the script doesnt change locked layers?

       

      Sry for my bad english

        • 1. Re: Select only one layer for my Script
          BEGINNER_X Level 3

          Hi,

           

          Use the below code,

           

          var d = app.activeDocument;
          var g = d.allGraphics;
          
          for (i=0; i<d.allGraphics.length; i++) {
              if(d.allGraphics[i].itemLayer.name == "RED")
              {
               g = d.allGraphics[i];
               g.absoluteHorizontalScale = 100; // Horizontal Scale
               g.absoluteVerticalScale = 100; // Vertical Scale
               }
          }
          

           

           

          Regards

          Siraj

          • 2. Re: Select only one layer for my Script
            milligramme Level 3

            Hi try this code

             

            it can't change objects' properties on locked layer.

             

            var d = app.activeDocument;
            var l = d.layers.item("RED");
            var ag = l.allGraphics;
            app.pdfPlacePreferences.pdfCrop = PDFCrop.CROP_TRIM;
            
            
            if (l.locked) {
              alert('the layer is locked');
              exit();
            }
            
            
            for (i=0; i< ag.length; i++) {
              var g = ag[i];
              g.absoluteHorizontalScale = 100; // Horizontal Scale
              g.absoluteVerticalScale = 100; // Vertical Scale
              g.place(g.itemLink.filePath);
            }