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

Script Help: Layer names based on Excel Data

Explorer ,
Jul 10, 2015 Jul 10, 2015

Hello!

I'm a scripting noob and have been trying to learn but unfortunately I just don't have the time. Projects at work keeps me at bay. Anyhow, here is my scenario and hopefully someone can guide me.

I want a script that would look at a database (XML, CSV, excel or whatever works) and create separate layers in illustrator based on the data.

Example: part number and description is from a database. Illustrator Layer Name is what I want the script to automate. The reason for this request is a 200 item project that I don't want to re-type.

part numberdescriptionIllustrator Layer Name
33456Item 133456_Item 1
33457Item 233457_Item 2
33458Item 333458_Item 3
33459Item 433459_Item 4
33460Item 533460_Item 5
33461Item 633461_Item 6
33462Item 733462_Item 7
33463Item 833463_Item 8

After I have all my items laid out with correct layer names, i export each layer as a separate PDF. The file name of the export would be the same as the layer name with  "_1up" appended at the end. For example, 33456_Item 1_1up.ai.

I would have a separate illustrator file that contains all the same layer name as above and I would then place the exported file to it's respected layer. This is where the another script would be great. Is it possible make to a script that will place an image to a layer that has similar naming structures (the only differences would be the layer name wouldn't have "_1up")?

Hopefully this makes sense and I know I'm asking alot. Thank you very much in advance!

TOPICS
Scripting
3.1K
Translate
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

Guide , Jul 10, 2015 Jul 10, 2015

still not sure why you export all layers to separate files only to place them all back in again?

but this will get your layers created.

var line,lay,myLayers = [];

var csvFile = File('e:/csv.csv');

csvFile.open( 'r' );

while(!csvFile.eof){

    line = csvFile.readln();

    line = line.replace(',','_');

    myLayers.push(line);

}

csvFile.close();

var doc = app.activeDocument;

for(var i = myLayers.length - 1; i > 0; i--){

    lay = doc.layers.add();

    lay.name = myLayers;

}

var oldLayer = doc.la

...
Translate
Adobe
Guide ,
Jul 10, 2015 Jul 10, 2015

nothing to hard there. but need some more info.

sounds like you want:

     excel to layer names

     part files to each layer

     export each layer

     re import to layers

     add image

if you have the parts and they are named then this sounds like too much.

would this work? (or have I miss understood)

     import all parts from file to layer with filename as layername

     import image to each layer

  

tell us more about what you have:

ie.

files you have and there naming structure

if you only had 5 to do you would do it manually,

can you feed us a step by step of what you would do if you did it manually.

Translate
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
Explorer ,
Jul 10, 2015 Jul 10, 2015

Thank you for the reply.

To restate I want to import the excel column data as illustrator layer names. Once I have the layer names matching the excel database I then manually create the contents of each layer. Once complete I then export each layer as individual files and the filename matches the layer name with an additional "_1up" (I have a script that does this already).

I duplicate the file that exported the _1up files and delete all its contents while retaining only the layer names. I then place the exported _1up files to their matching layers (this is the script I'm looking for in addition to the import of excel data as illustrator layer names)

Does This make sense? Thank you again.

Translate
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
Guide ,
Jul 10, 2015 Jul 10, 2015

still not sure why you export all layers to separate files only to place them all back in again?

but this will get your layers created.

var line,lay,myLayers = [];

var csvFile = File('e:/csv.csv');

csvFile.open( 'r' );

while(!csvFile.eof){

    line = csvFile.readln();

    line = line.replace(',','_');

    myLayers.push(line);

}

csvFile.close();

var doc = app.activeDocument;

for(var i = myLayers.length - 1; i > 0; i--){

    lay = doc.layers.add();

    lay.name = myLayers;

}

var oldLayer = doc.layers.getByName('Layer 1');

oldLayer.remove();

csv should just be:

33456,Item 1

33457,Item 2

...

Translate
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
Explorer ,
Jul 13, 2015 Jul 13, 2015

The reason why I export to separate files only to place them all back again is because I treat each separate files as a reference link. I'm in prepress and we step out files in a multitude of ways and often times a single item would be used multiple times in a layout. Just like in coding, if there are any changes to a file I would go back to the original file, fix it and then re-export. Less errors this way.

Translate
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
Explorer ,
Jul 13, 2015 Jul 13, 2015

My apologies... I wasn't finished responding.

I did try the code you provided Qwertyfly but it gets stuck. See attached screenshot.

Also, how does the code know which CSV file to use? I'm on a mac but line 2 looks like a pc location.

Screen Shot 2015-07-13 at 8.14.51 AM.png

Thank you again.

Translate
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
Guide ,
Jul 13, 2015 Jul 13, 2015

when a new document is created it typicaly has a layer named "Layer 1".

the last 2 lines of code remove the default layer.

if you have the "Identify Objects By:" preference set to "XML ID", or if you use a different language, it may not be called "Layer 1".

change this value to the name of the default layer in a new document, or remove the last 2 lines of code.

as for line 2 of the code, the path "e:/csv.csv" is where I put the csv file I used for testing.

change this to the location of your file.

your user documents folder will look something like:

     ~/Documents/MyCSVfile.csv

Translate
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
Explorer ,
Jul 15, 2015 Jul 15, 2015

I finally got a chance to test the script and I can say it worked like a charm! Thank you ever so much.

Any luck with the 2nd part of the script request which imports a file to a layer with the same filename?

Again, thank you very much for your help!

Translate
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
Guide ,
Jul 16, 2015 Jul 16, 2015

‌aare all the images in a folder?

are they .jpg or ....

where  do you want them?

centered on the page?

Translate
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
Explorer ,
Jul 16, 2015 Jul 16, 2015

All the images are in the same folder (/Working Files/1ups) and they are either  .ai or .pdf.  When imported, it doesn't matter where they are on the page - all of them can be centered on the page.

I've attached a screenshot of my folder structure (the same for every project) and illustrator layers & links palette.

FolderStructure.pngAI Palette.png

I made a mistake in telling you that the only difference between the layer name and the links imported is the appended "_1up". Attached at the beginning of the 1ups linked file is a project number that is 5 digits long followed by an underscore.

Thank you so much for helping me with this... I surely appreciate you taking the time and helping! Have a great one.

Translate
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
Explorer ,
Jul 04, 2019 Jul 04, 2019
LATEST

Hi guys!

I was very happy to find similar topic, without a need to open a new one.

Although my issue is a bit different. I have a SVG file with multiple layers that are named the same: <Layer>.

Now what I would like to do is to rename those layers according to a column A in excel file.

(or even better, although I know it's probably impossible - according to layers in Adobe Animate project).

The thing is I am importing SVG file exported from Animate and unfortunately it doesn't retain layer names.

There is a function called Optimize for Character Animator which does that, but it totally screws up the images inside the SVG.

Since I am a script newbie I don't even know where to start to edit the script in this thread, so it would fit my need.

Any help would be great!

Translate
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