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

Script to import csv file to create artboards with name and size

New Here ,
Mar 22, 2019 Mar 22, 2019

Copy link to clipboard

Copied

Hello,

is there a script or possibility to create multiple artboards via a .csv file in illustrator?

For example in the csv file is written …

Name of the artboard, height of the artboard and the width of the artboard. With that information

in the csv file illustrator could generate artboards with that specification and naming.

And is it possible to arrange the generated artboards automatically in a specific way?

For example …

artboard 1 (100 x 100 px)  |  artboard 2 (50 x 50 px)  |  artboard 3 (25 x 25 px) ↵

artboard 4 (100 x 100 px)  |  artboard 5 (50 x 50 px)  |  artboard 6 (25 x 25 px) ↵

artboard 7 (100 x 100 px)  |  artboard 8 (50 x 50 px)  |  artboard 9 (25 x 25 px) ↵

and so on …

Thanks a lot.

Saludos.

Simon

TOPICS
Scripting

Views

2.7K

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
Adobe Employee ,
Mar 22, 2019 Mar 22, 2019

Copy link to clipboard

Copied

Moved to Illustrator Scripting

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 ,
Mar 23, 2019 Mar 23, 2019

Copy link to clipboard

Copied

yes, it is possible to create and arrange artboards from data in a csv. Do you need help getting started with scripting?

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
New Here ,
Mar 25, 2019 Mar 25, 2019

Copy link to clipboard

Copied

Hello Carlos,

thank you for your response. Yes I need help to get started with scripting.

I am not familiar with scripting and I don´t know how to start.

Thank you.

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 ,
Mar 25, 2019 Mar 25, 2019

Copy link to clipboard

Copied

you can start reading a practicing with the official scripting guides/references.

Illustrator Scripting | Adobe Developer Connection

come back here and ask as many questions if you get stuck.

to get your gears going, open a document and run the following script

var idoc = app.activeDocument;

var ab = idoc.artboards.add([0, 0, 100, -200]);

it will add a new 100x200 artboard at left/top corner 0,0

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
New Here ,
Mar 26, 2019 Mar 26, 2019

Copy link to clipboard

Copied

Hello Carlos,

that´s what I got so far. I am not sure is good enough to

get it running with data from csv file.

var newDoc = app.documents.add(

  DocumentColorSpace.RGB,

  width = 1, 

    height = 1, 

    numArtboards = 1, 

    DocumentArtboardLayout.GridByCol, 

    artboardSpacing = 20, 

    artboardRowsOrCols = 2,);

/*var newDoc = app.activeDocument;

alert(newDoc.rulerOrigin);

alert(newDoc.pageOrigin);*/

var idoc16 = app.activeDocument;

var ab16 = idoc16.artboards.add([0, 0, 16, -16]);

ab16.name = "_16";

var rectRef = idoc16.pathItems.rectangle(0, 0, 16, 16);

var areaTextRef = idoc16.textFrames.areaText(rectRef);

areaTextRef.contents = "16";

areaTextRef.selected = true;

var rectRef = idoc16.pathItems.rectangle(0, -140, 100, 26);

var areaTextRef = idoc16.textFrames.areaText(rectRef);

areaTextRef.contents = "ROW 1";

areaTextRef.selected = true;

var idoc24 = app.activeDocument;

var ab24 = idoc24.artboards.add([36, 0, 60, -24]);

ab24.name = "_24";

var rectRef = idoc24.pathItems.rectangle(0, 36, 24, 24);

var areaTextRef = idoc24.textFrames.areaText(rectRef);

areaTextRef.contents = "24";

areaTextRef.selected = true;

var idoc32 = app.activeDocument;

var ab32 = idoc32.artboards.add([80, 0, 112, -32]);

ab32.name = "_32";

var rectRef = idoc32.pathItems.rectangle(0, 80, 32, 32);

var areaTextRef = idoc32.textFrames.areaText(rectRef);

areaTextRef.contents = "32";

areaTextRef.selected = true;

var idoc48 = app.activeDocument;

