Length of specific layer
Greetings everyone,
I'm strugling with a problem for a script.
My main goal was to export in a CSV files the names of the layers within a specific layer.
My layers are as follow :
- Texte
- Calque 1
- Sub layer 1
- Sub layer 2
- ...
- Text
- 1
- 1
- 1
- 2
- 2
- 3
- 3
- 3
- 5
- 5
- 5
- 5
- 6
- ...
- PUCES
- CALQUES
I want it to export the names of the layers from the layer "Text", so 1;1;1;2;2;3;3;3;3;5....
The script I used is as following, inspired by a fellow scripter on the web :
#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/Tests/' + docTitle + '_Layers.csv');
var docText = '';
var TEXTLayer = doc.layers.getByName("Text");
var TEXTLength = doc.layers.getByName("Text").length;
for (var i = 0; i < doc.layers.length; i++) {
var currentLayer = doc.layers[i];
docText += docTitle +';' + currentLayer.name + '\r';
}
textFile.open('e');
textFile.write(docText);
textFile.close();
}
This script works perfectly for the top layers of my document (here Texte, Calque 1, Text, PUCES and CALQUES ).
But whe I apply the function below to the var "TextLayer" with the getByName method, to get the layers of the layer "Text" :
for (var i = 0; i < TEXTLength; i++) {
var currentLayer = TEXTLayer.layers[i];
docText += docTitle +';' + currentLayer.name + '\r';
It doesn't work.
I tried to dig up what the problem could be and it appears that TEXTLength is undefined ...
Same apply if I try to get the length of the other top layers (Texte, Calque 1 ...).
Is it a problem in the writing ? In the properties of the layers/sublayers? Or something else ?
I'm quite new to Javascript so that doesn't help ... ^^'
Many thanks in advance for your help !