4 Replies Latest reply on Aug 2, 2011 2:09 PM by Danny Noonan

    CS5 JS-Apply Transparency Question

    Danny Noonan Level 1

      Hello,

      I am having trouble applying transparency to some ovals I'm creating with a script. I've used script in the past to apply drop shadows but this seems a little different. I'm trying to apply Feathering and Glows and I just can't seem to figure this out. The current script I am running does some basic document preperation and the ovals are going to be used by the person who builds the page. If you could help me apply the inner glow, hopefully I will be able to figure out the feathering. Thanks for any help in advance.

       

      The Inner Glow Presets:

      InnerGlow.png

       

      And the Script:

       

      var myDoc = app.activeDocument;
      
      //Set measurement units to inches
      myDoc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.inches;
      myDoc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.inches;
      myDoc.viewPreferences.rulerOrigin = RulerOrigin.pageOrigin;
      //Zero out the document
      myDoc.zeroPoint = [0,0]
      
      //Unlock any of the locked layers     boolean 
      myDoc.layers.everyItem().locked=false
      
      //Create layer and move it to the bottom, name New Layer, Set color to Charcoal
      var myLayer = myDoc.layers.add();
      myLayer = myLayer.move(LocationOptions.atEnd)
      myLayer.name = "New Layer";
      myLayer.layerColor = UIColors.CHARCOAL;
      
      //Find swatches with values 0,0,0,100 and merge with Black swatch
      var myColors = myDoc.colors;
      var myBlack = myDoc.swatches.itemByName("Black");
      
      for (i = myColors.length-1; i >= 0; i--) {
          var myColor = myColors[i];
          if (myColor.colorValue == "0,0,0,100" && myColor.name != "Black"){
              myColor.remove(myBlack);
          }
      }
      
       
       // Add 25% Black swatch  
          try{
      myDoc.colors.item("25% Black").name;
      }
      catch (myError){
      myDoc.colors.add({name:"25% Black", model:ColorModel.process,
      colorValue:[0, 0, 0, 25]});
      }
      
      //What Pages should the ovals be put on-All Spreads
      var myPage = myDoc.spreads.everyItem();
      
      
      //Create the ovals and specify their size and location...
      var myLeftOval = myPage.ovals.add({geometricBounds:[2, -3, 2.75, -.75], fillColor:myDoc.colors.item("25% Black"),strokeColor:myDoc.swatches.item("None"), itemLayer:myDoc.layers.item("New Layer")});
      
      var myCenterOval = myPage.ovals.add({geometricBounds:[3, -3, 3.75, -.75], fillColor:myDoc.colors.item("25% Black"),strokeColor:myDoc.swatches.item("None"), itemLayer:myDoc.layers.item("New Layer")});
      
      var myRightOval = myPage.ovals.add({geometricBounds:[4, -3, 4.75, -.75], fillColor:myDoc.colors.item("25% Black"),strokeColor:myDoc.swatches.item("None"), itemLayer:myDoc.layers.item("New Layer")});
      
       
      

       

      Thanks again for any help with this, I am at a dead end.

       

      Danny

        • 1. Re: CS5 JS-Apply Transparency Question
          milligramme Level 3

          Hi

          You can get current value of inner glow settings with this snippet in javascript console.

           

          var obj=app.activeDocument.selection[0];
          $.writeln(obj.transparencySettings.innerGlowSettings.properties.toSource().replace(/,/g,",\n"));
          

           

           

           

          And then, edit value what you want.

          You can edit other transparency settings like this.

           

           

          with (obj.transparencySettings.innerGlowSettings){
            applied = true;
            blendMode = 1852797549/*BlendMode.NORMAL*/;
            opacity = 100;
            noise = 0;
            effectColor = "Paper";
            technique = 2020618338/*GlowTechnique.PRECISE*/;
            spread = 79;
            size = '0.125in';
            source = 2020618594 /*InnerGlowSource.EDGE_SOURCED*/;  
          }
          

           

          Thankyou

          mg.

          1 person found this helpful
          • 2. Re: CS5 JS-Apply Transparency Question
            Danny Noonan Level 1

            Thanks for your reply milligramme. I didn't realize I needed to get the current vallue of the applied transparency before applying transparency. But I was hoping to add this script to the script I originally posted. If I could apply these settings to myLeftOval, myCenterOval and myRightOval it would be great. I have attempted to change the your supplied scripts "selection" to "my""Oval" but am not having any luck. Could you possibley show me how to do this?

             

            Thanks again,

             

            Danny

            • 3. Re: CS5 JS-Apply Transparency Question
              milligramme Level 3

              Hi

              I think you should use ObjectStyle!

               

              create an Object Style and set some transparency settings, and apply this to objects

               

              var my_obj_style;
              try {  
                my_obj_style = myDoc.objectStyles.add({name:"inner glow setting"});
              }
              catch(e){
                my_obj_style = myDoc.objectStyles.item("inner glow setting");
              }
              with (my_obj_style.transparencySettings.innerGlowSettings){
                applied = true;
                blendMode = 1852797549/*BlendMode.NORMAL*/;
                opacity = 100;
                noise = 0;
                effectColor = "Paper";
                technique = 2020618338/*GlowTechnique.PRECISE*/;
                spread = 79;
                size = '0.125in';
                source = 2020618594 /*InnerGlowSource.EDGE_SOURCED*/;  
              } 
              //Create the ovals and specify their size and location...
              var myLeftOval = myPage.ovals.add({geometricBounds:[2, -3, 2.75, -.75], fillColor:myDoc.colors.item("25% Black"),strokeColor:myDoc.swatches.item("None"), itemLayer:myDoc.layers.item("New Layer"),appliedObjectStyle:my_obj_style});
               
              var myCenterOval = myPage.ovals.add({geometricBounds:[3, -3, 3.75, -.75], fillColor:myDoc.colors.item("25% Black"),strokeColor:myDoc.swatches.item("None"), itemLayer:myDoc.layers.item("New Layer")});
               
              var myRightOval = myPage.ovals.add({geometricBounds:[4, -3, 4.75, -.75], fillColor:myDoc.colors.item("25% Black"),strokeColor:myDoc.swatches.item("None"), itemLayer:myDoc.layers.item("New Layer"),appliedObjectStyle:my_obj_style});
              
              
              

               

               

              I didn't apply object style to center oval, on purpose.

               

               

              Thankyou

              mg.

              • 4. Re: CS5 JS-Apply Transparency Question
                Danny Noonan Level 1

                This worked great, the only change I had to make was to add the fill color, stroke color etc. to the object style otherwise the ovals came up with no fills.

                Thanks milligramme. You've been a tremendous help with this!

                 

                Danny