var ab48 = idoc48.artboards.add([132, 0, 180, -48]);

ab48.name = "_48";

var rectRef = idoc48.pathItems.rectangle(0, 132, 48, 48);

var areaTextRef = idoc48.textFrames.areaText(rectRef);

areaTextRef.contents = "48";

areaTextRef.selected = true;

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
Contributor ,
Mar 26, 2019 Mar 26, 2019

Copy link to clipboard

Copied

Hello, how are you?

Welcome to our beautiful Scripting world.

As seen above you are already able to create the artboards, my question is: Why .csv files? .csv as other text files are possible to read and return to the illustrator using the simple way to read and close the file by assigning its contents to a string. Sample:

var myFile = File ('~/Desktop/Artboards.csv');

myFile.open("r"); 

var contentString = myFile.read();

myFile.close();

alert (contentString);

But to do the reading and indexing of the content to use in the course of the script you should assign everything to an Array handling all the text, and this will earn you a lot of hard work ... I suggest using .XML files for this task as javascript already does the reading and indexing of an .xml natively. Here is an Sample:

Artboards.xml

<?xml version="1.0"?>

<Artboards> 

  <AB1>

       <left>0</left>

       <top>0</top>

       <right>16</right>

       <bottom>-16</bottom>

  </AB1>

  <AB2>

       <left>36</left>

       <top>0</top>

       <right>60</right>

       <bottom>-24</bottom>

  </AB2>

  <AB3>

       <left>80</left>

       <top>0</top>

       <right>112</right>

       <bottom>-32</bottom>

  </AB3>

  <AB4>

       <left>132</left>

       <top>0</top>

       <right>180</right>

       <bottom>-48</bottom>

  </AB4>

</Artboards> 

To make this parseXML use the code below similarly to the .csv file:

var xmlFile = File ('~/Desktop/Artboards.xml');

    xmlFile.open('r'); 

    var myXML = XML(xmlFile.read()); 

    xmlFile.close();

//Here you read the node you want from xml, in case Bottom from AB1

    alert(myXML.AB1.bottom);

I think it's the most practical way to do this.

I hope helped anyway...

Greetings,

-Vinícius Dias

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
Contributor ,
Mar 28, 2019 Mar 28, 2019

Copy link to clipboard

Copied

I am using this javascript parser for tab separated CSV:

var curData = parse(curContents, false);

function parse( curContents, option) {

try {  

        // output object

        var data = {},

        // output no columns array

        container = [],

        // output array

        records = [],

        // splits csv data at each new line

        lines =input.split(/\r/),

        // creates columns by splitting first line of csv

        columns = lines[0].split('\t');

               

        // creates objects from csv data if column option included

        if (option === true) {

            // loop through each line of csv file

            for (var l = 1; l <= lines.length-1; l++) {

                // splits each line of csv by comma

                var words = lines.split('\t');

                // builds object based on column headers

                for (var cell in columns) {

                   

                    data[ columns[cell] ] = words[cell];         

                }

           

                // pushes object to output array

                records.push(data);

                // resets object in order to add another

                data = {};

            }

       

        } else {

           

            // creates nested arrays from csv data if column option omitted, false or not true

           

            for (var l = 0; l <= lines.length-1; l++) {

               

                var curLine = lines;

               

                // leere Zeilen ignorieren

                if (curLine == "\t") continue;

               

                // splits each line of csv by comma

                var words = curLine.split('\t');

               

                // creates objects from csv data               

                for (var cell in words) {

                    container.push(words[cell]);   

                }

           

                // push array to output array

                records.push(container);

               

                // reset array in order to add another

                container = [];

            }

        }

   

        // returns output array

        return records;

       

      

    } catch(error){

        return err;

    }

}

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
Explorer ,
Aug 18, 2020 Aug 18, 2020

Copy link to clipboard

Copied

LATEST

Hi YellowCoat

Did you even solve this issue. This is EXACTLY what I need to do for a project but I can not find any way to do it. I thought I could do it with JavaScript task but I'd love to know how to do this if you or someone has a solution.

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