Skip to main content
Inspiring
June 19, 2017
Answered

Proper way to return if a layer is a group or not.

  • June 19, 2017
  • 3 replies
  • 1867 views

I'm actually writing plugin using the C++ SDK and need to know what's the 'Ways' I am able to return if a layer is a group layer or not, It seems I have no access to this information...

I don't have a document element that I can call Document.Layer('myLayer'); I just have access to some suits. So if you could give me more than one way so I can see if I have this key / element to use it would be perfect, I just need high concept not full code. Thanks,

This topic has been closed for replies.
Correct answer SuperMerlin

A couple of ways using Dom/Action/Manager

//DOM

if(activeDocument.activeLayer.typename == "LayerSet") {

    alert("LayerSet");

    }else{

        alert("This is not a LayerSet");

        }

////////////////////////

//Action Manager function by Index/ID/Active Layer

function isLayerSet(idx){

var ref = new ActionReference();

ref.putIndex( charIDToTypeID( 'Lyr ' ), idx);//Index

//ref.putIdentifier(charIDToTypeID('Lyr '), ID); layer ID

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

var desc = executeActionGet(ref);

var isSet = typeIDToStringID(desc.getEnumerationValue(stringIDToTypeID('layerSection')));

var LayerSet=false;

switch (isSet.toString()){

    case 'layerSectionStart' : LayerSet=true; break;

    case 'layerSectionEnd' : LayerSet=true; break;

    case 'layerSectionContent' : LayerSet=false; break;

    }

return LayerSet;

};

3 replies

Jarda Bereza
Inspiring
June 19, 2017

I am looking into C++ SDK and there is something like:

OSErr PIGetTargetLayerLock(bool & transparency, bool & composite, bool & position);

OSErr PIGetTargetLayerIndex(int32 & index);

pluginsdk/samplecode/common/includes/propertyutils.h

Or maybe pluginsdk/samplecode/automation/getter/common/GetInfoFromPhotoshop.ccs > GetLayerInfo

looks very promisingly. This should give you something like my JSON example above... I guess.

i73Author
Inspiring
June 19, 2017

Hey Jarda, I think you're thinking I'm asking for the selected layer honest mistake, sorry if I confused you with my question.

How to return the selected layer: ~ Re: How can I get the currently selected Layer?

I'm actually looking to see if a layer is a group layer or not Title: "Proper way to return if a layer is a group or not.":

I've just re read what you've written...Sorry about that I was the one who was confused about the layer selection... WHY DO YOU HAVE TO BE SO CONFUSING SDK!

SuperMerlin
SuperMerlinCorrect answer
Inspiring
June 19, 2017

A couple of ways using Dom/Action/Manager

//DOM

if(activeDocument.activeLayer.typename == "LayerSet") {

    alert("LayerSet");

    }else{

        alert("This is not a LayerSet");

        }

////////////////////////

//Action Manager function by Index/ID/Active Layer

function isLayerSet(idx){

var ref = new ActionReference();

ref.putIndex( charIDToTypeID( 'Lyr ' ), idx);//Index

//ref.putIdentifier(charIDToTypeID('Lyr '), ID); layer ID

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

var desc = executeActionGet(ref);

var isSet = typeIDToStringID(desc.getEnumerationValue(stringIDToTypeID('layerSection')));

var LayerSet=false;

switch (isSet.toString()){

    case 'layerSectionStart' : LayerSet=true; break;

    case 'layerSectionEnd' : LayerSet=true; break;

    case 'layerSectionContent' : LayerSet=false; break;

    }

return LayerSet;

};

i73Author
Inspiring
June 19, 2017

Thank you SuperMerlin I've gotten it (Now that I know they call it layer SETS):

static SPErr EventIsLayerSet(int32 index, int32 &result)

  {

    SPErr error = kSPNoError;

    char layertype[1024] = "";

    char cdata1[1024] = "";

    char cdata2[1024] = "";

    DescriptorTypeID runtimeKeyID;

    uint32 data1;

    uint32 data2;

    error = sPSActionControl->StringIDToTypeID("layerSection", &runtimeKeyID);

    if (error) goto returnError;

    error = PIUGetInfoByIndex(index, classLayer, runtimeKeyID, &data1, &data2);

    if (error) goto returnError;

    error = sPSActionControl->TypeIDToStringID(data1, cdata1, 255);

    if (error) goto returnError;

    error = sPSActionControl->TypeIDToStringID(data2, cdata2, 255);

    if (error) goto returnError;

    if (strcmp(cdata1, "layerSectionStart") == 0) result = 2;

    else if (strcmp(cdata1, "layerSectionEnd") == 0)result = 1;

    else if (strcmp(cdata1, "layerSectionContent") == 0) result = 0;

    else result = -1;

  returnError:

    return error;

  }

