Skip to main content
Inspiring
April 6, 2020
Answered

Layer Set Mask Feather Value

  • April 6, 2020
  • 2 replies
  • 2246 views

Is a layer set mask feather value scriptable? 

If so visit possible to see a sample code?

 

PSCC 2020

OSX Catalina

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

In it's simplest form:

 

 

 

app.activeDocument.activeLayer.layerMaskFeather = 25;

 

 

 

However, in practice, you would probably wish to set up a test to see if the active layer actually had a layer mask applied beforehand:

 

if (hasLayerMask() == true) { // Only if it has a layer mask
    app.activeDocument.activeLayer.layerMaskFeather = 25;
}

//github.com/ES-Collection/Photoshop-Scripts/blob/master/Link%20All%20Masks.jsx

///////////////////////////////////////////////////////////////////////////////
// Function: hasLayerMask
// Usage: see if there is a raster layer mask
// Input: <none> Must have an open document
// Return: true if there is a vector mask
///////////////////////////////////////////////////////////////////////////////
function hasLayerMask() {
    var hasLayerMask = false;
    try {
        var ref = new ActionReference();
        var keyUserMaskEnabled = app.charIDToTypeID('UsrM');
        ref.putProperty(app.charIDToTypeID('Prpr'), keyUserMaskEnabled);
        ref.putEnumerated(app.charIDToTypeID('Lyr '), app.charIDToTypeID('Ordn'), app.charIDToTypeID('Trgt'));
        var desc = executeActionGet(ref);
        if (desc.hasKey(keyUserMaskEnabled)) {
            hasLayerMask = true;
        }
    } catch (e) {
        hasLayerMask = false;
    }
    return hasLayerMask;
}

2 replies

Legend
April 7, 2020

Inspiring
April 7, 2020

I looked at the specification for layerMaskFetehr before but was not able to make it work. How exactly would you use this property? 

Stephen Marsh
Community Expert
Stephen MarshCommunity ExpertCorrect answer
Community Expert
April 7, 2020

In it's simplest form:

 

 

 

app.activeDocument.activeLayer.layerMaskFeather = 25;

 

 

 

However, in practice, you would probably wish to set up a test to see if the active layer actually had a layer mask applied beforehand:

 

if (hasLayerMask() == true) { // Only if it has a layer mask
    app.activeDocument.activeLayer.layerMaskFeather = 25;
}

//github.com/ES-Collection/Photoshop-Scripts/blob/master/Link%20All%20Masks.jsx

///////////////////////////////////////////////////////////////////////////////
// Function: hasLayerMask
// Usage: see if there is a raster layer mask
// Input: <none> Must have an open document
// Return: true if there is a vector mask
///////////////////////////////////////////////////////////////////////////////
function hasLayerMask() {
    var hasLayerMask = false;
    try {
        var ref = new ActionReference();
        var keyUserMaskEnabled = app.charIDToTypeID('UsrM');
        ref.putProperty(app.charIDToTypeID('Prpr'), keyUserMaskEnabled);
        ref.putEnumerated(app.charIDToTypeID('Lyr '), app.charIDToTypeID('Ordn'), app.charIDToTypeID('Trgt'));
        var desc = executeActionGet(ref);
        if (desc.hasKey(keyUserMaskEnabled)) {
            hasLayerMask = true;
        }
    } catch (e) {
        hasLayerMask = false;
    }
    return hasLayerMask;
}
c.pfaffenbichler
Community Expert
Community Expert
April 6, 2020

Have you tried recording the operation with ScriptingListener.plugin? 

Inspiring
April 6, 2020

I thought about it but have not been able to make the script listener plugin work with PSCC 2020 and OSX Catalina.