Copy link to clipboard
Copied
Hi,
I was wondering if anyone could help me write a Adobe Illustrator script.
The script must be able to:
1. Read a file containing several coordinates (X,Y) and angles.
2. Select an image (or load an image).
3. Copy and paste an image to the coordinates and rotate the images by the given angles.
4. Repeat pasting/rotating until all coordinates are pasted with images.
The result should be something like the image attached below.
Can this be possible with an illustrator script?
Could anyone guide me how I should approach this?
Could you recommend any online references on programming an illustrator script?
I don't always have access to Illustrator.
Many thanks in advance,
Anthony

Copy link to clipboard
Copied
it is possible, are you familiar with Illustrator? with Javascript? or other programming language?
Copy link to clipboard
Copied
Hi Carlos,
I have a bit of programming background. I'm familiar with VB, C, C++. I'm a novice on illustrator.
I attempted at writing quick "copy, paste & rotate" script in javascript, see below. But I need to somehow get the coordinates from another file (a text file).
Can I use something like this on the Illustrator script?
http://www.javapractices.com/topic/TopicAction.do?Id=42
---
var selectedObjects = app.activeDocument.selection; var topObject = app.activeDocument.selection[0];
var msgType = "";
if (app.documents.length>0)
{
myselection = app.activeDocument.selection;
if (myselection.length>0)
{
for (var i=0; i<myselection.length; i++) {
myselection.duplicate()
myselection.translate(200,0)
myselection.rotate(13)
myselection.duplicate()
myselection.translate(300,50)
myselection.rotate(50)
myselection.duplicate()
myselection.translate(600,10)
myselection.rotate(45)
}
}
Copy link to clipboard
Copied
Can I use something like this on the Illustrator script?
no, Java is not the same as Javascript, there's a function that Mark wrote to parse a CSV file here
http://forums.adobe.com/thread/676299?tstart=-1
the result is an array of array (your x,y,angle) values read from your file, you can get the values you hardcoded from there (fileArray).
post back if you get stuck.
Copy link to clipboard
Copied
Thanks Carlos,
I can now read a csv file and get values, which is great! Thanks heaps.
But duplicate, translate & rotate aren't quite doing what I want them to do.
I'm trying to understand how duplicate, translate and rotate methods work.
Duplicate seems to make a copy of the selected object and leaves a copy in the original location.
The original selected object becomes translated and rotated.
The next 'translate & rotate' happens from the new location, not from the original location.
I would like the original selection to stay in its original position, and copied items are translated and rotated, to X,Y coordinates relative to the original position.
Can this be possible with .duplicate/translate/rotate methods? Is there a better way to use the methods?
I also want the unit to be in "mm". UnitValue() seem to be the tool to use. Does it work with .translate?
--- (test.csv)
30,20,10
80,20,20
100,20,30
140,20,40
---- (Myscript.js)
var csvFile = File.openDialog("Choose a CSV file");
function readInCSV(fileObj) {
var fileArray = new Array();
fileObj.open('r');
while(!fileObj.eof) {
var thisLine = fileObj.readln();
var csvArray = thisLine.split(',');
fileArray.push(csvArray);
}
fileObj.close();
return fileArray;
}
if (csvFile.exists) {
var fileArray = readInCSV(csvFile);
}
var myselection = app.activeDocument.selection;
for (var i=0; i<fileArray.length; i++)
{
myselection[0].duplicate();
myselection[0].translate(fileArray[0],fileArray[1]);
myselection[0].rotate(fileArray[2]);
}
----
The result looks like this (not what I want):

Copy link to clipboard
Copied
To move the copy do…
var myDupe = myselection[0].duplicate();
myDupe.translate(fileArray[0],fileArray[1]);
myDupe.rotate(fileArray[2]);
I don't really like the use of selection it's not needed just target what you want…
var myImage = app.activeDocument.placedItems[0];
or something to that effect… Why is the result not what you want? And just use math to get mm value*2.834654
Copy link to clipboard
Copied
Thanks so much.
It works! ![]()
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more