Skip to main content
Inspiring
March 21, 2023
Answered

Moving a group with ExtendScript

Hello, everyone,

I am using ExtendScript to move groups of objects into certain locations on an Illustrator art board. It had been working up until now, when I had to change the positions. Now when I try to run the script, the positions of the objects are off by about 1.417 points.

I have an action in Illustrator that sets the origin point to the top left corner, and then runs the javaScript. Here is the code:

 

app.activeDocument.artboards[0].rulerOrigin = [0,0];
var alpha = app.activeDocument.layers.getByName('Layer 2').groupItems[0];
alpha.position = [0, 0]; 
//This puts the top left corner of the group at the location x = 1.4173 pt, y = 1.4173 pt.
 
Can anyone help me figure out what I am doing incorrectly?
 
Thanks!
 
 
This topic is closed to new replies. Start a new post to keep the conversation going.
CarlosCanto
CarlosCantoCorrect answer
Community Expert
March 21, 2023

it looks like 1.41, 1.41 is where the 0,0 is. How's the Action setting the Ruler?

 

The issue with pageOrigin and rulerOrigin is that those are "relative" positions, they depend on the the size of the document, the 0,0 position and/or the coordinate system.

 

Use the ArtboardRect instead, that will give you the left/top coordinate regardless of the other variables.

var r = app.activeDocument.artboards[0].artboardRect;
var left = r[0];
var top = r[1];

var alpha = app.activeDocument.layers.getByName('Layer 2').groupItems[0];
alpha.position = [left, top]; 

2 replies

CarlosCanto
Community Expert
CarlosCantoCommunity ExpertCorrect answer
Community Expert
March 21, 2023

it looks like 1.41, 1.41 is where the 0,0 is. How's the Action setting the Ruler?

 

The issue with pageOrigin and rulerOrigin is that those are "relative" positions, they depend on the the size of the document, the 0,0 position and/or the coordinate system.

 

Use the ArtboardRect instead, that will give you the left/top coordinate regardless of the other variables.

var r = app.activeDocument.artboards[0].artboardRect;
var left = r[0];
var top = r[1];

var alpha = app.activeDocument.layers.getByName('Layer 2').groupItems[0];
alpha.position = [left, top]; 
Translate
Inspiring
March 21, 2023

Thanks, CarlosCanto, that did the trick. I was having the origin point set by the extendScript, but the selected object's reference point changed to the upper left corner.

 

Thanks, again!

Translate