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

How to create shape from variable data

Explorer ,
Oct 21, 2021 Oct 21, 2021

Copy link to clipboard

Copied

Hello Community !

 

I would like to create square/shape from variable data (CSV).

(Colone 1: Height / Colone 2: Width)

Do you know if this is possible ? One shape per file/several ?

I can't find anything anywhere...

 

Thanks for your help !

TOPICS
Scripting , SDK , Tools

Views

762

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

correct answers 1 Correct answer

Engaged , Oct 26, 2021 Oct 26, 2021

Basic script to read your comma-separated text file and generate box artworks from your AI template (base file):

var csvFile = File.openDialog('Choose CSV file:')
var outDir = Folder.selectDialog('Choose output folder:')

if (!csvFile.open("r")) { throw "Cannot read CSV file" }
var lines = csvFile.read().split(/[\r\n]+/g)
csvFile.close()


function mmToPt(n) {
	return n / 25.4 * 72
}

var doc = app.activeDocument // template file must be open and frontmost in AI


for (var i = 1; i < lines.length
...

Votes

Translate

Translate
Adobe
Engaged ,
Oct 22, 2021 Oct 22, 2021

Copy link to clipboard

Copied

It is certainly doable via scripting. It will help if you can post an example of the CSV data you’re using and a mockup of the artwork you wish generated from it. That will allow folks here to gauge the requirements and complexity of the job, request any additional details, and offer code or quotes as appropriate.

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 ,
Oct 22, 2021 Oct 22, 2021

Copy link to clipboard

Copied

Thank you for the answer. I will give more details.

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 ,
Oct 22, 2021 Oct 22, 2021

Copy link to clipboard

Copied

Here is a example of the CSV file and the illustrator file.

I would like to know if it is possible from data to modify shape. Can be even modify the positioning (x y)

 

DATA-Square.png

 

Thanks for your help !

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 ,
Oct 22, 2021 Oct 22, 2021

Copy link to clipboard

Copied

an important piece of data is missing here. we need the position of the squares. To draw a rectangle programmatically, you need the following:

  • x coordinate
  • y coordinate
  • width
  • height

you've only provided width/height and a label.

 

it could, however, be possible to work without this position information by just creating a group with a square and a label, and then centering it on the artboard afterword (or potentially distributing multiple groups as shown in your example).

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
Engaged ,
Oct 22, 2021 Oct 22, 2021

Copy link to clipboard

Copied

I’m guessing “BASE FILE” is a template file containing two existing rectangles, from which all of the generated files are derived. For each line of the CSV, the rectangles should be resized (remaining centered on their original position) and the document saved under a new file name. OP can confirm/correct this as appropriate.

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 ,
Oct 22, 2021 Oct 22, 2021

Copy link to clipboard

Copied

Yes that's it. 

We could also add positioning information in the CSV file. 

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
Engaged ,
Oct 26, 2021 Oct 26, 2021

Copy link to clipboard

Copied

Basic script to read your comma-separated text file and generate box artworks from your AI template (base file):

var csvFile = File.openDialog('Choose CSV file:')
var outDir = Folder.selectDialog('Choose output folder:')

if (!csvFile.open("r")) { throw "Cannot read CSV file" }
var lines = csvFile.read().split(/[\r\n]+/g)
csvFile.close()


function mmToPt(n) {
	return n / 25.4 * 72
}

var doc = app.activeDocument // template file must be open and frontmost in AI


for (var i = 1; i < lines.length; i++) { // skip first row (headings)
    var line = lines[i].split(',') // use split('\t') if tab-delimited
    var filename = line[0], boxes = []
    for (var j = 1; j <= 2; j++) {
        var c = j * 3 - 2
        var label = line[c], nw = mmToPt(line[c+1]), nh = mmToPt(line[c+2])
        doc.textFrames.getByName('{file name}').contents = filename
        doc.textFrames.getByName('{label ' + j + '}').contents = label
        var box = doc.pathItems.getByName('{box ' + j + '}')
        var position = box.position
        var ow = box.width
        var oh = box.height
        box.position = [position[0] - (nw - ow) / 2, position[1] + (nh - oh) / 2]
        box.width = nw
        box.height = nh
        doc.saveAs(new File(outDir + '/' + filename + '.ai'))
    }
}

 

Label the text frames and paths in your template file so the script can identify them:

Screenshot 2021-10-26 at 08.11.50.png

 

Make sure the template document is open and frontmost in AI before running the script.

Please DM if you require any additional work.

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 ,
Oct 26, 2021 Oct 26, 2021

Copy link to clipboard

Copied

LATEST

Thak you very much!

I will try this

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