Get the VALUE of AnchorPosition.BOTTOMLEFT??

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

Holograph

Get the VALUE of AnchorPosition.BOTTOMLEFT??

Post by Holograph »

I want to get the bottom-left corner of a layer MINUS the expansion of the layer's bounds caused by layer effects like outer glow, etc...the quickest (and yet, most illusive) way that I can see to do this dynamically on a per layer basis is to find the bottom-left corner of the region to which the effects are being applied...the AnchorPosition.BOTTOMLEFT coordinate is EXACTLY what I need, but AnchorPosition is only used as a passed-in argument for methods such as resize(offset, anchor) scale(, etc etc...

Does anyone know how to retrieve the actual coordinate VALUE of the AnchorPosition.BOTTOMLEFT? After all, according to the documentation, it sends an x,y point to the transform fuctions...I just want a way to grab that point to use the location info. Any help would be greatly appreciated. Thanks in advance.

-Brian-
Holograph

Get the VALUE of AnchorPosition.BOTTOMLEFT??

Post by Holograph »

I forgot to mention that this is just like the bounds[] array, but with only two elements [x,y]...however, my question is how can you pull the VALUES of those points out from a AnchorPosition.BOTTOMLEFT? Thanks...

-Brian-
Mike Hale

Get the VALUE of AnchorPosition.BOTTOMLEFT??

Post by Mike Hale »

Use scriptlistner to make a hide/show layer effect function. Then turn off the layer FX and use layer bounds to find the corners, then turn the effect back on
Holograph

Get the VALUE of AnchorPosition.BOTTOMLEFT??

Post by Holograph »

That sure sounds like it may lead to a solution, but I have not yet heard of scriptlistener...any details/examples would be appreciated, and in the meantime, I'll do some of my own research. Thanks!

-Brian-
Mike Hale

Get the VALUE of AnchorPosition.BOTTOMLEFT??

Post by Mike Hale »

Here is one I use. It really should have a try/catch block incase it is used on a layer that doesn't have an effect but I haven't gotten around to doing that

Code: Select allfunction showLayerFX( layername, bool ) {
   if(bool){
      var state = 'Shw ';
   }else{
      var state = 'Hd  ';
   };
   function cTID(s) { return app.charIDToTypeID(s); };
   
    var desc19 = new ActionDescriptor();
        var list2 = new ActionList();
            var ref9 = new ActionReference();
            ref9.putClass( cTID('FrFX') );
            ref9.putName( cTID('Lyr '), layername );
        list2.putReference( ref9 );
            var ref10 = new ActionReference();
            ref10.putClass( cTID('Lefx') );
            ref10.putName( cTID('Lyr '), layername );
        list2.putReference( ref10 );
    desc19.putList( cTID('null'), list2 );
    executeAction( cTID( state ), desc19, DialogModes.NO );
};
//demo usage
showLayerFX('Layer 2', true);// show effect
showLayerFX('Layer 1', false);// hide effect
Holograph

Get the VALUE of AnchorPosition.BOTTOMLEFT??

Post by Holograph »

Thanks Mike!

Is there an equivalent to something like "hasLayerEffects" as a property to test to see if a Layer indeed has any active effects, or is it just as good to use a try catch as you mentioned?

Also, does this turn off only one layer effect at a time (ex. just the Drop Shadow) or does it turn off all active layer effects at once?

Thanks.

-Brian-
Mike Hale

Get the VALUE of AnchorPosition.BOTTOMLEFT??

Post by Mike Hale »

Layer effects or styles are not easy to deal with in Photoshop. You might want to look at Xbytor's style script for dealing with layer styles.

But I am assuming that in your case you just don't want the script to crash if the layer doesn't have an effect. A try/catch block would be the easiest way to deal with the layer not having an effect. Here is the same function with a try/catch block. If you are using a non-english version of Photoshop you will need to change the error sting to match yours

