2 Replies Latest reply on Oct 5, 2012 4:29 AM by jason@micrographix.co.uk

    Select ungrouped items, change opacity and save

    jason@micrographix.co.uk Level 1

      Hi, I am a javascript beginner trying to create a script to do the following to several . ai files, one at a time:

       

      1. open document
      2. select all items
      3. change opacity to 40%
      4. select all grouped items
      5. change opacity to 100%
      6. save and close

       

      This is what I have so far which I know only affects the opacity of one layer, but if anybody has any tips for what I can do next, it would be greatly appreciated.

       

      for ( i = 0; i < app.documents.length; i++ ) {

          var targetDocument = app.documents[i];

          var layerCount = targetDocument.layers.length;

       

              for (var ii = layerCount - 1; ii >= 0; ii-- ) {

                  targetLayer = targetDocument.layers[ii];

                  var layerName = new String( targetLayer.name );

       

                      if ( layerName.indexOf("TEST") == 0 ) {

                          targetDocument.layers[ii].opacity=40.0;

                      }

              }

      targetDocument.close;

      targetDocument = null;

      }

        • 1. Re: Select ungrouped items, change opacity and save
          Muppet Mark Level 5

          You don't select in script but does this do what you meant?

          #target illustrator
          
          setObjectOpacity()
          
          function setObjectOpacity() {
              
              var doc = app.activeDocument;
              
              for ( var i = 0; i < doc.pageItems.length; i++ ) {
                      
                  doc.pageItems[i].opacity = 40; // This will do everything
                  
              };
              
              for ( var i = 0; i < doc.groupItems.length; i++ ) {
                  
                  doc.groupItems[i].opacity = 100; // Put this back
                  
                  for ( var j = 0; j < doc.groupItems[i].pageItems.length; j++ ) {
                      
                      doc.groupItems[i].pageItems[j].opacity = 100; // Put these back too
                      
                 };
                  
              }; 
              
          };
          
          
          • 2. Re: Select ungrouped items, change opacity and save
            jason@micrographix.co.uk Level 1

            That is perfect Muppet Mark, thanks very much. I will enclose it in a script to open and close the documents.

            Cheers