Skip to main content
Participant
October 3, 2024
Question

A l'aide ;) Automatiser l'enregistrement de chaque calque en jpg en gardant le nom de chaque calque

  • October 3, 2024
  • 3 replies
  • 402 views

Bonjour, j'ai très régulièrement des PSD avec :

- en haut plusieurs calques d'habillage graphique qui doivent rester en permanence

- en-dessous des dizaines de calque avec un portrait différent (personnes différentes)

Pour enregistrer chaque portrait avec l'habillage graphique par dessus je dois :

- copier le nom du calque

- coller le nom du calque

- enregister en jpg

 

Je cherche un moyen d'automatiser ou un script pour que l'enregistrement en jpg prenne les noms des calques.

 

Un grand merci d'avance !!!

This topic has been closed for replies.

3 replies

c.pfaffenbichler
Community Expert
Community Expert
October 13, 2024

Did you give the Script a try? 

If it should not work out please provide the layered file for testing (a lores version with blurred out image-content would suffice). 

Participant
October 14, 2024

No, I don't know how to transform your text into a script, how to bring it in Photoshop...

c.pfaffenbichler
Community Expert
Community Expert
October 6, 2024

You can give this a try: 

// save jpg for each layer in group of certain name;
// 2024, use it at your own risk;
if (app.documents.length > 0) {
var myDocument = app.activeDocument;
try {
var theName = myDocument.name.match(/(.*)\.[^\.]+$/)[1];
var thePath = myDocument.path;
}
catch (e) {
var theName = myDocument.name;
var thePath = "~/Desktop"
};
// jpg options;
var jpgopts = new JPEGSaveOptions();
jpgopts.embedProfile = true;
jpgopts.formatOptions = FormatOptions.STANDARDBASELINE;
jpgopts.matte = MatteType.NONE;
jpgopts.quality = 10;
// collect layers in group of name;
var theLayers = collectLayersInGroupOfName ("JOUERURS");
// hide layers;
for (var m = 0; m < theLayers.length; m++) {
showHideLayer (theLayers[m][2], "hide")
};
// show one layer and save jpg;
for (var n = 0; n< theLayers.length; n++) {
showHideLayer (theLayers[n][2], "show");
myDocument.saveAs((new File(thePath+"/"+"_"+theName+"_"+theLayers[n][0]+".jpg")),jpgopts,true);
};
};
////// collect layers in group of name //////
function collectLayersInGroupOfName (theName) {
var theGroup = collectLayersOfName (theName, true);
if (theGroup.length == 1) {
// get number of layers;
var ref = new ActionReference();
ref.putProperty(stringIDToTypeID('property'), stringIDToTypeID('numberOfLayers'));
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 group collect values;
if (layerSet != "layerSectionEnd" && layerSet != "layerSectionStart" && isBackground != true) {
var theName = layerDesc.getString(stringIDToTypeID('name'));
var theID = layerDesc.getInteger(stringIDToTypeID('layerID'));
var theIndex = layerDesc.getInteger(stringIDToTypeID('itemIndex'));
var theParentId = layerDesc.getInteger(stringIDToTypeID('parentLayerID'));
if (theParentId == theGroup[0][2]) {theLayers.push([theName, theIndex, theID])}
};
}
catch (e) {};
};
return theLayers
} else {alert ("no such group or more than one group")}
};
////// based on code by mike hale, via paul riggott //////
function selectLayerByID(id,add){
try {
add = undefined ? add = false:add 
var ref = new ActionReference();
ref.putIdentifier(charIDToTypeID("Lyr "), id);
var desc = new ActionDescriptor();
desc.putReference(charIDToTypeID("null"), ref );
if(add) desc.putEnumerated( stringIDToTypeID( "selectionModifier" ), stringIDToTypeID( "selectionModifierType" ), stringIDToTypeID( "addToSelection" ) ); 
desc.putBoolean( charIDToTypeID( "MkVs" ), false ); 
try{
executeAction(charIDToTypeID("slct"), desc, DialogModes.NO );
}catch(e){
alert(e.message); 
}
} catch (e) {}
};
////// collect layers //////
function collectLayersOfName (theString, isGroup) {
// get number of layers;
var ref = new ActionReference();
ref.putProperty(stringIDToTypeID('property'), stringIDToTypeID('numberOfLayers'));
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 group collect values;
if (layerSet != "layerSectionEnd" /*&& layerSet != "layerSectionStart" && isBackground != true*/) {
var theName = layerDesc.getString(stringIDToTypeID('name'));
var theID = layerDesc.getInteger(stringIDToTypeID('layerID'));
var theIndex = layerDesc.getInteger(stringIDToTypeID('itemIndex'));
var theColor = typeIDToStringID(layerDesc.getEnumerationValue(stringIDToTypeID("color")));
if (layerSet == "layerSectionStart" && isGroup == true) {
if (theName == theString) {theLayers.push([theName, theIndex, theID, theColor])}
};
if (layerSet != "layerSectionStart" && isGroup == false) {
if (theName == theString) {theLayers.push([theName, theIndex, theID, theColor])}
};
};
}
catch (e) {};
};
return theLayers
};
////// show or hide layer //////
function showHideLayer (theID, showOrHide) {
var idhide = stringIDToTypeID( showOrHide );
var desc22 = new ActionDescriptor();
var list2 = new ActionList();
var ref8 = new ActionReference();
ref8.putIdentifier( stringIDToTypeID( "layer" ), theID );
list2.putReference( ref8 );
desc22.putList( stringIDToTypeID( "null" ), list2 );
executeAction( idhide, desc22, DialogModes.NO );
};

c.pfaffenbichler
Community Expert
Community Expert
October 3, 2024

Could you please post screenshots with the pertinent Panels (Toolbar, Layers, Options Bar, …) visible to clarify the Layer structure? 

Participant
October 3, 2024

c.pfaffenbichler
Community Expert
Community Expert
October 4, 2024

Thanks. 

Please forgive the delay; I am currently not able to really help you due to time restraints. 

 

If the Group containing the Layers (that need to be saved out with the design elements one by one) can always be identified by its name the task can definitively be automated and such operations have come up before, though I am not sure what the best search term on the Forum would be …