Skip to main content
Known Participant
March 3, 2017
Answered

enable disable mask

  • March 3, 2017
  • 2 replies
  • 1598 views

Good evening

I am creating ui dialog

which provides a pulsed to activate and deactivate the layer mask

this button must do this function

When I click the first time disables mask

When I click the button the second time qualifies him

This topic has been closed for replies.
Correct answer SuperMerlin

#target photoshop;

app.bringToFront();

if(documents.length){

var w = new Window("dialog","Usermask");

w.bu1 = w.add("button",undefined,"Toggle usermask");

w.bu2 = w.add("button",undefined,"Close");

w.bu1.onClick=function(){

    if(!userMask()){

        alert("This layer does not have an usermask!");

        w.close(0);

        }

    if(userMask())disEnableMask(userMaskEnabled());

    app.refresh();

    }

w.bu2.onClick=function(){

    w.close(0);

    }

w.show();

}

function userMask(){

var ref = new ActionReference();

ref.putProperty(charIDToTypeID('Prpr'),stringIDToTypeID("hasUserMask"));

ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

return executeActionGet(ref).getBoolean (stringIDToTypeID("hasUserMask"));

};

function userMaskEnabled(){

var ref = new ActionReference();

ref.putProperty(charIDToTypeID('Prpr'),stringIDToTypeID("userMaskEnabled"));

ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

return executeActionGet(ref).getBoolean (stringIDToTypeID("userMaskEnabled"));

};

function disEnableMask(Bool) {

var desc3 = new ActionDescriptor();

var ref2 = new ActionReference();

ref2.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );

desc3.putReference( charIDToTypeID('null'), ref2 );

var desc4 = new ActionDescriptor();

desc4.putBoolean( charIDToTypeID('UsrM'), !Bool );

desc3.putObject( charIDToTypeID('T   '), charIDToTypeID('Lyr '), desc4 );

executeAction( charIDToTypeID('setd'), desc3, DialogModes.NO );

};

2 replies

SuperMerlin
SuperMerlinCorrect answer
Inspiring
March 4, 2017

#target photoshop;

app.bringToFront();

if(documents.length){

var w = new Window("dialog","Usermask");

w.bu1 = w.add("button",undefined,"Toggle usermask");

w.bu2 = w.add("button",undefined,"Close");

w.bu1.onClick=function(){

    if(!userMask()){

        alert("This layer does not have an usermask!");

        w.close(0);

        }

    if(userMask())disEnableMask(userMaskEnabled());

    app.refresh();

    }

w.bu2.onClick=function(){

    w.close(0);

    }

w.show();

}

function userMask(){

var ref = new ActionReference();

ref.putProperty(charIDToTypeID('Prpr'),stringIDToTypeID("hasUserMask"));

ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

return executeActionGet(ref).getBoolean (stringIDToTypeID("hasUserMask"));

};

function userMaskEnabled(){

var ref = new ActionReference();

ref.putProperty(charIDToTypeID('Prpr'),stringIDToTypeID("userMaskEnabled"));

ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

return executeActionGet(ref).getBoolean (stringIDToTypeID("userMaskEnabled"));

};

function disEnableMask(Bool) {

var desc3 = new ActionDescriptor();

var ref2 = new ActionReference();

ref2.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );

desc3.putReference( charIDToTypeID('null'), ref2 );

var desc4 = new ActionDescriptor();

desc4.putBoolean( charIDToTypeID('UsrM'), !Bool );

desc3.putObject( charIDToTypeID('T   '), charIDToTypeID('Lyr '), desc4 );

executeAction( charIDToTypeID('setd'), desc3, DialogModes.NO );

};

tssee
Inspiring
March 4, 2017

You are a great

thank you

tssee
Inspiring
March 4, 2017

Also I would be interested in this

someone could take a look