Thanks for all the help guys!

Jarda Bereza
Inspiring
June 19, 2017

I think... if you do C++ plugin you also create scripting interface known as Action Manager code. This code is generated in script listener. And you can explore layers descriptors to see how object model looks like. So maybe you could read somehow this object model.

{

    "name": "Layer 1",

    "color": "none",

    "visible": true,

    "mode": "normal",

    "opacity": 255,

    "linkedLayerIDs": [

        7

    ],

    "layerID": 10,

    "itemIndex": 2,

    "count": 2,

    "preserveTransparency": false,

    "layerFXVisible": false,

    "globalAngle": 90,

    "background": false,

    "layerSection": "layerSectionContent", // <-- it's here

    "layerLocking": {

        "protectTransparency": false,

        "protectComposite": false,

        "protectPosition": false,

        "protectArtboardAutonest": false,

        "protectAll": false

    },

    "group": false,

    "targetChannels": [

        {

            "actionReference": 1,

            "reference": {

                "count": 5,

                "typename": "ActionDescriptor"

            }

        },

        {

            "actionReference": 2,

            "reference": {

                "count": 5,

                "typename": "ActionDescriptor"

            }

        },

        {

            "actionReference": 3,

            "reference": {

                "count": 5,

                "typename": "ActionDescriptor"

            }

        }

    ],

    "visibleChannels": [

        {

            "actionReference": 1,

            "reference": {

                "count": 5,

                "typename": "ActionDescriptor"

            }

        },

        {

            "actionReference": 2,

            "reference": {

                "count": 5,

                "typename": "ActionDescriptor"

            }

        },

        {

            "actionReference": 3,

            "reference": {

                "count": 5,

                "typename": "ActionDescriptor"

            }

        }

    ],

    "channelRestrictions": [

        "red",

        "grain",

        "blue"

    ],

    "fillOpacity": 255,

    "hasUserMask": false,

    "hasVectorMask": false,

    "proportionalScaling": false,

    "layerKind": 1,

    "hasFilterMask": false,

    "userMaskDensity": 255,

    "userMaskFeather": 0,

    "vectorMaskDensity": 255,

    "vectorMaskFeather": 0,

    "bounds": {

        "top": 0,

        "left": 0,

        "bottom": 0,

        "right": 0,

        "width": 0,

        "height": 0

    },

    "boundsNoEffects": {

        "top": 0,

        "left": 0,

        "bottom": 0,

        "right": 0,

        "width": 0,

        "height": 0

    },

    "boundsNoMask": {

        "top": 0,

        "left": 0,

        "bottom": 0,

        "right": 0,

        "width": 0,

        "height": 0

    },

    "useAlignedRendering": false,

    "generatorSettings": {

       

    },

    "keyOriginType": [

       

    ],

    "fillEnabled": false,

    "animationProtection": {

        "animationUnifyPosition": false,

        "animationUnifyEffects": false,

        "animationUnifyVisibility": false,

        "animationPropagate": true

    },

    "artboard": {

        "artboardRect": {

            "top": 0,

            "left": 0,

            "bottom": 0,

            "right": 0

        },

        "guideIDs": [

           

        ],

        "artboardPresetName": "",

        "color": {

            "red": 255,

            "grain": 255,

            "blue": 255

        },

        "artboardBackgroundType": 1

    },

    "artboardEnabled": false,

    "vectorMaskEnabled": false,

    "vectorMaskEmpty": true,

    "textWarningLevel": 0

}

i73Author
Inspiring
June 19, 2017

@Jarda Bereza ​Is "group": false.

Actually returning if it's a group? Mines not:

Group name:

Returning false:

And this is from the Class layer, thanks for your reply guys!

Jarda Bereza
Inspiring
June 19, 2017

group is not group... this means clipping mask

and layerName is just a name you can name layer as group and vica versa

You are Disassembling layer ActionDescriptor and thats what you need. You need to get LayerSection enum. You need to find key for this enum/object.

As SuperMerlin said:

  1. var isSet = typeIDToStringID(desc.getEnumerationValue(stringIDToTypeID('layerSection')));