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

Getting layer's parent using ActionManager

New Here ,
Aug 25, 2011 Aug 25, 2011

Copy link to clipboard

Copied

Is there a way, to get layer's parent using ActionManager? There is an simple way by layer.parent, but this seems to be rather slow, I would appreciate fast access, but could not get an idea how to do it.

TOPICS
Actions and scripting

Views

2.1K

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

Guru , Aug 25, 2011 Aug 25, 2011

The layer descriptor does not have a 'parent' key. It does have a key with the stringID of "layerSection".

To Action Manger a layerSet is really two layers. One has the value of 'layerSectionStart' in the "layerSection" key. That is the layer that you can see in the Photoshop GUI. It marks the top of a layerSet. The bottom of the layerSet is a hidden layer with the value of "layerSectionEnd" in the "layerSection" key. You can not make that hidden layer active and some of the key have different va

...

Votes

Translate

Translate
Adobe
Community Expert ,
Aug 25, 2011 Aug 25, 2011

Copy link to clipboard

Copied

What do you mean by a layer's parent the layer above it, the layer group it may be in, the layers it effects or the layer it is clipped to.  Are layers in a hierarchy? Or someplace within a stack?  You can use the action manger code to go layer forward and backward that will sikp layers with their visibility off and wrap when you reach the top or bottom. I find that usefull.  You can get all layers into an aray with DOM code and run through all layers.

As fas as I know the document is the parent of things in it like layers etc

JJMack

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
New Here ,
Aug 25, 2011 Aug 25, 2011

Copy link to clipboard

Copied

I meant parent == Group (LayerSet)

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
Guru ,
Aug 25, 2011 Aug 25, 2011

Copy link to clipboard

Copied

The layer descriptor does not have a 'parent' key. It does have a key with the stringID of "layerSection".

To Action Manger a layerSet is really two layers. One has the value of 'layerSectionStart' in the "layerSection" key. That is the layer that you can see in the Photoshop GUI. It marks the top of a layerSet. The bottom of the layerSet is a hidden layer with the value of "layerSectionEnd" in the "layerSection" key. You can not make that hidden layer active and some of the key have different values than the matching 'top'. For example if the layerSet visible in Photoshop is 'Group 1' then the name for the end of the layerSet is '</Group 1>'.

I think you could find the parent of a layer using Action Manager if you first got the index of the layer in question. Then loop backwards using the index and searching the "layerSection" key for 'layerSectionStart'. If you run into a "layerSectionEnd" before you find the start you need to keep track of that to be sure you find the correct 'start'. Doing something like this is on my list of things to do, I just haven't gotten to it yet.

Altough looping by index in Action Manager is much faster than loop in the DOM, I an not sure that finding the parent with Action Manger would be faster than just making the layer active and using the DOM to find the parent.

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
Guru ,
Aug 25, 2011 Aug 25, 2011

Copy link to clipboard

Copied

LATEST

Something like this...

function getLayerParentAMIndexByAMIndex( idx ){
     var nestedSets = 0;
     var layerCount = getNumberOfLayer();
     for( var l = idx; l <= layerCount; l++ ){
          var layerSection = getLayerSectionByAMIndex( l );
          if( layerSection == 'layerSectionEnd' ) nestedSets++;
          if( layerSection == 'layerSectionStart'  && nestedSets > 0) nestedSets--;
          if( layerSection == 'layerSectionStart'  && nestedSets == 0) return l;
     }
     function getLayerSectionByAMIndex( idx ) {
          var ref = new ActionReference();
          ref.putProperty( charIDToTypeID("Prpr") , stringIDToTypeID('layerSection'));
          ref.putIndex( charIDToTypeID( "Lyr " ), idx );
          return typeIDToStringID(executeActionGet(ref).getEnumerationValue(stringIDToTypeID('layerSection')));
     };
     function getNumberOfLayer(){
          var ref = new ActionReference();
          ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
          var desc = executeActionGet(ref);
          var numberOfLayer = desc.getInteger(charIDToTypeID("NmbL"));
          return numberOfLayer;
     };
};
getLayerNameByIndex( getLayerParentAMIndexByAMIndex( 4 ) );
function getLayerNameByIndex( idx ) {
    var ref = new ActionReference();
    ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID( "Nm  " ));
    ref.putIndex( charIDToTypeID( "Lyr " ), idx );
    return executeActionGet(ref).getString(charIDToTypeID( "Nm  " ));;
};

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