2 Replies Latest reply on Nov 4, 2013 2:38 PM by aoswood

    Changing Object Style

    aoswood

      I have a script that adds a stroke around the piece, that is a spot color called Dieline. It works great except if the supplied file has a Object Style defined. The box it creates has that style applied to it. I would like to change the Object style to "None" but am having troubles figuring out how to accomlish this.

       

      Any help would be greatly appriecatated.

       

      //Script to create dieline at page size

       

       

      main();

       

       

      function main(){

          var myDocument = app.activeDocument;

          var myDielineColor = getOrAddColor(myDocument, "Dieline", ColorModel.spot, [100, 0, 0, 0])

          var myNoneSwatch = myDocument.swatches.itemByName("None");

       

       

          createLayer(myDocument, "Dieline");

       

       

          for (x=0;  x < app.activeDocument.pages.length ; x++) {

              myPage = app.activeDocument.pages[x]

              var myCoord = myPage.bounds;

       

       

              //Create the rectangle and move it to the Dieline layer

              var myRect = myPage.rectangles.add({fillColor:myNoneSwatch, strokeColor:myDielineColor, geometricBounds:(myCoord)});

              myRect.itemLayer = myDocument.layers.itemByName("Dieline");

       

       

          }

      }

       

       

      function createLayer(myDocument, myLayer){

           if(!myDocument.layers.item(myLayer).isValid){

               myDocument.layers.add({name:myLayer})

               .move(LocationOptions.AT_BEGINNING)

           };

      }

       

       

      function getOrAddColor(myDocument, myColorName, myColorModel, myColorValue){

                if(!myDocument.colors.item(myColorName).isValid){

              var myColor = myDocument.colors.add();

              myColor.name = myColorName;

              myColor.model = myColorModel;

              myColor.colorValue = myColorValue;

           }

           else {

              var myColor = myDocument.colors.itemByName(myColorName);

                }

          return myColor

      }

        • 1. Re: Changing Object Style
          Jump_Over Level 5

          Hi,

           

          Do it in two separate steps:

          1. apply objectStyle "None"

          2. apply your properties

           

          so inside your loop:

           

          ...
          var myRect = myPage.rectangles.add( { appliedObjectStyle: myDocument.objectStyles.item(0) } );
          myRect.properties = {
               fillColor:myNoneSwatch, 
               strokeColor:myDielineColor, 
               geometricBounds: myCoord
               };
          myRect.itemLayer = myDocument.layers.itemByName("Dieline");
          ...
          

           

          Jarek

          • 2. Re: Changing Object Style
            aoswood Level 1

            Thanks a bunch I was trying to do it all in one step and was banging my head against the wall. This makes sense.