Skip to main content
Participating Frequently
September 5, 2015
Answered

create rectangles in ilustrator using dimensions from csv

  • September 5, 2015
  • 2 replies
  • 2685 views

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 has been closed for replies.
Correct answer pixxxelschubser

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

2 replies

abspeedAuthor
Participating Frequently
September 6, 2015

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

pixxxelschubser
Community Expert
Community Expert
September 6, 2015

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

abspeedAuthor
Participating Frequently
September 6, 2015

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

pixxxelschubser
Community Expert
Community Expert
September 6, 2015

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