Skip to main content
Lev_Ger
Inspiring
June 22, 2010
Question

How to get active layer comp

  • June 22, 2010
  • 2 replies
  • 2158 views

Is there a way of getting the active layer comp?

I have a script that applies a series of layer comps saving different versions of the file in between, however it seems that on a very fast machine it the script tries to move onto saving before the layer comp is fully applied, so I would like to check which layer comp is applied and only let the script continue when the value changes from the last layer comp.

This topic has been closed for replies.

2 replies

Jarda Bereza
Inspiring
August 6, 2017

...7 years later

you can use generator features

var docRef = new ActionReference(); 

      var desc = new ActionDescriptor(); 

      var JSONid = stringIDToTypeID("json"); 

      docRef.putProperty(charIDToTypeID('Prpr'), JSONid); 

      docRef.putEnumerated(stringIDToTypeID("document"), charIDToTypeID('Ordn'), charIDToTypeID('Trgt')); 

      desc.putReference(charIDToTypeID('null'), docRef); 

      desc.putBoolean(stringIDToTypeID("compInfo"), true);  // just return the Layer Comp settings 

      desc.putBoolean(stringIDToTypeID( "getCompLayerSettings" ), false); // return Layer Comp settings for each layer 

      var result = executeAction(charIDToTypeID( "getd" ), desc, DialogModes.NO).getString(JSONid); 

output:

{

    "version": "1.5.0",

    "timeStamp": 1502037519.697,

    "count": 2,

    "id": 2718,

    "comps": [

        {

            "id": 604312576,

            "name": "Layer Comp 1",

            "position": true,

            "visibility": true,

            "appearance": true

        },

        {

            "id": 635237456,

            "name": "Layer Comp 2",

            "position": true,

            "visibility": true,

            "appearance": true,

            "applied": true //this is what we want

        }

    ]

}

Inspiring
June 22, 2010

I had a look at this and I don't see a way to tell if the layerComp as been applied. You can tell if a layerComp is selected in the panel with the selected property so you could do something like this to see which comp is selected.

var layerComps= app.activeDocument.layerComps;
var activeComp;
for(var c =0;c<layerComps.length;c++){
     if(layerComps.selected) activeComp = layerComps.name;
}
alert(activeComp);

But it returns the selected comp even if it has not been applied.

There doesn't seem to be any way to tell if the comp has been applied using Action Manager(scriptlistener). I can create an executeActionGet reference that can access the layerComp class

Lev_Ger
Lev_GerAuthor
Inspiring
June 22, 2010

Could you give an example of the executeActionGet method?

Inspiring
June 22, 2010

Here is an example that get the current tool.

function getCurrentTool()}
   var ref = new ActionReference();
   ref.putEnumerated( charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
   return = typeIDToStringID(executeActionGet(ref).getEnumerationType(stringIDToTypeID('tool')));
}

But for executeActionGet to work you need to create an Action Reference to the class or property you want to get the Action Descriptor for. Here is the scriptlistener log for apply layerComp.

var idapplyComp = stringIDToTypeID( "applyComp" );
    var desc37 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref36 = new ActionReference();
        var idcompsClass = stringIDToTypeID( "compsClass" );
        ref36.putName( idcompsClass, "Layer Comp 1" );
    desc37.putReference( idnull, ref36 );
executeAction( idapplyComp, desc37, DialogModes.NO );

It has been my experence that when null is used in the reference you can not access that class with Action Manager.