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

87

Likes

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

Adobe Community Professional , 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...

Likes

Translate

Translate
Adobe Community Professional ,
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

Likes

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

😞

 

 

Likes

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
Adobe Community Professional ,
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

Likes

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?

Likes

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
Adobe Community Professional ,
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

Likes

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

 

Likes

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?

Likes

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

Likes

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
Adobe Community Professional ,
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

Likes

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

Likes

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