Skip to main content
Participant
Feb 26, 2016 12:43 AM UTC
Question

Photoshop VB Scripting to apply Layer Mask Reveal Selection to Layer

I'm probably searching on the wrong terminology but I've been looking all day.

I have created a script, it opens a file, I can resize the image, I can have the user select region with magic wand and lasso tools, I can invert the selection, I can create a new layer duplicating the background, and I can save/or/export is all sorts of formats and options.  All is good.

Now all I want to do is take the selection (the one I just inverted using oPSDoc.Selection.Invert [where oPSDoc is my OLE Object pointing to my oPSApp.ActiveDocument]) and apply it to my new layer as a mask.  The toolbar equivalent to Layer->Layer Mask->Reveal Selection.

Now, I know I can "cheat" and use the "Script Listener" to snoop on the commands and just paste that into my code.  But SERIOUSLY!  Now I've got a bunch of charIDToTypeID and executeAction which is meaningless to a human or anyone who has to look at my code months from now.

This should be as simple as one line of code (not 14-20 lines of script listener gibberish):

oPSDoc.Selection.LayerMask(oPSMaskLayer, oMaskProperties)

or maybe:

oPSMaskLayer.LayerMask(oPSDoc.Selection, oMaskProperties)

where:

oPSApp = OLE Object ("Photoshop.Application")

oPSDoc = oPSApp.ActiveDocument

oPSMaskLayer = oPSDoc.ActiveLayer.Duplicate

oMaskProperties = some mask object to contain properties and methods for setting things like "Reveal Selection", "Hide Selection", etc...

Thank-you to the first wizard to enlighten me!

    This topic is closed to new replies. Start a new post to keep the conversation going.

    1 reply

    Chuck Uebele
    Community Expert
    Community Expert
    Mar 1, 2016 9:56 PM UTC

    While action manager code is long and hard to read, it generally runs faster and can do many things the DOM just can't do - even though it seems like it should. Not sure how to help you in figuring this out other than that, as I just work with js.

    Translate