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

Moving a group with ExtendScript

Explorer ,
Mar 21, 2023 Mar 21, 2023

Copy link to clipboard

Copied

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!
 
 
TOPICS
Scripting

Views

356

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

Community Expert , Mar 21, 2023 Mar 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.getByN
...

Votes

Translate

Translate
Adobe
Community Expert ,
Mar 21, 2023 Mar 21, 2023

Copy link to clipboard

Copied

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

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 ,
Mar 21, 2023 Mar 21, 2023

Copy link to clipboard

Copied

LATEST

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!

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