Copy link to clipboard
Copied
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?
1 Correct answer
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 op
Explore related tutorials & articles
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Which Illustrator version do you use?
Do you have an example CSV file with data for us?
How are your scripting experience?
Independently of:
Could it be better (perhaps) for you to work with several Ai-Templates?
Copy link to clipboard
Copied
Hi, I've paste the text below, which gives you an idea of the coordinates i want to script,
The csv can be set up in what ever format it needs to be, but taking the screen shots previously i have pulled this together as an example.
I'm using Illustrator CC2014, and by scripting experience is zero !
The idea is to have rectangle coordinates / sizes in from a csv and create multiple vectors from it.
The example below takes the visual in the previous post, and hopefully explains the size / shape required.
Ive added the x y ad the start finish which i know will not be required for the text file, but to explain the coordinates i thought it would be useful.
Many thanks for the support here!
x | y | |||
start | 20 | 20 | Cyan | |
120 | 20 | Cyan | ||
120 | 120 | Cyan | ||
20 | 120 | Cyan | ||
finish | 20 | 20 | Cyan | |
start | 150 | 50 | Yellow | |
190 | 150 | Yellow | ||
190 | 220 | Yellow | ||
150 | 120 | Yellow | ||
finish | 150 | 50 | Yellow | |
start | 30 | 150 | Magenta | |
105 | 30 | Magenta | ||
105 | 50 | Magenta | ||
30 | 170 | Magenta | ||
finish | 30 | 150 | Magenta | |
start | 20 | 250 | Black | |
40 | 20 | Black | ||
40 | 40 | Black | ||
20 | 270 | Black | ||
finish | 20 | 250 | Black | |
start | 20 | 250 | Red | |
40 | 20 | Red | ||
40 | 40 | Red | ||
20 | 270 | Red | ||
finish | 20 | 250 | Red |
Copy link to clipboard
Copied
You don't need 5 pairs for a rectangle. Only 4 pairs if you draw with pathpoint pairs.
var newShape.setEntirePath([[p1X, p1Y], [p2X, p2Y], [p3X, p3Y], [p4X, p4Y]]);
newShape.closed = true;
But finally you dont need pathpoint pairs for a rectangle. Only the top left coordinate and in addition the width and the height.
var rect = aDococ.pathItems.rectangle(top, left, width, height );
You want to draw only rectangles?
Where the coordinates come from?
Copy link to clipboard
Copied
OK, so the top, left, width and height dimensions come from the .txt file. topleftwidthheight.txt
column a - top
column b - position from left
column c - x dimension
column d - y dimension
how would this get inserted into your original script ?
many thanks again
Copy link to clipboard
Copied
Why you doesn't answer my questions about your Illustrator version and your scripting knowledge base and where the data in your txt file comes from?
But anyway:
this should do the job based on the data in your posting #8
// rectangleDraw_dataFromTxt.jsx
// regards pixxxelschubser
var aDoc = app.activeDocument;
var mm = 2.8346456;
// required: tab separated txt and opened document in Illustrator (CS5+)
// see https://forums.adobe.com/message/7934424#7934424
// post #8
var aFile = File ("~/Desktop/Testdateien/topleftwidthheight.txt");
aFile.open("r");
var txtFile = aFile.read();
aFile.close();
var theText = txtFile.split("\n");
var T;
for (i=0; i<theText.length-1; i++) {
T=theText.split( "\t");
aDoc.pathItems.rectangle( -(T[0] * mm), T[1] * mm, T[2] * mm, T[3] * mm );
}
Have fun
Copy link to clipboard
Copied
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,
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Hi, pixxxel schubser That's spot on, thank you very much.
Copy link to clipboard
Copied
Hi there!
Could you also plese help me?
eg i have table in newest exel like this, and i wanna made ractangle (just normal one) in newest illustrator. I tried to use this code and modife it, but it still show some error 😞
Copy link to clipboard
Copied
Bonjour,
// JavaScript Document
var aDoc = app.activeDocument;
var mm = 2.8346456;
// required: tab separated txt
// width tab height
// 100 tab 50
var aFile = File ("~/Desktop/widthheight.csv");
aFile.open("r");
var txtFile = aFile.read();
aFile.close();
var theText = txtFile.split("\n");
var T, rect;
var col = new RGBColor();
for (i = 0; i < theText.length-1; i++) {
T = theText[i].split( "\t");
rect = aDoc.pathItems.rectangle( 0, 0, T[0] * mm, T[1] * mm );
rect.filled = false;
rect.stroked = true;
rect.strokeWidth = 2;
}
Copy link to clipboard
Copied
Hi, now i have this error 😞

