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

create rectangles in ilustrator using dimensions from csv

New Here ,
Sep 05, 2015 Sep 05, 2015

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?

TOPICS
Scripting

Views

2.1K
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

correct answers 1 Correct answer

Community Expert , Sep 08, 2015 Sep 08, 2015

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

...

Votes

Translate
Adobe
Community Expert ,
Sep 05, 2015 Sep 05, 2015

Copy link to clipboard

Copied

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

Votes

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 ,
Sep 06, 2015 Sep 06, 2015

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

Votes

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 ,
Sep 06, 2015 Sep 06, 2015

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

Votes

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 ,
Sep 06, 2015 Sep 06, 2015

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

Screen Shot 2015-09-06 at 10.18.23.png

Votes

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 ,
Sep 06, 2015 Sep 06, 2015

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?

Votes

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 ,
Sep 06, 2015 Sep 06, 2015

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!

xy
start2020Cyan
12020Cyan
120120Cyan
20120Cyan
finish2020Cyan
start15050Yellow
190150Yellow
190220Yellow
150120Yellow
finish15050Yellow
start30150Magenta
10530Magenta
10550Magenta
30170Magenta
finish30150Magenta
start20250Black
4020Black
4040Black
20270Black
finish20250Black
start20250Red
4020Red
4040Red
20270Red
finish20250Red

Votes

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 ,
Sep 07, 2015 Sep 07, 2015

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?

Votes

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 ,
Sep 07, 2015 Sep 07, 2015

Copy link to clipboard

Copied

OK, so the top, left, width and height dimensions come from the .txt file. topleftwidthheight.txt

table.jpg

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

Votes

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 ,
Sep 07, 2015 Sep 07, 2015

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

Votes

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 ,
Sep 07, 2015 Sep 07, 2015

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,

Votes

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 ,
Sep 08, 2015 Sep 08, 2015

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

Votes

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 ,
Sep 08, 2015 Sep 08, 2015

Copy link to clipboard

Copied

Hi, pixxxel schubser That's spot on, thank you very much.

Votes

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 Beginner ,
Nov 22, 2024 Nov 22, 2024

Copy link to clipboard

Copied

Hi there!

 

Could you also plese help me?

Katarzyna29637567ss53_0-1732285991842.pngexpand image

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 😞 

Votes

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
Advocate ,
Nov 22, 2024 Nov 22, 2024

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;
      }

Votes

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 Beginner ,
Nov 24, 2024 Nov 24, 2024

Copy link to clipboard

Copied

LATEST

Katarzyna29637567ss53_0-1732518667075.pngexpand image

Hi, now i have this error 😞 

Votes

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