Skip to main content
Mattmcquiff
Inspiring
November 24, 2016
Answered

PS Script, add layer mask to current layer

  • November 24, 2016
  • 2 replies
  • 1815 views

I'm trying to keep this as simple as possible, so far this is how my script works. At the end I want to add a black layer mask to the document?

Whats the simplist way to make this happen?

#target photoshop

var docRef = activeDocument

var newdLayer = docRef.activeLayer.duplicate();

newdLayer;

var doc = app.activeDocument;

doc.activeLayer = doc.artLayers.getByName("Main Image copy");

doc.activeLayer.applyMedianNoise(12);

doc.activeLayer.applyAddNoise(3, NoiseDistribution.UNIFORM, true)

doc.activeLayer.applyDespeckle()  

This topic has been closed for replies.
Correct answer JJMack

A simple way would be to use action manager code to add a hide all layer mask.  The code would not be readable but you could hit the code in a function to make you mainline code readable.

AddHideAllMask();

function AddHideAllMask(); {

  // =======================================================

var idMk = charIDToTypeID( "Mk  " );

    var desc7 = new ActionDescriptor();

    var idNw = charIDToTypeID( "Nw  " );

    var idChnl = charIDToTypeID( "Chnl" );

    desc7.putClass( idNw, idChnl );

    var idAt = charIDToTypeID( "At  " );

        var ref3 = new ActionReference();

        var idChnl = charIDToTypeID( "Chnl" );

        var idChnl = charIDToTypeID( "Chnl" );

        var idMsk = charIDToTypeID( "Msk " );

        ref3.putEnumerated( idChnl, idChnl, idMsk );

    desc7.putReference( idAt, ref3 );

    var idUsng = charIDToTypeID( "Usng" );

    var idUsrM = charIDToTypeID( "UsrM" );

    var idHdAl = charIDToTypeID( "HdAl" );

    desc7.putEnumerated( idUsng, idUsrM, idHdAl );

executeAction( idMk, desc7, DialogModes.NO );

}

2 replies

JJMack
Community Expert
Community Expert
November 24, 2016

Yes  I can not type I forgot to delet the ; when I did the copy paste.

JJMack
JJMack
Community Expert
JJMackCommunity ExpertCorrect answer
Community Expert
November 24, 2016

A simple way would be to use action manager code to add a hide all layer mask.  The code would not be readable but you could hit the code in a function to make you mainline code readable.

AddHideAllMask();

function AddHideAllMask(); {

  // =======================================================

var idMk = charIDToTypeID( "Mk  " );

    var desc7 = new ActionDescriptor();

    var idNw = charIDToTypeID( "Nw  " );

    var idChnl = charIDToTypeID( "Chnl" );

    desc7.putClass( idNw, idChnl );

    var idAt = charIDToTypeID( "At  " );

        var ref3 = new ActionReference();

        var idChnl = charIDToTypeID( "Chnl" );

        var idChnl = charIDToTypeID( "Chnl" );

        var idMsk = charIDToTypeID( "Msk " );

        ref3.putEnumerated( idChnl, idChnl, idMsk );

    desc7.putReference( idAt, ref3 );

    var idUsng = charIDToTypeID( "Usng" );

    var idUsrM = charIDToTypeID( "UsrM" );

    var idHdAl = charIDToTypeID( "HdAl" );

    desc7.putEnumerated( idUsng, idUsrM, idHdAl );

executeAction( idMk, desc7, DialogModes.NO );

}

JJMack
Mattmcquiff
Inspiring
November 24, 2016

Many Thanks for that, I had to drop the ; from this line function AddHideAllMask(); { for it to work.

I'm trying to re write some of my applescripts to photoshop scripts, so I am trying to learn by doing these simpler things, that said is it common in the scripts to look as they do above as its something I can even begin to understand?