• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

View Layer Mask status via scripting

Contributor ,
Oct 19, 2022 Oct 19, 2022

Copy link to clipboard

Copied

Greetings all,

 

Does anyone know if I can check if the view layer mask (the greyscale thumbnail next to the layer) is on or off via scripting?

 

Thanks in advance!

TOPICS
Actions and scripting

Views

329

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guide , Oct 19, 2022 Oct 19, 2022

try this:

#target photoshop
s2t = stringIDToTypeID;
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('hasUserMask'));
r.putEnumerated(s2t("layer"), s2t("ordinal"), s2t("targetEnum"));
if (executeActionGet(r).getBoolean(p)) {
    (r = new ActionReference()).putProperty(s2t('property'), p = s2t('name'));
    (r = new ActionReference()).putEnumerated(s2t("layer"), s2t("ordinal"), s2t("targetEnum"));
    layerName = executeActionGet(r).getString(p);
    (r = new ActionReference()).pu
...

Votes

Translate

Translate
Adobe
Guide ,
Oct 19, 2022 Oct 19, 2022

Copy link to clipboard

Copied

#target photoshop
s2t = stringIDToTypeID;
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('userMaskEnabled'));
r.putEnumerated(s2t("layer"), s2t("ordinal"), s2t("targetEnum"));
if (executeActionGet(r).hasKey(p)) alert (executeActionGet(r).getBoolean(p));

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Oct 19, 2022 Oct 19, 2022

Copy link to clipboard

Copied

Thanks jazz-y for your quick reply.

I'll try to clarify a bit more about what I need below.

 

htweevqr50401.jpg

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Oct 19, 2022 Oct 19, 2022

Copy link to clipboard

Copied

alert(layerMaskHasContent())
function layerMaskHasContent() {
    #target photoshop
    s2t = stringIDToTypeID;
    (r = new ActionReference()).putProperty(s2t('property'), p = s2t('hasUserMask'));
    r.putEnumerated(s2t("layer"), s2t("ordinal"), s2t("targetEnum"));
    if (executeActionGet(r).getBoolean(p)) {
        (r = new ActionReference()).putEnumerated(s2t("channel"), s2t("channel"), s2t('mask'));
        (d = new ActionDescriptor).putReference(s2t("null"), r);
        executeAction(s2t("select"), d, DialogModes.NO);
        (r = new ActionReference()).putProperty(s2t('property'), p = s2t('histogram'));
        r.putEnumerated(s2t("channel"), s2t("ordinal"), s2t("targetEnum"));
        var hst = executeActionGet(r).getList(p);
        (r = new ActionReference()).putEnumerated(s2t("channel"), s2t("channel"), s2t('RGB'));
        (d = new ActionDescriptor).putReference(s2t("null"), r);
        executeAction(s2t("select"), d, DialogModes.NO);
        for (var i = 0; i < hst.count - 1; i++) { if (hst.getInteger(i)) return true }
        return false
    }
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Oct 19, 2022 Oct 19, 2022

Copy link to clipboard

Copied

Thanks so much, both work as intended.

Sorry I made an error in my image, but I could not change it after posting...

I just mean check if view mask (activated by option click on Mac) is visible (the white/greyscale mask) = true

 

Normal left view (ie layer mask is not visible) = false

 

Thanks againhtweevqr50401.jpg

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Oct 19, 2022 Oct 19, 2022

Copy link to clipboard

Copied

try this:

#target photoshop
s2t = stringIDToTypeID;
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('hasUserMask'));
r.putEnumerated(s2t("layer"), s2t("ordinal"), s2t("targetEnum"));
if (executeActionGet(r).getBoolean(p)) {
    (r = new ActionReference()).putProperty(s2t('property'), p = s2t('name'));
    (r = new ActionReference()).putEnumerated(s2t("layer"), s2t("ordinal"), s2t("targetEnum"));
    layerName = executeActionGet(r).getString(p);
    (r = new ActionReference()).putProperty(s2t('property'), p = s2t('channelName'));
    r.putEnumerated(s2t("channel"), s2t("ordinal"), s2t("targetEnum"));
    channelName = executeActionGet(r).getString(p);
    (r = new ActionReference()).putProperty(s2t('property'), p = s2t('alphaChannelOptions'));
    r.putEnumerated(s2t("channel"), s2t("ordinal"), s2t("targetEnum"));
    alphaChannel = executeActionGet(r).hasKey(p);
    (r = new ActionReference()).putProperty(s2t('property'), p = s2t('visible'));
    r.putEnumerated(s2t("channel"), s2t("ordinal"), s2t("targetEnum"));
    channelVisible = executeActionGet(r).getBoolean(p);
    alert (channelName.indexOf(layerName) == 0 && !alphaChannel && channelVisible)
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Oct 19, 2022 Oct 19, 2022

Copy link to clipboard

Copied

LATEST

Fantastic!

 

Thank you very much jazz-y : )

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines