Copy link to clipboard
Copied
Hi All,
I had posted a while ago inquiring about pulling Photoshop layer names in order to be copied to the XMP keywords and it was a huge success! We were successfully able to create a DAM to search for past and current files by keyword.
The issue is that we started to incorporate Illustrator into our workflow and these files are no longer searchable by keyword. We are trying to find a way to see if we can copy the Layer and Sublayer names and paste them into the XMP keywords.
Let me know if I can clear anything up!
Thanks so much!
Your LayerNames array contains the Layer objects and not the names Vasily 😋
But adding to this, ILST can have nested layers so if your use case is needing all layers and sublayers within no matter the depth, you'll need to collect them recursively:
function get(type, parent, deep) {
if (arguments.length == 1 || !parent)
(parent = app.activeDocument, deep = true);
var result = [];
if (!parent[type]) return [];
for (var i = 0; i < parent[type].length; i++) {
result
...
Copy link to clipboard
Copied
Here is a helpful link which deals with your question:
You would go through the layer names and add their names to an array variable, then you can feed this collection right into the function from the linked thread like this:
var doc = app.activeDocument;
var layerNames = [];
for(var i = 0; i < doc.layers.length; i++){
layerNames.push(doc.layers[i].name);
}
setKeywords(layerNames.join("\n")); // this function is also set to save the document - you may have to edit that part if needed.
// it also accepts a string which is delimited by nextlines, so it has a .join("\n") in this case.
Copy link to clipboard
Copied
Your LayerNames array contains the Layer objects and not the names Vasily 😋
But adding to this, ILST can have nested layers so if your use case is needing all layers and sublayers within no matter the depth, you'll need to collect them recursively:
function get(type, parent, deep) {
if (arguments.length == 1 || !parent)
(parent = app.activeDocument, deep = true);
var result = [];
if (!parent[type]) return [];
for (var i = 0; i < parent[type].length; i++) {
result.push(parent[type][i]);
if (parent[type][i][type] && deep)
result = [].concat(result, get(type, parent[type][i], deep));
}
return result || [];
}
var list = get("layers"); // Returns all layers and sublayers no matter their depth
// If Layer 1 (1 depth) contains Layer 2 (2 depth) which contains Layer 3 (3 depth)
for (var i = 0; i < list.length; i++) {
alert(list[i].name) // Returns Layer 1, Layer 2, Layer 3
}
This returns as a flat array, e.g. [Layer 1, Layer 2, Layer 3] and not nested: [ { name: "Layer 1", layer: Array} ]. If you need to convert the above to only names and not Layer objects
Array.prototype.map = function (callback) {
var mappedParam = [];
for (var i = 0; i < this.length; i++)
mappedParam.push(callback(this[i], i, this));
return mappedParam;
};
var layerNames = list.map(function (layer) {
return layer.name;
})
Copy link to clipboard
Copied
Haha, right you are! Edited.