rename layer comps
Posted: Sun Mar 15, 2015 10:45 am
It’s a potentially time-consuming work-around to duplicate the image in order to determine the selected LayerComps but creating a Snapshot or making sure the HistoryStates number is set high enough seem a bother to me, so if someone wants to give it a try here is some code:
Code: Select all// determine selected layercomps;
// 2015, use it at your own risk;
#target "photoshop-70.032"
if (app.documents.length > 0) {
alert (getSelectedLayerComps().join("\n"))
};
////////////////////////////////////
////// determine selected layer comps //////
function getSelectedLayerComps () {
////////////////////////////////////
var theComps = app.activeDocument.layerComps;
var theNumber = theComps.length;
////////////////////////////////////
if (theNumber > 0) {
var myDocument = app.activeDocument.duplicate("thecopy", false);
var theComps2 = app.activeDocument.layerComps;
////////////////////////////////////
for (var m = 0; m < theNumber; m++) {
theComps2[m].name = String(m);
};
////////////////////////////////////
deleteLayerComps ();
try {
////////////////////////////////////
var theMissing = new Array;
var theCounter = 0;
// check against old list;
for (var n = 0; n < theNumber; n++) {
if (theCounter < myDocument.layerComps.length) {
if (Number(myDocument.layerComps[theCounter].name) != n) {theMissing.push(theComps[n])}
else {theCounter ++}
} else {theMissing.push(theComps[n])};
};
////////////////////////////////////
} catch (e) {myDocument.close(SaveOptions.DONOTSAVECHANGES)};
};
try {myDocument.close(SaveOptions.DONOTSAVECHANGES)} catch (e) {};
return (theMissing)
};
////// delete layer comps //////
function deleteLayerComps () {
try {
// =======================================================
var idDlt = charIDToTypeID( "Dlt " );
var desc2 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref1 = new ActionReference();
var idcompsClass = stringIDToTypeID( "compsClass" );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref1.putEnumerated( idcompsClass, idOrdn, idTrgt );
desc2.putReference( idnull, ref1 );
executeAction( idDlt, desc2, DialogModes.NO );
} catch (e) {}
};
////// rename layer comp //////
function nameLayerComp () {
// =======================================================
var idsetd = charIDToTypeID( "setd" );
var desc1 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref1 = new ActionReference();
var idcompsClass = stringIDToTypeID( "compsClass" );
ref1.putName( idcompsClass, "2" );
desc1.putReference( idnull, ref1 );
var idT = charIDToTypeID( "T " );
var desc2 = new ActionDescriptor();
var iduseVisibility = stringIDToTypeID( "useVisibility" );
desc2.putBoolean( iduseVisibility, true );
var idusePosition = stringIDToTypeID( "usePosition" );
desc2.putBoolean( idusePosition, true );
var iduseAppearance = stringIDToTypeID( "useAppearance" );
desc2.putBoolean( iduseAppearance, true );
var idTtl = charIDToTypeID( "Ttl " );
desc2.putString( idTtl, """22""" );
var idcompsClass = stringIDToTypeID( "compsClass" );
desc1.putObject( idT, idcompsClass, desc2 );
executeAction( idsetd, desc1, DialogModes.NO );
};
Code: Select all// determine selected layercomps;
// 2015, use it at your own risk;
#target "photoshop-70.032"
if (app.documents.length > 0) {
alert (getSelectedLayerComps().join("\n"))
};
////////////////////////////////////
////// determine selected layer comps //////
function getSelectedLayerComps () {
////////////////////////////////////
var theComps = app.activeDocument.layerComps;
var theNumber = theComps.length;
////////////////////////////////////
if (theNumber > 0) {
var myDocument = app.activeDocument.duplicate("thecopy", false);
var theComps2 = app.activeDocument.layerComps;
////////////////////////////////////
for (var m = 0; m < theNumber; m++) {
theComps2[m].name = String(m);
};
////////////////////////////////////
deleteLayerComps ();
try {
////////////////////////////////////
var theMissing = new Array;
var theCounter = 0;
// check against old list;
for (var n = 0; n < theNumber; n++) {
if (theCounter < myDocument.layerComps.length) {
if (Number(myDocument.layerComps[theCounter].name) != n) {theMissing.push(theComps[n])}
else {theCounter ++}
} else {theMissing.push(theComps[n])};
};
////////////////////////////////////
} catch (e) {myDocument.close(SaveOptions.DONOTSAVECHANGES)};
};
try {myDocument.close(SaveOptions.DONOTSAVECHANGES)} catch (e) {};
return (theMissing)
};
////// delete layer comps //////
function deleteLayerComps () {
try {
// =======================================================
var idDlt = charIDToTypeID( "Dlt " );
var desc2 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref1 = new ActionReference();
var idcompsClass = stringIDToTypeID( "compsClass" );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref1.putEnumerated( idcompsClass, idOrdn, idTrgt );
desc2.putReference( idnull, ref1 );
executeAction( idDlt, desc2, DialogModes.NO );
} catch (e) {}
};
////// rename layer comp //////
function nameLayerComp () {
// =======================================================
var idsetd = charIDToTypeID( "setd" );
var desc1 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref1 = new ActionReference();
var idcompsClass = stringIDToTypeID( "compsClass" );
ref1.putName( idcompsClass, "2" );
desc1.putReference( idnull, ref1 );
var idT = charIDToTypeID( "T " );
var desc2 = new ActionDescriptor();
var iduseVisibility = stringIDToTypeID( "useVisibility" );
desc2.putBoolean( iduseVisibility, true );
var idusePosition = stringIDToTypeID( "usePosition" );
desc2.putBoolean( idusePosition, true );
var iduseAppearance = stringIDToTypeID( "useAppearance" );
desc2.putBoolean( iduseAppearance, true );
var idTtl = charIDToTypeID( "Ttl " );
desc2.putString( idTtl, """22""" );
var idcompsClass = stringIDToTypeID( "compsClass" );
desc1.putObject( idT, idcompsClass, desc2 );
executeAction( idsetd, desc1, DialogModes.NO );
};