Code: Select allfunction showLayerFX( layername, bool ) {
   if(bool){
      var state = 'Shw ';
   }else{
      var state = 'Hd  ';
   };
   function cTID(s) { return app.charIDToTypeID(s); };
 try {   
    var desc19 = new ActionDescriptor();
        var list2 = new ActionList();
            var ref9 = new ActionReference();
            ref9.putClass( cTID('FrFX') );
            ref9.putName( cTID('Lyr '), layername );
        list2.putReference( ref9 );
            var ref10 = new ActionReference();
            ref10.putClass( cTID('Lefx') );
            ref10.putName( cTID('Lyr '), layername );
        list2.putReference( ref10 );
    desc19.putList( cTID('null'), list2 );
    executeAction( cTID( state ), desc19, DialogModes.NO );

  } catch (e) {
    if (!e.toString().match(/is not currently available/)) {//string will change with error
      throw e;
    };
};
};
showLayerFX('Layer 2', true)


It turns off/on all the effects and the layer doesn't need to be active, which is why the layer name is in the arguments
Holograph

Get the VALUE of AnchorPosition.BOTTOMLEFT??

Post by Holograph »

Thanks again, Mike.

By the way, I asked about the individual on/off or all-off functionality for effects because in this case, I would like all effects to be rendered as off/invisible at once so I dont have to loop through it. I haven't had a chance to try this code yet, but I hope that's what it will do. Thanks again for your help so far. I'll keep you posted on how things go.

-Brian-
Holograph

Get the VALUE of AnchorPosition.BOTTOMLEFT??

Post by Holograph »

Hey Mike,

I have modified your function a bit...basically, the show/hide layer effects was not working because when it would show the layer effects, it would show all of them, even ones that were not used before, resulting in strokes and satin and everything on top of my actual chosen effects set.

I need to have the layer effects hide entriely to get the true bounds of the object, then show the layer effects just as I had them before the hide to grab the extended bounds with my chosen layer effects setup...here's what I came up with, but the Paste Layer Effects is "not availabile"...and then it says "value needed"...also, I had to add the alert(e) command because the catch block was staying silent and not reporting any errors to me.

If you can tell from this code, please let me know where my copy/paste layer effects solution went wrong.

Or, you could simply help me modifiy your original code such that it shows only the effects that were previously appied and not every category of effect all at once, whether it was used before or not. Thanks Mike!

--modified for copy/paste layer effects
Code: Select allfunction showLayerFX(layername, bool, curLayer) {
   /*
   if(bool){
      var state = 'Shw ';
   }else{
      var state = 'Hd  ';
   };
   */
   
   //set activeLayer to ensure that Copy/Paste works.
   dupDocRef.activeLayer = curLayer;
   //alert("should have layer");

   function cTID(s) { return app.charIDToTypeID(s); };
   try {   
      var desc19 = new ActionDescriptor();
      var list2 = new ActionList();
      var ref9 = new ActionReference();
      ref9.putClass( cTID('FrFX') );
      ref9.putName( cTID('Lyr '), layername );
      list2.putReference( ref9 );
      var ref10 = new ActionReference();
      ref10.putClass( cTID('Lefx') );
      ref10.putName( cTID('Lyr '), layername );
      list2.putReference( ref10 );
      desc19.putList( cTID('null'), list2 );
      //executeAction( cTID( state ), desc19, DialogModes.NO );
      if(bool) {
         executeAction( cTID('CpFX'), desc19, DialogModes.NO );
         executeAction( cTID('Hd  '), desc19, DialogModes.NO );
         alert("Effects Disabled...");
      } else {
         executeAction( cTID('PaFX'), desc19, DialogModes.NO );
         alert("Effects Pasted");
      }
   } catch (e) {
      alert(e);
      if (!e.toString().match(/is not currently available/)) {//string will change with error
         throw e;
      };
   };
};
Mike Hale

Get the VALUE of AnchorPosition.BOTTOMLEFT??

Post by Mike Hale »

I haven't run into that before with the way I set up my docs, but you are right it doesn't do a good job of keeping track of which effects were visible.

My function really should have the catch block changed. I was lazy when I added that and it matches most errors, which is why it doesn't catch the one you have with your changes. It should test for the two possible errors that I want it to handle. Here is the corrected line.

Code: Select allif (!e.toString().match(/Show.+is not currently available/) && !e.toString().match(/Hide.+is not currently available/)) {

As to the changes you made, I don't think that approach will work as what it is working with the current layer effects so even if we get it to work without throwing an error it will still have the same problem as mine does.

You could either use Xbytor's style script to better deal with the style or you could dupe the layer, turn off the style, get the bounds, then delete the layer. That way you will have the true bounds and your layer will remain unchaged