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

Is there any way to get active layer comp in JSX?

Community Beginner ,
Nov 20, 2017 Nov 20, 2017

Copy link to clipboard

Copied

I want go get currently active layer comp.

Is there any way to that?

TOPICS
Actions and scripting

Views

1.8K

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

People's Champ , Nov 21, 2017 Nov 21, 2017

Probably so. Works in CC2018 (verified)

 

aaa()

function aaa()
    {
    try
        {
        var r = new ActionReference();
        r.putProperty( charIDToTypeID( "Prpr" ), stringIDToTypeID( "json" ) );
        r.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

        var ret = executeActionGet(r); 

        var json = ret.getString(stringIDToTypeID("json"));

        eval("var obj= " + json);

        var ok = false;

        for (var i = 0; i < obj.
...

Votes

Translate

Translate
Adobe
Guide ,
Nov 20, 2017 Nov 20, 2017

Copy link to clipboard

Copied

This will give the first selected Layer Comp, it does not check if more than one comp is selected!

#target photoshop;

main();

function main(){

var sourceDoc = app.activeDocument;

for( var c = 0; c < sourceDoc.layerComps.length; c++ ){

     if( sourceDoc.layerComps.selected == true ){

         // do whatever get name etc.

         alert(sourceDoc.layerComps.name + " is selected");

         return;

         }}

     alert("No layer comp selected");

};

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
Enthusiast ,
Nov 20, 2017 Nov 20, 2017

Copy link to clipboard

Copied

Selected layer comp is not active layer comp.

Activation has its own state button.

I tried to solve this and only thing that worked for me was getting data via generator plugin.

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
People's Champ ,
Nov 21, 2017 Nov 21, 2017

Copy link to clipboard

Copied

Probably so. Works in CC2018 (verified)

 

aaa()

function aaa()
    {
    try
        {
        var r = new ActionReference();
        r.putProperty( charIDToTypeID( "Prpr" ), stringIDToTypeID( "json" ) );
        r.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

        var ret = executeActionGet(r); 

        var json = ret.getString(stringIDToTypeID("json"));

        eval("var obj= " + json);

        var ok = false;

        for (var i = 0; i < obj.comps.length; i++)
            {
            if (obj.comps[i].applied)
                 {
                 var idx = get_comp_idx(obj.comps[i].id);

                 alert ( obj.comps[i].name + "\n\n" + "index: " + (idx-1) + "\n\n" + "id:" + obj.comps[i].id + "\n\n" +
                        "app.activeDocument.layerComps["+(idx-1)+"].name = " + app.activeDocument.layerComps[idx-1].name, "Applied comp");

                 ok = true;
                 break;
                 }
            }

        if (!ok) alert ("No applied comp found");

        function get_comp_idx(id)
            {
            try
                {
                var r = new ActionReference();
                r.putProperty( charIDToTypeID( "Prpr" ), stringIDToTypeID("compsList"));
                r.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
   
                var comps = executeActionGet(r).getList(stringIDToTypeID("compsList")); 

                for (var i = 0; i < comps.count; i++)
                    if (comps.getObjectValue(i).getInteger(stringIDToTypeID("ID")) == id)
                        return comps.getObjectValue(i).getInteger(stringIDToTypeID("itemIndex"));
       
                return -1;
                }
            catch (e) { alert(e); }
            }

        }
    catch (e) { alert(e)  }
    }

 

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
Enthusiast ,
Nov 21, 2017 Nov 21, 2017

Copy link to clipboard

Copied

This is interesting. I thought that JSON property returns all properties accessible with document reference without property. But this is exactly same content as from Generator plugin 🙂

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
Explorer ,
Dec 16, 2019 Dec 16, 2019

Copy link to clipboard

Copied

LATEST

Thank you, r-bin! I've been figuring this problem out all day.

 

LayerComp only has the "selected" property. There is no property for an active or applied layer comp. A selected layer comp does not mean that it is the active layer comp. There can even be several selected layer comps and the active one may not even be selected.

 

I have simplified your code and it works in Adobe Photoshop 2020, too:

var doc = activeDocument;

function getActiveLayerComp(){
	var r = new ActionReference();
	r.putProperty( charIDToTypeID( "Prpr" ), stringIDToTypeID( "json" ) );
	r.putEnumerated( charIDToTypeID( "Dcmn" ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
	
	var ret = executeActionGet( r );  
	var json = ret.getString( stringIDToTypeID( "json" ) );
    eval( "var obj= " + json );
	
	for ( i = 0; i < doc.layerComps.length; i++ ){
		var compRef = doc.layerComps[ i ];
		if( obj.comps[ i ].applied )
			return compRef;
	}
}



 

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