Copy link to clipboard
Copied
Hello, everyone,
I am trying to write JavaScript that will take a selected group in an active Illustrator document and move it to a particular X/Y position on the artboard.
I have tried using the .position() method, but this doesn't seem to do anything. I have also tried running an existing Illustrator action to reposition the art using .doScript(), but this either doesn't do anything or crashes Illustrator.
Hi,
Try following
var _group = app.activeDocument.layers['Layer 2'].groupItems[0];
_group.position = [0,0];
You need to access the group inside the Layer. In your code, alpha is a layer not group inside the Layer 2. Therefore it does not work.
Copy link to clipboard
Copied
Hi,
You said you would like reposition group, but you are trying to move Layer 2.
What excatly you want to reposition, selected items? Could you post the screenshot and specify what items you want to position. Attaching ai file will also be helpful
Copy link to clipboard
Copied
Hello,
What I would like to do is have the JavaScript take the group item which is on a specified layer and move it on the artboard to a specific xy location.
In the test .ai file I have attached, I would like to take the group item in Layer 2 and move the group to the upper left corner in the document on the same layer.
The screenshot shows the group item at the bottom of the screen of the yellow star. I would like to move this whole group to the upper left corner into position on the document.
I am guessing that my code is trying to move the layer in the palette rather than the items on the layer.
Copy link to clipboard
Copied
Hello,
I am trying to use JavaScript to move a selected group on a specified layer to a particular location on the same layer. In the screenshot and PDF that are attached, I would like to move the group with the yellow star up to the upper-left part of the document.
I tried using .position = [x, y], but it doesn't seem to do anything. It doesn't throw an error, though. I also tried to have the script run an Illustrator action to do the same thing, .doScript(action, set name), but it gives an error saying that it is not a function.
Copy link to clipboard
Copied
Hi,
Try following
var _group = app.activeDocument.layers['Layer 2'].groupItems[0];
_group.position = [0,0];
You need to access the group inside the Layer. In your code, alpha is a layer not group inside the Layer 2. Therefore it does not work.
Copy link to clipboard
Copied
That worked. Thanks for your help and your explanation!
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more