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 !
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
...
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.
Copy link to clipboard
Copied
Thank you for the answer. I will give more details.
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)
Thanks for your help !
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:
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).
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.
Copy link to clipboard
Copied
Yes that's it.
We could also add positioning information in the CSV file.
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:
Make sure the template document is open and frontmost in AI before running the script.
Please DM if you require any additional work.
Copy link to clipboard
Copied
Thak you very much!
I will try this