I need to replace text elements in a photoshop template via a script. When it’s a regular file, everything works fine. But if it’s a project where artboards are used, I have no way to select the active layer I want to change. The layer names are fixed and I just want to refer to them by name, but no matter how much I search I can’t find a way.
This is how I access the layers in a normal file:
#target photoshop;
var fileRef = new File("I:/ps15.psd");
if (fileRef.exists) {
app.open(fileRef); //open file
activeDocument.activeLayer = activeDocument.artLayers.getByName("layer_1"); //find the layer with the name I want
activeDocument.activeLayer.textItem.contents = "Hi!"; //text replacement
app.activeDocument.close(SaveOptions.SAVECHANGES); //close file
} else { alert("File not found"); }
I’ve found functions that determine if a layer is an artboard, but I’ve never been able to figure out how to select the active layer in them.
2
Answers
I think this code can help you out:
Artboards are really a type of layer groups, which is a type of layer. So you have you called them by name from their parent group and the child.
Alternatively, get it’s layer ID and then make that the active layer.