11 Replies Latest reply on Aug 18, 2013 1:23 AM by Mikaeru69

    Get layer style parameters?

    Sombrero

      How is it possible to set and get layer style parameters? For example read out stroke size, shadow distance, etc...

        • 1. Re: Get layer style parameters?
          Paul Riggott Level 6

          Not easy, as an example of getting a layers Pattern effect details it would on the lines of ...

           

           

          var P ={}
          P = patternFX();
          for(var a in P){
              $.writeln(a + " = " + P[a]);
          }
          function patternFX(){
          var Pattern ={};
          var ref = new ActionReference();
          ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
          var desc = executeActionGet(ref);
          if(desc.hasKey(stringIDToTypeID( 'layerEffects' ))){
          if(!desc.getBoolean (stringIDToTypeID( 'layerFXVisible'))) return undefined;
          desc = desc.getObjectValue(stringIDToTypeID('layerEffects'));
          if(!desc.hasKey(stringIDToTypeID( 'patternFill'))) return null;
          desc = desc.getObjectValue(stringIDToTypeID('patternFill'));
          Pattern.Enabled = desc.getBoolean(stringIDToTypeID('enabled'));
          Pattern.Mode = typeIDToStringID(desc.getEnumerationValue( stringIDToTypeID( 'mode' )));
          Pattern.Opacity = desc.getUnitDoubleValue (stringIDToTypeID( 'opacity' ));
          Pattern.Scale = desc.getUnitDoubleValue (stringIDToTypeID( 'scale' ));
          Pattern.Align = desc.getBoolean (stringIDToTypeID( 'align'));
          var patDesc = desc.getObjectValue(stringIDToTypeID('pattern'));
          Pattern.Name = patDesc.getString(stringIDToTypeID('name'));
          Pattern.ID = patDesc.getString(stringIDToTypeID('ID'));
          var phaseDesc = desc.getObjectValue(stringIDToTypeID('phase'));
          Pattern.PhaseHorizontal = phaseDesc.getUnitDoubleValue (stringIDToTypeID( 'horizontal' ));
          Pattern.PhaseVertical = phaseDesc.getUnitDoubleValue (stringIDToTypeID( 'vertical' ));
          
          }
           return Pattern;
          };
          
          

           

          To get a better idea download Xbytors xtools.

          • 2. Re: Get layer style parameters?
            Sombrero Level 1

            Wow! Paul, you are real a HERO!

             

            I am looking for a code like yours for days, this is the first one that is doing exatly what I want. It is working perfectly! Based on this I will be able to do the equialent for the other effects.

             

            Is there a good description anywhere that explains how this ActionReference and other stuff works? In the official adobe documentation there is nothing about it, with I can start.

             

            Do you know any code snippet that is doing this in the other direction? I mean set the layer FX params.

             

            Sorry for my stupid english...

             

            And thanx a lot!

             

            Daniel

            • 3. Re: Get layer style parameters?
              Paul Riggott Level 6

              There are many problem with setting FXs as if you change one effect the others are wiped out.

              I think there are some threads on this over at www.ps-scripts.com where you will also find details on xtools.

              xtools is a huge library of functions that cover most scripting functions with Photoshop and it's worth reading the documentation that comes with it.

              • 4. Re: Get layer style parameters?
                Paul Riggott Level 6

                This might help you get the details of a layer....

                 

                 

                var ref = new ActionReference();
                ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
                var desc = executeActionGet(ref);//.getObjectValue(stringIDToTypeID('layerEffects')).getObjectValue(stringIDToTypeID('patternFill'));
                $.writeln(desc);
                var c = desc.count
                if(desc.typename == 'ActionReference'){
                    var c = desc.count;
                    for(var i=0;i<c;i++){ //enumerate reference. use getForm() to determine which get method to use
                      $.writeln('AR '+zeroPad( i+1, 2 )+' = '+desc.getReference(i).getIndex()); 
                    }
                }
                if(desc.typename == 'ActionList'){
                    var c = desc.count;
                    for(var i=0;i<c;i++){ //enumerate list
                     $.writeln('AL '+zeroPad( i+1, 2 )+' = '+desc.getType(i)/* added desc.getPath(i) for aliastype */ +' - ' + typeIDToStringID(desc.getClass (i)));
                    }
                }
                if(desc.typename == 'ActionDescriptor'){
                    var c = desc.count;
                    for(var i=0;i<c;i++){ //enumerate descriptor's keys
                      $.writeln('AD '+zeroPad( i+1, 2 )+' = '+IDTz(desc.getKey(i)) +' : '+desc.getType(desc.getKey(i))); 
                    }
                }
                function IDTz(id){
                     try {
                          var res = typeIDToStringID( id );
                          if(res == '' ){
                               var res = typeIDToCharID( id );
                          }
                     }catch(e){}
                     return res;
                }
                function zTID( s ){
                     if( s.length == 4 ) var res = charIDToTypeID( s );
                     if( s.length > 4 ) var res = stringIDToTypeID( s );
                     return res;
                }
                function zeroPad(num,pad) {
                     var z = Math.pow(10,Number(pad))
                     return num <= z ? ((Number( num) + z).toString().substr(1)): num
                }
                
                
                1 person found this helpful
                • 6. Re: Get layer style parameters?
                  Michael L Hale Level 5

                  To add to Paul's comments and suggestions.

                   

                  Working with layer styles or effects is not easy for many reasons. The main problem is documentation. I don't know of any Adobe documentation. There may be some in the Photoshop SDK. Here are some other reasons:

                   

                  1. You have to use Action Manger.

                  2. The structure of the effect descriptor varys a lot. Each effect has it's own structure as one would expect and some are more complex than others.

                  3. The color mode of the document can effect the structure of the effect

                  4. The language version of Photoshop requires different string to be used for some setting.

                  5. An effect descriptor may not contain all the effect options. You can use ActionDescriptor.hasKey() to check before trying a access a key.

                  6. As Paul said, writing to an effect is harder than getting an info from an effect if you want to maintain the other existing setting of all the effect a layer may have.

                   

                  So I would say make sure you change all the settings in an effect when you create one to study it's descriptor. Also make several using different color modes. That will make sure you don't miss any setting you want.

                   

                  I have worked on a good way to get/set effect for a while now in my spare time. And I am getting closer to having something I can be happy with. Here is an example of my currrent approach for editing an effect. It makes a copy of the entire effect descriptor and updates using the new arguments.

                   

                  // helper function for working with descriptors
                  function getActiveLayerProperty( psKey, psType ) {
                      var ref = new ActionReference();
                      ref.putProperty( charIDToTypeID( 'Prpr' ), psKey );
                      ref.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
                      if( undefined == psType ){
                        return executeActionGet( ref ).getObjectValue( psKey );
                      }else{
                          return executeActionGet( ref );
                      }
                  };
                  function duplicateDescriptor( descriptor ) {
                      var newDescriptor = new ActionDescriptor;
                      newDescriptor.fromStream( descriptor.toStream() );
                      return newDescriptor;
                  };
                  function localizeDescriptor( desc ) {
                      var stream, pointer, zStringLength, zstring, localized_string, newZStringLength, previousStream, followingStream, newDesc;
                      stream = desc.toStream();
                      while( true ) {
                          pointer = stream.search(/TEXT....\x00\$\x00\$\x00\$/);
                          if( pointer === -1 ) {
                              break;
                          }
                          zStringLength = getLongFromStream( stream, pointer + 4 );
                          zstring = readUnicode( stream.substr( pointer + 8, ( zStringLength - 1 ) * 2) );
                          localized_string = ( localize( zstring ) ) + '\u0000';
                          newZStringLength = localized_string.length;
                          previousStream = stream.slice( 0, pointer);
                          followingStream = stream.slice( pointer + 8 + zStringLength * 2);
                          stream = previousStream.concat( 'TEXT', longToString( newZStringLength ), bytesToUnicode( localized_string ), followingStream );
                      }
                      newDesc = new ActionDescriptor();
                      newDesc.fromStream( stream );
                      return newDesc;
                  };
                  function getShortFromStream( stream, pointer ) {
                      var hi, low;
                      hi = stream.charCodeAt( pointer ) << 8 ;
                      low = stream.charCodeAt( pointer + 1 );
                      return hi + low;
                   };
                  function getLongFromStream( stream, pointer ) {
                      var hi, low;
                      hi = getShortFromStream( stream, pointer) << 16;
                      low = getShortFromStream( stream, pointer + 2);
                      return hi + low;
                  };
                  function readUnicode( unicode ) {
                      var string = "";
                      for( i = pointer = 0; pointer < unicode.length; i = pointer += 2) {
                          string +=String.fromCharCode( getShortFromStream( unicode, pointer ) );
                      }
                      return string;
                  };
                  function longToString( longInteger ) {
                      var string;
                      string = String.fromCharCode( longInteger >>> 24 );
                      string += String.fromCharCode( longInteger << 8 >>> 24 );
                      string += String.fromCharCode( longInteger << 16 >>> 24 );
                      string += String.fromCharCode( longInteger << 24 >>> 24 );
                      return string;
                  };
                  function bytesToUnicode( bytes ) {
                      var unicode = "", char_code, charIndex;
                      for( charIndex  = 0; charIndex < bytes.length; charIndex ++ ) {
                          char_code = bytes.charCodeAt( charIndex );
                          unicode += String.fromCharCode(char_code >> 8 ) +  String.fromCharCode( char_code & 0xff );
                      }
                      return unicode;
                  };
                  
                  
                  function setInnerGlow( opts ) {
                      var layerEffects, newLayerEffects, currentDesc, newDesc, colorDesc, newLayerEffects, layerDesc, targetDesc, setDesc;
                      layerEffects = getActiveLayerProperty( charIDToTypeID( 'Lefx' ) );
                      newLayerEffects = duplicateDescriptor( layerEffects );
                      currentDesc = layerEffects.getObjectValue( charIDToTypeID( 'IrGl' ) );
                      newDesc = duplicateDescriptor( currentDesc );
                      
                      if(opts.enabled != undefined) newDesc.putBoolean( charIDToTypeID('enab'), opts.enabled );
                      if(opts.blendmode != undefined) newDesc.putEnumerated( charIDToTypeID('Md  '), charIDToTypeID('BlnM'), opts.blendmode );
                      if(opts.color != undefined){
                          var colorDesc = new ActionDescriptor();
                          colorDesc.putDouble( charIDToTypeID('Rd  '), opts.color.rgb.red );
                          colorDesc.putDouble( charIDToTypeID('Grn '), opts.color.rgb.green );
                          colorDesc.putDouble( charIDToTypeID('Bl  '), opts.color.rgb.blue );
                          newDesc.putObject( charIDToTypeID('Clr '), charIDToTypeID('RGBC'), colorDesc );
                      }
                      if(opts.opacity != undefined) newDesc.putUnitDouble( charIDToTypeID('Opct'), charIDToTypeID('#Prc'), opts.opacity );
                      if(opts.technique != undefined) newDesc.putEnumerated( charIDToTypeID('GlwT'), charIDToTypeID('BETE'), opts.technique );
                      if(opts.choke != undefined)newDesc.putUnitDouble( charIDToTypeID('Ckmt'), charIDToTypeID('#Pxl'), opts.choke );
                      if(opts.size != undefined) newDesc.putUnitDouble( charIDToTypeID('blur'), charIDToTypeID('#Pxl'), opts.size );
                      if(opts.jitter != undefined) newDesc.putUnitDouble( charIDToTypeID('ShdN'), charIDToTypeID('#Prc'), opts.jitter );
                      if(opts.noise != undefined) newDesc.putUnitDouble( charIDToTypeID('Nose'), charIDToTypeID('#Prc'), opts.noise );
                      if(opts.antialias != undefined) newDesc.putBoolean( charIDToTypeID('AntA'), false );
                      if(opts.source != undefined) newDesc.putEnumerated( charIDToTypeID('glwS'), charIDToTypeID('IGSr'), opts.source );
                      if(opts.contourName != undefined){
                          var contourrDesc = new ActionDescriptor();
                          contourrDesc.putString( charIDToTypeID('Nm  '), opts.contourName );
                          newDesc.putObject( charIDToTypeID('TrnS'), charIDToTypeID('ShpC'), contourrDesc );
                      }
                      if(opts.range != undefined) newDesc.putUnitDouble( charIDToTypeID('Inpr'), charIDToTypeID('#Prc'), opts.range );
                      newLayerEffects.putObject( charIDToTypeID('IrGl'), charIDToTypeID('IrGl'), newDesc );
                      
                      
                      newLayerEffects = localizeDescriptor( newLayerEffects );
                      layerDesc = new ActionDescriptor();
                      layerDesc.putObject( charIDToTypeID('Lefx'), charIDToTypeID('lfxv'), newLayerEffects);
                      targetDesc = new ActionReference();
                      targetDesc.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
                      setDesc = new ActionDescriptor;
                      setDesc.putObject( charIDToTypeID('T   '), charIDToTypeID('Lyr '), layerDesc );
                      setDesc.putReference( charIDToTypeID('null' ), targetDesc );
                      executeAction(charIDToTypeID('setd'), setDesc, DialogModes.NO);
                  };
                  // you only need to define the option you want to change.
                  // undefined options will retain the current setting.
                  var InterGlowOptions = {};
                  // InterGlowOptions.enabled = true;
                  // InterGlowOptions.blendmode = charIDToTypeID('Drkn');
                  InterGlowOptions.color = app.foregroundColor;
                  // InterGlowOptions.opacity = 80;
                  // InnerShadow.technique = charIDToTypeID('PrBL');
                  // InterGlowOptions.choke = 100;
                  // InterGlowOptions.size = 32;
                  // InterGlowOptions.noise = 52;
                  // InterGlowOptions.jitter = 21;
                  // InterGlowOptions.antialias = true;
                  // InterGlowOptions.contourName = "$$$/Contours/Defaults/HalfRound=Half Round";
                  // InterGlowOptions.range = 45;
                  InterGlowOptions.source = charIDToTypeID('SrcC');
                  
                  /*  blend mode ID
                  charIDToTypeID( "Nrml" )// Normal
                  charIDToTypeID( "Dslv" )// Dissolve
                  charIDToTypeID( "Drkn" )// Darken
                  charIDToTypeID( "Mltp" )// Multiply
                  charIDToTypeID( "CBrn" )// Color Burn
                  stringIDToTypeID( "linearBurn" )
                  stringIDToTypeID( "darkerColor" )
                  charIDToTypeID( "Lghn" )// Lighten
                  charIDToTypeID( "Scrn" )// Screen
                  charIDToTypeID( "CDdg" )// Color Dodge
                  stringIDToTypeID( "linearDodge" )
                  stringIDToTypeID( "lighterColor" )
                  charIDToTypeID( "Ovrl" )// Overlay
                  charIDToTypeID( "SftL" )// Soft Light
                  charIDToTypeID( "HrdL" )// Hard Light
                  stringIDToTypeID( "vividLight" )
                  stringIDToTypeID( "linearLight" )
                  stringIDToTypeID( "pinLight" )
                  stringIDToTypeID( "hardMix" )
                  charIDToTypeID( "Dfrn" )// Difference
                  charIDToTypeID( "Xclu" )// Exclusion
                  stringIDToTypeID( "blendSubtraction" )
                  stringIDToTypeID( "blendDivide" )
                  charIDToTypeID( "H   " )// Hue
                  charIDToTypeID( "Strt" )// Saturation
                  charIDToTypeID( "Clr " )// Color
                  charIDToTypeID( "Lmns" )// Luminosity
                  
                  // contour name string
                   "$$$/Contours/Defaults/Linear=Linear"
                   "$$$/Contours/Defaults/Cone=Cone"
                   "$$$/Contours/Defaults/ConeInverted=Cone - Inverted"
                   "$$$/Contours/Defaults/CoveDeep=Cove - Deep"
                   "$$$/Contours/Defaults/CoveShallow=Cove - Shallow"
                   "$$$/Contours/Defaults/Gaussian=Gaussian"
                   "$$$/Contours/Defaults/HalfRound=Half Round"
                   "$$$/Contours/Defaults/Ring=Ring"
                   "$$$/Contours/Defaults/DoubleRing=Ring - Double"
                    "$$$/Contours/Defaults/RollingSlopeDescending=Rolling Slope - Descending"
                    "$$$/Contours/Defaults/RoundedSteps=Rounded Steps"
                    "$$$/Contours/Defaults/Sawtooth1=Sawtooth 1"
                    
                  // technique IDs
                  charIDToTypeID('PrBL');
                  charIDToTypeID('Scrn');
                  
                  // source ids
                  charIDToTypeID('SrcC');
                  charIDToTypeID('SrcE');
                    */
                  
                  setInnerGlow( InterGlowOptions );
                  

                   

                  I think that has everything except dealing with custom contours. And of course I may have miss something.

                  1 person found this helpful
                  • 7. Re: Get layer style parameters?
                    Marijan Tompa [tomaxxi] Level 4

                    Thanks Michael! Excellent stuff!

                    I was dealing with this lately!

                     

                    I've finally created tomaxxiFXcolor panel using Configurator!

                    http://bit.ly/TO0iaw

                    http://www.creativepro.com/article/adjust-photoshop-fx-quickly-and-easily-tomaxxifxcolor

                     

                    New version will be available on Adobe Exhange soon!

                    tomaxxiFXcolor UI.png

                    • 8. Re: Get layer style parameters?
                      Paul Riggott Level 6

                      Here is an example of Stroke details using Mikes function for getting the correct colour mode.

                       

                       

                      var S ={}
                      S = getStrokeFX();
                      for(var a in S){
                          $.writeln(a + " = " + S[a]);
                      }
                      function getStrokeFX(){
                      var Stroke ={};
                      var ref = new ActionReference();
                      ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
                      var desc = executeActionGet(ref);
                      if(desc.hasKey(stringIDToTypeID( 'layerEffects' ))){
                      if(!desc.getBoolean (stringIDToTypeID( 'layerFXVisible'))) return undefined;
                      desc = desc.getObjectValue(stringIDToTypeID('layerEffects'));
                      if(!desc.hasKey(stringIDToTypeID( 'frameFX'))) return null;
                      desc = desc.getObjectValue(stringIDToTypeID('frameFX'));
                      Stroke.Enabled = desc.getBoolean(stringIDToTypeID('enabled'));
                      Stroke.Mode = typeIDToStringID(desc.getEnumerationValue( stringIDToTypeID( 'mode' )));
                      Stroke.Style = typeIDToStringID(desc.getEnumerationValue( stringIDToTypeID( 'style' )));
                      Stroke.PaintType = typeIDToStringID(desc.getEnumerationValue( stringIDToTypeID( 'paintType' )));
                      Stroke.Opacity = desc.getUnitDoubleValue (stringIDToTypeID( 'opacity' ));
                      Stroke.Size = desc.getUnitDoubleValue (stringIDToTypeID( 'size' ));
                      if(desc.hasKey (stringIDToTypeID('color'))){
                      var cColour = getColorFromDescriptor(desc.getObjectValue(stringIDToTypeID("color")), typeIDToCharID(desc.getClass(stringIDToTypeID("color"))));
                      Stroke.Colour = cColour.rgb.hexValue;
                      }
                      if(desc.hasKey (stringIDToTypeID('gradient'))){
                      Stroke.Angle  = desc.getUnitDoubleValue (stringIDToTypeID( 'angle' ));
                      Stroke.Type = typeIDToStringID(desc.getEnumerationValue( stringIDToTypeID( 'type' )));
                      Stroke.Reverse = desc.getBoolean(stringIDToTypeID('reverse'));
                      Stroke.Dither = desc.getBoolean(stringIDToTypeID('dither'));
                      Stroke.Scale = desc.getUnitDoubleValue (stringIDToTypeID( 'scale' ));
                      Stroke.Align = desc.getBoolean(stringIDToTypeID('align'));
                      var gradientDesc = desc.getObjectValue(stringIDToTypeID('gradient'));
                      Stroke.Name = gradientDesc.getString(stringIDToTypeID('name'));
                      Stroke.GradientForm = typeIDToStringID(gradientDesc.getEnumerationValue( stringIDToTypeID( 'gradientForm' )));
                      Stroke.InterfaceIconFrameDimmed  = gradientDesc.getUnitDoubleValue (stringIDToTypeID( 'interfaceIconFrameDimmed' ));
                      var colorDesc = gradientDesc.getList(stringIDToTypeID( 'colors'));
                      var cCount = colorDesc.count;
                      Stroke.GradientColours = [];
                      Stroke.GradientType = [];
                      Stroke.GradientLocation = [];
                      Stroke.GradientMidpoint = [];
                      for(var a = 0;a<cCount;a++){
                         var gradDesc = desc.getObjectValue(stringIDToTypeID('gradient')).getList(stringIDToTypeID('colors')).getObjectValue(a);
                         var gColour = getColorFromDescriptor(gradDesc.getObjectValue(stringIDToTypeID("color")), typeIDToCharID(gradDesc.getClass(stringIDToTypeID("color"))));
                      Stroke.GradientColours.push(gColour.rgb.hexValue);
                      Stroke.GradientType.push(typeIDToStringID(gradDesc.getEnumerationValue( stringIDToTypeID( 'type' ))));
                      Stroke.GradientLocation.push(gradDesc.getInteger (stringIDToTypeID( 'location' )));
                      Stroke.GradientMidpoint.push(gradDesc.getInteger (stringIDToTypeID( 'midpoint' )));
                          }
                      var tranDesc = gradientDesc.getList(stringIDToTypeID( 'transparency'));
                      var tCount = tranDesc.count;
                      Stroke.TransparencyOpacity = [];
                      Stroke.TransparencyLocation = [];
                      Stroke.TransparencyMidpoint = [];
                      for(var a = 0;a<tCount;a++){
                         var tDesc = desc.getObjectValue(stringIDToTypeID('gradient')).getList(stringIDToTypeID('transparency')).getObjectValue(a);
                      Stroke.TransparencyOpacity.push(tDesc.getUnitDoubleValue (stringIDToTypeID( 'opacity' )));
                      Stroke.TransparencyLocation.push(tDesc.getInteger (stringIDToTypeID( 'location' )));
                      Stroke.TransparencyMidpoint.push(tDesc.getInteger (stringIDToTypeID( 'midpoint' )));
                         }
                      var offsetDesc = desc.getObjectValue(stringIDToTypeID('offset'));
                      Stroke.OffsetHorizontal = offsetDesc.getUnitDoubleValue (stringIDToTypeID( 'horizontal' ));
                      Stroke.OffsetVertical = offsetDesc.getUnitDoubleValue (stringIDToTypeID( 'vertical' ));
                          }
                      if(desc.hasKey (stringIDToTypeID('pattern'))){
                      var patternDesc = desc.getObjectValue(stringIDToTypeID('pattern'));
                      Stroke.Scale = desc.getUnitDoubleValue (stringIDToTypeID( 'scale' ));
                      Stroke.Linked = desc.getBoolean(stringIDToTypeID('linked'));
                      Stroke.PatternName = patternDesc.getString(stringIDToTypeID('name'));
                      Stroke.PatternID = patternDesc.getString(stringIDToTypeID('ID'));
                      var phaseDesc = desc.getObjectValue(stringIDToTypeID('phase'));
                      Stroke.PatternHorizontal = phaseDesc.getUnitDoubleValue (stringIDToTypeID( 'horizontal' ));
                      Stroke.PatternVertical = phaseDesc.getUnitDoubleValue (stringIDToTypeID( 'vertical' ));
                          }
                      }
                      return Stroke;
                      };
                      function getColorFromDescriptor(colorDesc, keyClass) {
                        var colorObject = new SolidColor();
                        switch (keyClass) {
                        case "Grsc":
                          colorObject.grey.grey = color.getDouble(charIDToTypeID('Gry '));
                          break;
                        case "RGBC":
                          colorObject.rgb.red = colorDesc.getDouble(charIDToTypeID('Rd  '));
                          colorObject.rgb.green = colorDesc.getDouble(charIDToTypeID('Grn '));
                          colorObject.rgb.blue = colorDesc.getDouble(charIDToTypeID('Bl  '));
                          break;
                        case "CMYC":
                          colorObject.cmyk.cyan = colorDesc.getDouble(charIDToTypeID('Cyn '));
                          colorObject.cmyk.magenta = colorDesc.getDouble(charIDToTypeID('Mgnt'));
                          colorObject.cmyk.yellow = colorDesc.getDouble(charIDToTypeID('Ylw '));
                          colorObject.cmyk.black = colorDesc.getDouble(charIDToTypeID('Blck'));
                          break;
                        case "LbCl":
                          colorObject.lab.l = colorDesc.getDouble(charIDToTypeID('Lmnc'));
                          colorObject.lab.a = colorDesc.getDouble(charIDToTypeID('A   '));
                          colorObject.lab.b = colorDesc.getDouble(charIDToTypeID('B   '));
                          break;
                        default:
                          return null;
                        }
                        return colorObject;
                      };
                      
                      
                      • 9. Re: Get layer style parameters?
                        Michael L Hale Level 5

                        marijan, I don't know if you can use ZStrings in Configurator to localize the UI. If you can would you want me to post those?

                         

                        Paul, thanks for that - it will save me some time later on.

                         

                        As I said I have been working on this when I have time and in the mood. I have been working my way down the list creating both get and set/edit functions. One of the reason I haven't gotten this done faster is I spend a lot of time thinking about if I( or most users ) want get/set everything. It would be great to get some feedback from other users.

                         

                        to everyone,

                        Do you want to be able to get/set/modify all the possible options for each effect. I haven't included custom contours as I thought they would be seldom used.

                        Should I add the extra code needed to get the UUID for gradients and patterns? I think you can set those without the IDs but there could be problem it there is more than one name.

                        Should I have range check for those values that require them when setting the value? My approach has been no but that means possible un-trapped errors.

                        Is the custom option object acceptable. I thought it would be better than a long arguments list.

                         

                        Any other suggestions or comments would be great.

                        Mike

                        • 10. Re: Get layer style parameters?
                          Sombrero Level 1

                          Your code is also a big help for me (and I believe for many others too), and works good, but is very mystical for my action manager experience.

                          I am tying to apply the technics used in your and Paul's code to do similar in the remaining layer fx, but it is not so easy that I hoped.

                          XTools is cool, but even that has no functions for handling individual layer style parameters. It would be nice to build in this functionality.

                           

                          Sorry for my english...

                          • 11. Re: Get layer style parameters?
                            Mikaeru69 Level 3

                            In case you're still interested about getting and setting layer styles parameters, I've just released a new module jamStyles of my open-source JSON Action Manager scripting library, which provides full support for blending options and layer effects using a fully-documented, simplified JSON object format.

                             

                            I've also written a quick tutorial showing how to perform a few standard operations, using mainly the two functions jamStyles.getLayerStyle and jamStyles.setLayerStyle.

                             

                            For instance, the following code sample will set a mildly complex layer style:

                             

                            var layerStyleObj =
                            {
                                "blendOptions":
                                {
                                    "fillOpacity": 70,
                                    "blendInterior": true
                                },
                                "layerEffects":
                                {
                                    "scale": 100,
                                    "dropShadow":
                                    {
                                        "enabled": true,
                                        "mode": "multiply",
                                        "color":
                                        {
                                            "red": 0,
                                            "green": 0,
                                            "blue": 0
                                        },
                                        "opacity": 70,
                                        "useGlobalAngle": false,
                                        "localLightingAngle": 90,
                                        "distance": 6,
                                        "chokeMatte": 0,
                                        "blur": 4,
                                        "noise": 0,
                                        "antiAlias": false,
                                        "transparencyShape":
                                        {
                                            "name": "Linear",
                                            "curve":
                                            [
                                                {
                                                    "horizontal": 0,
                                                    "vertical": 0
                                                },
                                                {
                                                    "horizontal": 255,
                                                    "vertical": 255
                                                }
                                            ]
                                        },
                                        "layerConceals": true
                                    },
                                    "innerShadow":
                                    {
                                        "enabled": true,
                                        "mode": "multiply",
                                        "color":
                                        {
                                            "red": 0,
                                            "green": 0,
                                            "blue": 0
                                        },
                                        "opacity": 70,
                                        "useGlobalAngle": false,
                                        "localLightingAngle": 90,
                                        "distance": 10,
                                        "chokeMatte": 15,
                                        "blur": 20,
                                        "noise": 0,
                                        "antiAlias": false,
                                        "transparencyShape":
                                        {
                                            "name": "Linear",
                                            "curve":
                                            [
                                                {
                                                    "horizontal": 0,
                                                    "vertical": 0
                                                },
                                                {
                                                    "horizontal": 255,
                                                    "vertical": 255
                                                }
                                            ]
                                        }
                                    },
                                    "innerGlow":
                                    {
                                        "enabled": true,
                                        "mode": "linearDodge",
                                        "color":
                                        {
                                            "red": 255,
                                            "green": 246,
                                            "blue": 168
                                        },
                                        "opacity": 31,
                                        "glowTechnique": "preciseMatte",
                                        "chokeMatte": 0,
                                        "blur": 20,
                                        "shadingNoise": 0,
                                        "noise": 0,
                                        "antiAlias": true,
                                        "innerGlowSource": "centerGlow",
                                        "transparencyShape":
                                        {
                                            "name": "Half Round",
                                            "curve":
                                            [
                                                {
                                                    "horizontal": 0,
                                                    "vertical": 0
                                                },
                                                {
                                                    "horizontal": 29,
                                                    "vertical": 71
                                                },
                                                {
                                                    "horizontal": 87,
                                                    "vertical": 167
                                                },
                                                {
                                                    "horizontal": 195,
                                                    "vertical": 240
                                                },
                                                {
                                                    "horizontal": 255,
                                                    "vertical": 255
                                                }
                                            ]
                                        },
                                        "inputRange": 43
                                    },
                                    "bevelEmboss":
                                    {
                                        "enabled": true,
                                        "highlightMode": "screen",
                                        "highlightColor":
                                        {
                                            "red": 255,
                                            "green": 255,
                                            "blue": 255
                                        },
                                        "highlightOpacity": 100,
                                        "shadowMode": "multiply",
                                        "shadowColor":
                                        {
                                            "red": 0,
                                            "green": 0,
                                            "blue": 0
                                        },
                                        "shadowOpacity": 100,
                                        "bevelTechnique": "softMatte",
                                        "bevelStyle": "innerBevel",
                                        "useGlobalAngle": false,
                                        "localLightingAngle": 90,
                                        "localLightingAltitude": 75,
                                        "strengthRatio": 80,
                                        "blur": 16,
                                        "bevelDirection": "stampIn",
                                        "transparencyShape":
                                        {
                                            "name": "Linear",
                                            "curve":
                                            [
                                                {
                                                    "horizontal": 0,
                                                    "vertical": 0
                                                },
                                                {
                                                    "horizontal": 255,
                                                    "vertical": 255
                                                }
                                            ]
                                        },
                                        "antialiasGloss": false,
                                        "softness": 0,
                                        "useShape": true,
                                        "mappingShape":
                                        {
                                            "name": "Half Round",
                                            "curve":
                                            [
                                                {
                                                    "horizontal": 0,
                                                    "vertical": 0
                                                },
                                                {
                                                    "horizontal": 29,
                                                    "vertical": 71
                                                },
                                                {
                                                    "horizontal": 87,
                                                    "vertical": 167
                                                },
                                                {
                                                    "horizontal": 195,
                                                    "vertical": 240
                                                },
                                                {
                                                    "horizontal": 255,
                                                    "vertical": 255
                                                }
                                            ]
                                        },
                                        "antiAlias": true,
                                        "inputRange": 70,
                                        "useTexture": false
                                    },
                                    "solidFill":
                                    {
                                        "enabled": true,
                                        "mode": "normal",
                                        "opacity": 100,
                                        "color":
                                        {
                                            "red": 0,
                                            "green": 102,
                                            "blue": 255
                                        }
                                    }
                                }
                            };
                            jamStyles.setLayerStyle (layerStyleObj);
                            

                             

                            And this code will let you read out the drop shadow distance:

                             

                            var layerStyleObj = jamStyles.getLayerStyle ();
                            if (layerStyleObj)
                            {
                                if ("layerEffects" in layerStyleObj)
                                {
                                    var layerEffectsObj = layerStyleObj["layerEffects"];
                                    if ("dropShadow" in layerEffectsObj)
                                    {
                                        var dropShadowObj = layerEffectsObj["dropShadow"];
                                        alert ("Drop shadow distance: " + dropShadowObj["distance"]);
                                    }
                                }
                            }
                            

                             

                            Actually, if you know for sure that the current layer you're working on has layer effects, including a drop shadow effect, the code can be as short as:

                             

                            var layerStyleObj = jamStyles.getLayerStyle ();
                            alert ("Drop shadow distance: " + layerStyleObj["layerEffects"]["dropShadow"]["distance"]);
                            

                             

                            Or, even shorter, using dot notation:

                             

                            alert ("Drop shadow distance: " + jamStyles.getLayerStyle ().layerEffects.dropShadow.distance);
                            

                             

                            HTH,

                             

                                 --Mikaeru