• 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

484

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 , 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 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

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
Community Expert ,
Sep 18, 2024 Sep 18, 2024

Copy link to clipboard

Copied

@lesliek83377343

 

Where is your (0,0) point? 

 

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
Participant ,
Sep 18, 2024 Sep 18, 2024

Copy link to clipboard

Copied

Hi,

 

Thank you for the post! I am often finding the need to move text frames on a long document where the margins have been changed or the document wasn't setup properly to begin with (i.e. the master pages) 

 

I note a relevant post elsewhere on the forum: How to reposition linked text frames?

 

quote
 app.selection[0].move (['105.75mm', '76.754mm']);

 

 

 

What would the script be if I wanted to move frames in position [x1, y1] to [x2, y2] AND frames in position [x3, y3] to [x4, y4]?

 

For example, condsider a book document where all the frames are out of position -- the verso frames need to be treated in one way and the recto frames in another.

quote

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.

 

I cannot see "location" in the object styles ... is this a feature available in newer versions of InDesign?

The following image shows the Object Styles dialogue in my version.

 

A2D2_0-1726659467596.png

 

I am using CS6 (InDesign 8.0), Windows 11

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 Expert ,
Sep 18, 2024 Sep 18, 2024

Copy link to clipboard

Copied

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
Participant ,
Sep 18, 2024 Sep 18, 2024

Copy link to clipboard

Copied

Thank you @Robert at ID-Tasker , from the screen shot in the article it appears older versions of InDesign do not have the "Size and Position Options" within the Object Style settings.

 

If Size and Position Options can be selected then presumably they could be manipulated through an object find/replace also.

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 Expert ,
Sep 18, 2024 Sep 18, 2024

Copy link to clipboard

Copied

LATEST

@A2D2

 

As you work on a PC - I would suggest CS6 version of my ID-Tasker tool - not free but if you have a lot of mundane clicking to do every day... 

 

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