Skip to main content
Participating Frequently
January 23, 2024
Answered

Script to position an object on a page

  • January 23, 2024
  • 1 reply
  • 1181 views

When I paste an object on a page I need to reposition it to get to an exact X and Y position. I am doing this manually on a few hundred pages because the pasted object never falls in the right position, and to alter the X and Y each time is very time consuming.

Is there a scripting solution that will allow me to click on the object and run the script so that it positions the object to the desired X/Y coordinates? I cannot find one that has already been written.  In summary, I want to click on the object and then run a script that positions it at  X = 105.75mm and Y = 76.754mm. Can anyone help please? 

This topic has been closed for replies.
Correct answer Peter Kahrel
app.selection[0].move (['105.75mm', '76.754mm']);

A better solution would be to create an object style and make it the default style for graphics (or text, whichever your pasted objects are). In the object style you set the location, and on pasting the object should be placed correctly.

 

It would be even easier if there's an alyernative to pasting the object, such as duplicating it.

1 reply

Peter Kahrel
Community Expert
Peter KahrelCommunity ExpertCorrect answer
Community Expert
January 23, 2024
app.selection[0].move (['105.75mm', '76.754mm']);

A better solution would be to create an object style and make it the default style for graphics (or text, whichever your pasted objects are). In the object style you set the location, and on pasting the object should be placed correctly.

 

It would be even easier if there's an alyernative to pasting the object, such as duplicating it.

Participating Frequently
January 23, 2024

Thanks very much, Peter. I still need to learn about object styles, but you short script worked fine once I changed the co-ordinates a bit. I have an A4 page and paste one object into the top half, and one into the bottom half. When I paste them the top one 'lands' at 54.623mm (X) and 76.026mm(Y). I adapted your script to ['27.036', '7.886mm'] and the object moves to just where it should be (i.e. 105.75mm(X) and 76.754mm(Y)).

When I paste  the bottom one it 'lands' at 54.623mm (X) and 209.376mm(Y). I adapted your script this time to ['27.036', '152.264mm'] and the object moves to just where it should be (i.e. 105.75mm(X) and 221.132mm(Y)).

I run these as two seperate scripts depending upon whether I'm dealing with the top object or the bottom object, and it all works exactly right. So thanks again for showing me the way to do this.

 

Participating Frequently
January 23, 2024

I made a mistake when I typed the co-ordinates. The object in the top half  'lands' at 54.623mm (X) and 71.126mm(Y). I adapted your script to ['27.036', '7.886mm'] and the object moves to just where it should be (i.e. 105.75mm(X) and 76.754mm(Y)).

When I paste  the bottom one it 'lands' at 54.623mm (X) and 189.659mm(Y). I adapted your script this time to ['27.036', '152.264mm'] and the object moves to just where it should be (i.e. 105.75mm(X) and 221.132mm(Y)).

I must admit I cannot find the relationship to calculate the numbers (it was all done my trial and error until I got the 'new' coordinates to move the object to the right position. Anyway, thanks again!

I run these as two seperate scripts depending upon whether I'm dealing with the top object or the bottom object, and it all works exactly right. So thanks again for showing me the way to do this.