Skip to main content
Known Participant
November 6, 2010
Question

How to get info from a layer which is applied with styles ?

  • November 6, 2010
  • 1 reply
  • 1902 views

How to get info from a  layer  ?  such  as   (  apply  style  or  not , which  effect  have  applied  on  it  etc..)

I  really  can't  solve  it , Who can hlep me..  By the way , I 'am  using  CS version.  

This topic has been closed for replies.

1 reply

Inspiring
November 6, 2010

xtools/xlib/Styles.js has a set of functions for working with layer styles. I do not know if it works with CS. I wrote it several years ago for either CS or CS2. If this doesn't work, then nothing will. The script retrieves a layer's style by saving it to disk then parsing the file for the desired ActionDescriptor.

There is a function at the bottom of the file that tests the Styles.js API.

Styles.test = function() {

  var doc = app.activeDocument;

  var layer0 = doc.artLayers[0];

  var gdesc = Styles.getLayerStyleDescriptor(doc, layer0);

  if (!gdesc) {
    alert("There is no layer style associated with the layer");
    return;
  }

//   this will set the layer style to another layer.
//   var layer1 = doc.artLayers[1];
//   Styles.setLayerStyleDescriptor(doc, layer1, gdesc);

  if (!gdesc.hasKey(cTID('FrFX'))) {  // look for a stroke effect
    return;
  }
  var frfx = gdesc.getObjectValue(cTID('FrFX'));
  if (!frfx.hasKey(cTID('Clr '))) {   // look for the color
    return;
  }
  var clr = frfx.getObjectValue(cTID('Clr '));
  // we should really check that the objectType is RGBC
  var r = clr.getDouble(cTID('Rd  '));
  var g = clr.getDouble(cTID('Grn '));
  var b = clr.getDouble(cTID('Bl  '));
  if (r == 0 && g == 0xFF && b == 0xFF) {
    return;
  }
  clr.putDouble(cTID('Rd  '), 0);
  clr.putDouble(cTID('Grn '), 0xFF);
  clr.putDouble(cTID('Bl  '), 0xFF);

  frfx.putObject(cTID('Clr '), cTID('RGBC'), clr);
  gdesc.putObject(cTID('FrFX'), cTID('FrFX'), frfx);

  Styles.setLayerStyleDescriptor(doc, layer0, gdesc);
};

leezjnuAuthor
Known Participant
November 10, 2010

I  found  two years ago  you helped  a  person   solve  this   problem  sucessfully.  Below is  the  link  where  I  found

http://www.ps-scripts.com/bb/viewtopic.php?p=9968&sid=01bacc68a936a6f5087b9833d96d045b

the person  nickname  is  pzwhz,  I  saw  his  Appliction   can  deal  with  layer  style  perfect.   Have  you  any thought?    Thank you,  Xbytor

leezjnuAuthor
Known Participant
November 12, 2010
On the other hand now that I think about it I'm not sure when app pointed to the host app. With older versions maybe it should be just charIDToTypeID.

This is probably the case.

The easiest way to fix this is to add

app.charIDToTypeID = charIDToTypeID;

app.stringIDToTypeID = stringIDToTypeID;

If that doesn't work, you would have to do the equvialent search-and-replace in the necessary files.


Thanks  Xbytor,Mike

            I  used  Photoshop CS, ESTK 2.0 ,And  I  can't  see  the  dropdown  top_left  in ESTK  have the item  'Adobe Photoshop CS', so I  tried  another  ESTK 1.0 ,  and  use Photoshop CS2,  Now,  the the top left  dropdown of ESTK   appear  an  option   Adobe Photoshop cs2.

           but  I  run  the  code  you  give me  another  error  occured :    PSClass is undefined     

           I'am swirled by this thing.  Could  you help  me  with  this ?