• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Illustrator Script to Copy Layer Names into Metadata

Community Beginner ,
Jan 21, 2021 Jan 21, 2021

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!

TOPICS
Scripting

Views

428

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Enthusiast , Jan 21, 2021 Jan 21, 2021

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
...

Votes

Translate

Translate
Adobe
Valorous Hero ,
Jan 21, 2021 Jan 21, 2021

Copy link to clipboard

Copied

Here is a helpful link which deals with your question:

https://community.adobe.com/t5/illustrator/add-keywords-with-script-xmp/m-p/7698285?page=1https://co...

 

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.

 

 

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jan 21, 2021 Jan 21, 2021

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;
})

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Jan 21, 2021 Jan 21, 2021

Copy link to clipboard

Copied

LATEST

Haha, right you are! Edited.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines