In the code below the object of the chamber "Cameron Right" shifts vertically but does not center on the artboart. What's wrong ?
// Get the active document
var doc = app.activeDocument;
// Get the "Cameron Direito" layer
var layer = doc.layers.getByName("Cameron Direito");
// Get the first item in the layer
var item = layer.pageItems;
// Get the bounds of the artboard
var artboardBounds = doc.artboards.artboardRect;
// Calculate the center of the artboard
var centerY = (artboardBounds - artboardBounds) / 2 + artboardBounds;
// Position the item at the center of the artboard
item.position = [item.position, centerY];
In the code below the object of the layer "Cameron Direito" shifts vertically but does not center on the artboart. What's wrong with you?
... What's wrong with you?
By @Julio Ricardo
That seems to be a translation issue - right?
And the answer is:
Nothing is wrong with your code. Your snippet works as expected.
Unforturnately you forgot to calculate the middle of your item. "Position" always set/get the top left coordinate.
Could you show me ?
Replace the last line of your code with:
item.position = [item.position, centerY+item.height/2];
Hello @Julio Ricardo,
Thanks for reaching out. I hope the suggestions shared by pixxxelschubser helped resolve the trouble you were having with your script. Feel free to reach out if you have more questions or need assistance. We'd be happy to help.
Thank you so much !