Answered
Can't get access to layers of Smart object by Script
Hi all. I have a small script that should open all folders and change all text layers. But I need to change text layers in smart objects too and this is the biggest problem. I don't know why but I can only get the name of the smart object and nothing else.
function replaceTextInLayers(layer) {
if (layer.kind == LayerKind.TEXT) {
var currentText = layer.textItem.contents;
var newText = findTranslation(currentText);
layer.textItem.contents = newText;
}else if(layer.kind === LayerKind.SMARTOBJECT) {
alert("Name of smart object: " + layer.name)
layer.smartObject.editContents();
var smartDoc = app.activeDocument;
if (smartDoc != null) {
alert("Layers count in smart objects: " + smartDoc.layers.length);
} else {
alert("Smart object is null");
}
smartDoc.close(SaveOptions.DONOTSAVECHANGES);
}
if (layer instanceof LayerSet) {
for (var i = 0; i < layer.layers.length; i++) {
replaceTextInLayers(layer.layers[i]);
}
}
}
