Skip to main content
Inspiring
March 15, 2024
Answered

Is it possible to make a layer mask with the current selection using extendscript?

  • March 15, 2024
  • 1 reply
  • 317 views

I've had no luck and was wondering is someone knows how. Thanks.

This topic has been closed for replies.
Correct answer Stephen Marsh

Yes, but not with DOM code, you need AM code. I'll post the code shortly...

 

To add a reveal or hide mask from an active selection:

 

maskSelection("revealSelection");

function maskSelection(maskParameter) {
  // Parameter = "revealSelection" or "hideSelection"
	var s2t = function (s) {
		return app.stringIDToTypeID(s);
	};
	var descriptor = new ActionDescriptor();
	var reference = new ActionReference();
	descriptor.putClass( s2t( "new" ), s2t( "channel" ));
	reference.putEnumerated( s2t( "channel" ), s2t( "channel" ), s2t( "mask" ));
	descriptor.putReference( s2t( "at" ), reference );
	descriptor.putEnumerated( s2t( "using" ), s2t( "userMaskEnabled" ), s2t( maskParameter ));
	executeAction( s2t( "make" ), descriptor, DialogModes.NO );
}

 

https://gist.github.com/MarshySwamp/cbd0f135aa6ad089b053c80a2a02edaa

 

 

To add a "full" layer mask with no selection:

 

addMask("reveallAll");

function addMask(maskVisibility) {
    // maskVisibility = "revealAll" or "hideAll"
    var c2t = function (s) {
        return app.charIDToTypeID(s);
    };
    var s2t = function (s) {
        return app.stringIDToTypeID(s);
    };
    var descriptor = new ActionDescriptor();
    var reference = new ActionReference();
    descriptor.putClass(s2t("new"), s2t("channel"));
    reference.putEnumerated(s2t("channel"), s2t("channel"), s2t("mask"));
    descriptor.putReference(s2t("at"), reference);
    descriptor.putEnumerated(s2t("using"), c2t("UsrM"), s2t(maskVisibility));
    executeAction(s2t("make"), descriptor, DialogModes.NO);
}

 

https://gist.github.com/MarshySwamp/5eb4863d08335e870a53ef04ccb33916

 

1 reply

Stephen Marsh
Community Expert
Stephen MarshCommunity ExpertCorrect answer
Community Expert
March 15, 2024

Yes, but not with DOM code, you need AM code. I'll post the code shortly...

 

To add a reveal or hide mask from an active selection:

 

maskSelection("revealSelection");

function maskSelection(maskParameter) {
  // Parameter = "revealSelection" or "hideSelection"
	var s2t = function (s) {
		return app.stringIDToTypeID(s);
	};
	var descriptor = new ActionDescriptor();
	var reference = new ActionReference();
	descriptor.putClass( s2t( "new" ), s2t( "channel" ));
	reference.putEnumerated( s2t( "channel" ), s2t( "channel" ), s2t( "mask" ));
	descriptor.putReference( s2t( "at" ), reference );
	descriptor.putEnumerated( s2t( "using" ), s2t( "userMaskEnabled" ), s2t( maskParameter ));
	executeAction( s2t( "make" ), descriptor, DialogModes.NO );
}

 

https://gist.github.com/MarshySwamp/cbd0f135aa6ad089b053c80a2a02edaa

 

 

To add a "full" layer mask with no selection:

 

addMask("reveallAll");

function addMask(maskVisibility) {
    // maskVisibility = "revealAll" or "hideAll"
    var c2t = function (s) {
        return app.charIDToTypeID(s);
    };
    var s2t = function (s) {
        return app.stringIDToTypeID(s);
    };
    var descriptor = new ActionDescriptor();
    var reference = new ActionReference();
    descriptor.putClass(s2t("new"), s2t("channel"));
    reference.putEnumerated(s2t("channel"), s2t("channel"), s2t("mask"));
    descriptor.putReference(s2t("at"), reference);
    descriptor.putEnumerated(s2t("using"), c2t("UsrM"), s2t(maskVisibility));
    executeAction(s2t("make"), descriptor, DialogModes.NO);
}

 

https://gist.github.com/MarshySwamp/5eb4863d08335e870a53ef04ccb33916

 

Inspiring
March 15, 2024

Awesome, thank you so much that works perfectly!