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

Script to get list of all smart object layers

Explorer ,
Aug 17, 2022 Aug 17, 2022

Copy link to clipboard

Copied

Can you change this code to simply output a list of the name of every smart object?

TOPICS
Actions and scripting , SDK

Views

80

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
Adobe
Community Expert ,
Aug 18, 2022 Aug 18, 2022

Copy link to clipboard

Copied

Try the following, it will print the names of all smartobject layers. The names of layers inside group as written in the format group_name:layer_name

function getlayerNames(lyrCol, grpName){
	var retval = []
	for(var i = 0; i < lyrCol.length; i++){
		var lyr  =  lyrCol[i]
		var nm = grpName ? grpName + ":" + lyr.name : lyr.name
		if(lyr.typename == "LayerSet")
			retval = retval.concat(getlayerNames(lyr.layers, nm))
		if(lyr.kind == LayerKind.SMARTOBJECT){
			retval.push(nm)
		}
	}
	return retval
}


alert(getlayerNames(activeDocument.layers))

-Manan

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
Community Expert ,
Aug 18, 2022 Aug 18, 2022

Copy link to clipboard

Copied

LATEST

This would get an Array of Arrays containing the names and IDs. 

// 2017, use it at your own risk;
#target photoshop
if (app.documents.length > 0) {
alert (collectSmartObjects2017().join("\n"));
};
////////////////////////////////////
////// collect smart objects, probably based on code by paul, mike or x //////
function collectSmartObjects2017 () {
// the file;
var myDocument = app.activeDocument;
// get number of layers;
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
var applicationDesc = executeActionGet(ref);
var theNumber = applicationDesc.getInteger(stringIDToTypeID("numberOfLayers"));
// process the layers;
var theLayers = new Array;
for (var m = 0; m <= theNumber; m++) {
try {
var ref = new ActionReference();
ref.putIndex( charIDToTypeID( "Lyr " ), m);
var layerDesc = executeActionGet(ref);
var layerSet = typeIDToStringID(layerDesc.getEnumerationValue(stringIDToTypeID("layerSection")));
var isBackground = layerDesc.getBoolean(stringIDToTypeID("background"));
// if not layer group collect values;
if (layerSet != "layerSectionEnd" && layerSet != "layerSectionStart" && isBackground != true) {
var theName = layerDesc.getString(stringIDToTypeID('name'));
var theID = layerDesc.getInteger(stringIDToTypeID('layerID'));
if(layerDesc.hasKey(stringIDToTypeID('smartObject'))) {theLayers.push([theName, theID])}
};
}
catch (e) {};
};
return theLayers
};

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