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

Name sublayers to CSV

Community Beginner ,
Jul 14, 2021 Jul 14, 2021

Copy link to clipboard

Copied

Does anyone have a script that can pass the name of the sublayers to CSV?

Thanks

i have this code,
but it does not detect the sublayers.

I don't understand much about scripts, can someone correct it for me?

 
#target illustrator  
  
main();  
function main(){  
 
if(!documents.length) return;  
    
var doc = app.activeDocument;  
var docTitle = doc.name;
var docTitle = docTitle.substring(0, docTitle.length - 3);
var textFile = File('~/Desktop/' + docTitle +'_Layers.csv');  
var docText = '';  
 
for (var i = 0; i < doc.layers.length; i++)  {
var currentLayer = app.activeDocument.layers[i];  
docText += currentLayer.name + '\r';  
}  
  
textFile.open('e');  
textFile.write(docText);  
textFile.close();  
}  
TOPICS
Scripting

Views

421

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

Community Expert , Jul 15, 2021 Jul 15, 2021

Hi,

It will give the name of all pageItems in the document

#target illustrator

main();
function main() {

    if (!documents.length) return;

    var doc = app.activeDocument;
    var docTitle = doc.name;
    var docTitle = docTitle.substring(0, docTitle.length - 3);
    var textFile = File('~/Desktop/' + docTitle + '_Layers.csv');
    var docText = '';

    var names = [];
    for (var i = 0; i < doc.pageItems.length; i++) {
        if (doc.pageItems[i].name != '')
            names.push(doc.p
...

Votes

Translate

Translate
Adobe
Community Expert ,
Jul 14, 2021 Jul 14, 2021

Copy link to clipboard

Copied

Hi,

Try following snippet

#target illustrator

main();
function main() {

    if (!documents.length) return;

    var doc = app.activeDocument;
    var docTitle = doc.name;
    var docTitle = docTitle.substring(0, docTitle.length - 3);
    var textFile = File('~/Desktop/' + docTitle + '_Layers.csv');
    var docText = '';

    var layersName = [];
    getAllLayers(doc, layersName);
    docText = layersName;

    textFile.open('e');
    textFile.write(docText);
    textFile.close();
}

function getAllLayers(container, layersName) {
    for (var i = 0; i < container.layers.length; i++) {
        layersName.push(container.layers[i].name);
        getAllLayers(container.layers[i], layersName);
    }
}

 

 

Best regards

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
Community Beginner ,
Jul 15, 2021 Jul 15, 2021

Copy link to clipboard

Copied

Thank you,
But I sure do something wrong

it does the same to me as the previous one,

just write me the name of the layer, I need the sublayers

😞

 

 

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
Community Expert ,
Jul 15, 2021 Jul 15, 2021

Copy link to clipboard

Copied

Could you please attach the your ai files. It may possible only single layer exists and other are groups not layers. Or may be screen shot of your Layer panel.

Best regards

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
Community Beginner ,
Jul 15, 2021 Jul 15, 2021

Copy link to clipboard

Copied

Thank you for the quick response.

Attached screenshot of the layers.

Actually there is only a single layer, maybe I explained myself wrong,
what I need are the names of the items that are in the layer.

This is possible?

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
Community Expert ,
Jul 15, 2021 Jul 15, 2021

Copy link to clipboard

Copied

Hi,

It will give the name of all pageItems in the document

#target illustrator

main();
function main() {

    if (!documents.length) return;

    var doc = app.activeDocument;
    var docTitle = doc.name;
    var docTitle = docTitle.substring(0, docTitle.length - 3);
    var textFile = File('~/Desktop/' + docTitle + '_Layers.csv');
    var docText = '';

    var names = [];
    for (var i = 0; i < doc.pageItems.length; i++) {
        if (doc.pageItems[i].name != '')
            names.push(doc.pageItems[i].name)
    }
    docText = names;

    textFile.open('e');
    textFile.write(docText);
    textFile.close();
}

 

If you want item of only variables layers then use following

#target illustrator

main();
function main() {

    if (!documents.length) return;

    var doc = app.activeDocument;
    var docTitle = doc.name;
    var docTitle = docTitle.substring(0, docTitle.length - 3);
    var textFile = File('~/Desktop/' + docTitle + '_Layers.csv');
    var docText = '';

    var names = [];
    for (var i = 0; i < doc.pageItems.length; i++) {
        if (doc.pageItems[i].name != '' && doc.pageItems[i].layer.name == 'variables')
            names.push(doc.pageItems[i].name)
    }
    docText = names;

    textFile.open('e');
    textFile.write(docText);
    textFile.close();
}
Best regards

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
Participant ,
Jul 15, 2021 Jul 15, 2021

Copy link to clipboard

Copied

@Charu Rajput 

this script works good,

get the name of sublayers to csv

 

GerssonDelgado_0-1626358920262.png

 

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
Community Beginner ,
Jul 15, 2021 Jul 15, 2021

Copy link to clipboard

Copied

Hello,
I don't see the script, where can I get it?

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
Participant ,
Jul 15, 2021 Jul 15, 2021

Copy link to clipboard

Copied

hey @siscub42209571 

the fisrt snippet provided by @Charu Rajput  in the first comment above

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
Community Expert ,
Jul 15, 2021 Jul 15, 2021

Copy link to clipboard

Copied

@GerssonDelgado 

Yes first script gives name of the sublayer, but the actual problem is @siscub42209571 document does not have sublayers. As per the screen shots it is not sublayers but page items.

I hope updated version of the script will help @siscub42209571 

Best regards

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
Community Beginner ,
Jul 15, 2021 Jul 15, 2021

Copy link to clipboard

Copied

LATEST

Yessss,

Yes Yes

now it works, thank you so much

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