Skip to main content
Participating Frequently
Sep 5, 2015 9:51 PM UTC
Answered

create rectangles in ilustrator using dimensions from csv

I'm looking for a script that will create various box sizes from dimensions stored in a csv file.

I've found a reoccuring thread when using a PC and VBA but i am using a MAC so am looking for a .jsx solution.


Can anyone help please?

This topic is closed to new replies. Start a new post to keep the conversation going.
pixxxelschubser
pixxxelschubserCorrect answer
Community Expert
Sep 9, 2015 4:27 AM UTC

Hi, pixxxel schubser‌ that's fantastic, thank you so much.

Apologies for the missing answers, the Illustrator version is CC, and the data is coming from an excel document that i am populating from internal data.

Just one last question, could each box now be filled with a different colour ? your original example showed the path being filled with Red, but ifi wanted to fill each rectangle with a different colour, is this possible ?


Many thanks,


Ouch!

There are so much ways to do this. But You need many "secure question" in the script - e.g. it is dependent of color mode, or swatches exists, or the installed language of Illustrator and so on …

Here is one "simple way" to work with three additional RGB color values columns in your txt file. Be sure that the color mode of your document is RGB.

// rectangleDraw_dataFromTxt.jsx

// regards pixxxelschubser

var aDoc = app.activeDocument;

var mm = 2.8346456;

// required: tab separated txt and opened RGB document in Illustrator (CS5+)

// see https://forums.adobe.com/message/7934424#7934424

// top    left    width    height    R    G    B

// 20    20    100    100    255    0    0

var aFile = File ("~/Desktop/Testdateien/topleftwidthheight.txt");

aFile.open("r");

var txtFile = aFile.read();

aFile.close();

var theText = txtFile.split("\n");

var T, rect, col;

var col = new RGBColor();

for (i=0; i<theText.length-1; i++) {

T=theText.split( "\t");

$.writeln(T[4]);

rect = aDoc.pathItems.rectangle( -(T[0] * mm), T[1] * mm, T[2] * mm, T[3] * mm );

col.red = T[4];

col.green = T[5];

col.blue = T[6];

rect.fillColor = col;

}

Have fun

15 replies

abspeedAuthor
Participating Frequently
Sep 6, 2015 7:40 AM UTC

Hi pixxxel schubser Great thanks, I must admit I tried it yesterday, but didn;t put the txt file in a folder on the desktop !!

So I have this working now, as a single element.

How would the code evolve if i wanted to create 5 boxes from one set of coordinates ?

All the best

Translate
pixxxelschubser
Community Expert
Community Expert
Sep 6, 2015 9:12 AM UTC

allan bendall schrieb:

… How would the code evolve if i wanted to create 5 boxes from one set of coordinates ? …

Sorry? I don't understand. Why you want to create 5 boxes at the same position? The better way could be: create one box and duplicate it.

Otherwise:

At first show us (or upload) your example csv file, please.

The script always depends on it.

Here is an example for more sets of elements in a csv and with an open dialog (written by Muppet Mark):

Re: Importing Color to Swatch Library from Text File

Have fun

Translate
abspeedAuthor
Participating Frequently
Sep 6, 2015 9:22 AM UTC

I'm trying to create something like this, where each box has a different colour and a different start point, but all controlled from a csv / script environment.

sample image below.


Cheers

Translate
pixxxelschubser
Community Expert
Community Expert
Sep 6, 2015 4:44 AM UTC

Hi allan bendall

to create a shape with jsx from external file:

Re: Excel data to construct illustrator object

to fill the shapes with jsx from external file:

FILLING FORMS FROM A FILE CSV / EXCEL

Have fun

Translate