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

Script to position an object on a page

Community Beginner ,
Jan 23, 2024 Jan 23, 2024

Copy link to clipboard

Copied

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? 

TOPICS
Scripting

Views

166

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 2 Correct answers

Community Expert , Jan 23, 2024 Jan 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.

Votes

Translate

Translate
Community Beginner , Jan 23, 2024 Jan 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 relat

...

Votes

Translate

Translate
Community Expert ,
Jan 23, 2024 Jan 23, 2024

Copy link to clipboard

Copied

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.

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
Community Beginner ,
Jan 23, 2024 Jan 23, 2024

Copy link to clipboard

Copied

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.

 

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
Community Beginner ,
Jan 23, 2024 Jan 23, 2024

Copy link to clipboard

Copied

LATEST

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.

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