Layer mask functions

Use this Forum for Beta-Testing your Photoshop Scripts

Moderators: Tom, Kukurykus

Mike Hale

Layer mask functions

Post by Mike Hale »

Here is a set of layer mask functions. They allow you to do anything with a layer mask that you could do using the GUI.

I would especially like Xbytor's option, because 'I want to be like X'
xbytor

Layer mask functions

Post by xbytor »

I'll take a close look at it in a couple of days.

One thing I noticed off the bat was that
Code: Select alllayerMask.makeFromSelection = function() {

should probably have been
Code: Select alllayerMask.makeFromSelection = function(bool) {

And I'll write me a script to convert all of those typeIds back into something readable by humans .
Mike Hale

Layer mask functions

Post by Mike Hale »

Thanks X,

I added the reveal/hide part after I had written the function and forgot to add that. I did that to match the layer menu's options. As it is it works like clicking on the make mask icon in the layer's palette.

I changed all the cTID() to numbers so that it would work alone or with your stdlib. Is there a better way to have it work either way?

Mike
xbytor

Layer mask functions

Post by xbytor »

One alternative to using cTID and sTID is to define symbols for the Ids like I do with PSConstants or with SLCFlix. Something like

Code: Select allLayerMaskID = function() {};

LayerMaskID.SELECT  = charIDToTypeID('sel ');
LayerMaskID.DELETE_MASK  = charIDToTypeID('dmsk');
// etc....

Then, in your functions, you would substitute in those symbols:

Code: Select allexecuteAction( LayerMaskID.DELETE_MASK, desc, DialogModes.NO );

(There are a lot of different ways of approaching the problem. This was just one off the top of my head. I ultimately prefer the 'PSEvent.Select' style for IDs.)

This goes a long way towards make your code understandable, maintainable, and reusable. It's overkill for small one-off scripts, but if you are growing a library of reusable scripts, this is something important to consider.

The PSConstants code was one of the first things I wrote just for this specific reason.

I'll post more later.

BTW, I'm still working on a way of change the blocks that look like this

Code: Select all} catch (e) {
    if (e.toString().match(/Select.+is not currently available/)) {//change if not english PS
      return false;
    } else {
      throw e;
    }
 }

to blocks that look like this
Code: Select all} catch (e) {
    if (e.number == PSError.SelectionNotAvailable) {
      return false;
    } else {
      throw e;
    }
}

to get around the localization issues. I know it's a "good thing" I just don't know how easy it's going to be to get all of the error numbers generated.
Mike Hale

Layer mask functions

Post by Mike Hale »

I hadn't thought that being able to understand what scriptlistner is doing would be that helpful as it really can't be changed. Or can it?

But I can see where using symbols would better than using numbers.

Ouch, that means I have to convert all those number back to cTID before I can set the symbols.

That's a great tip about e.number. I don't have that many different errors to test for in the lib so I can use the debugger to change them. Should I comment what the error sting is so someone reading the script would know what the error was?

And thanks for all you tips, both here and in your scripts

Mike
xbytor

Layer mask functions

Post by xbytor »

Code: Select allI hadn't thought that being able to understand what scriptlistner is doing would be that helpful as it really can't be changed. Or can it?

Sure, you can edit SL code. It's ultimately just Action Manager code which, while painful to write, is frequently the only way to get somethings done. That's why I wrote stuff like the SLCFixer code to make SL code readable, etc...

Ouch, that means I have to convert all those number back to cTID before I can set the symbols.

Application.typeIDToCharID and Application.typeIDToStringID will map the long integers back to stuff like "UsrM" or "fileBrowser".

Code: Select allShould I comment what the error sting is so someone reading the script would know what the error was?

As long as your symbolic name is meaningful, providing the string is nice-to-have but not essential.
Mike Hale

Layer mask functions

Post by Mike Hale »

When I have the debugger break after an error, e.number always returns '8800' while 'e.toString()' gives different strings. So for now I will leave the error catching as is.

Of coruse I couldn't find anything useful searching the Adode site for error codes.

Hopefully if others do use this they will be able to change the strings
Mike Hale

Layer mask functions

Post by Mike Hale »

Searching the web for examples of executeActionGet really drove home the point of not using ID numbers. Almost every example I could find used ID numbers, so where worthless as far as showing how to construct a function.

Maybe it's because they are my symbols, but they really helps in understanding what the action manager is doing.

I also set it up so that if there was an error, you could read lMID.eror to get the error then deal with the reason in the functions that could fail for more than one reason.

I think that the only things missing are a way to check the state of the mask link and if the mask is being applyed to the layer. So far I can't find a way to do those.

Thanks again X,

Mike
Mike Hale

Layer mask functions

Post by Mike Hale »

Mike Hale wrote:I think that the only things missing are a way to check the state of the mask link and if the mask is being applyed to the layer.

Thanks to Xbytor's tutorial on using getter, those two are now part of the lib.
Andrew

Layer mask functions

Post by Andrew »

Can you test if a layer has a layer mask.

Can you count how many layers have layer masks and identify the layer names (or index's) that have masks.

Can you delete all layer masks or the layer mask of an individual layer.

I have been having a look at the channels/ channel Objects and it seems layer masks are not part of the collection.

Andrew