Skip to main content
rcraighead
Legend
January 17, 2019
Answered

move selection to XY coordinate?

  • January 17, 2019
  • 2 replies
  • 4587 views

I want to move the current selection or better yet, paste the clipboard item to a pre-defined X,Y coordinate. I am able to pull the coordinate variables from a text object within the file but I don't know how to write the javascript to "move" the object into place.

I found this script in the InDesign forum. Can I tweak it to work in AI? Running it as-is returns an error: "illegal argument - argument 1".

var s=app.activeDocument.selection[0];   

s.move([-.25,-.25]) 

Here is a sample file: Dropbox - Align_Sample.ai

I want to paste other "fingerprints" to the coordinates listed in the file. I know I'll need to convert the coordinates to points. I can do that although I may not know the best method.

Thanks for any help!

This topic has been closed for replies.
Correct answer pixxxelschubser

rcraighead  schrieb

… but I don't know how to write the javascript to "move" the object …

To answer this scripting question:

1) using translate: move x + 100pt, move y -100pt

var aDoc = app.activeDocument;

aDoc.selection[0].translate(100,-100);

or

2) using pathItem.position: move x + 100pt, move y -100pt

var aDoc = app.activeDocument;

var aSel = aDoc.selection[0];

var SelBounds = aSel.geometricBounds;

aSel.position = new Array( SelBounds[0]+100, SelBounds[1]-100 );

Have fun

2 replies

pixxxelschubser
Community Expert
pixxxelschubserCommunity ExpertCorrect answer
Community Expert
January 20, 2019

rcraighead  schrieb

… but I don't know how to write the javascript to "move" the object …

To answer this scripting question:

1) using translate: move x + 100pt, move y -100pt

var aDoc = app.activeDocument;

aDoc.selection[0].translate(100,-100);

or

2) using pathItem.position: move x + 100pt, move y -100pt

var aDoc = app.activeDocument;

var aSel = aDoc.selection[0];

var SelBounds = aSel.geometricBounds;

aSel.position = new Array( SelBounds[0]+100, SelBounds[1]-100 );

Have fun

pixxxelschubser
Community Expert
Community Expert
January 17, 2019

Why so complicated?

At first: the positions are not plausible. You should recreate your file.

Second: use some effects to do what you want. (see the attached link --> Dropbox - Align_Sample_effect.ai  ). You only need one motiv.

All what you have to do in future is: remove the (old) fingerprint and add a new one in the same group. The effects will complete automatically your file.

If that is what you want - have fun.

If you still need a script, please contact us again.

rcraighead
Legend
January 17, 2019

At first: the positions are not plausible. You should recreate your file.

This may be because the "Reference Point" is not set to "Centered".

Second: use some effects to do what you want

That was my first thought, but relative coordinate are not always equally spaced. This is to accommodate for laser angle and other imperfections in the production process.

You HAVE provided some food for thought though. Maybe I can create an effect that would reposition the fingerprint or inscription to the correct location. We have about 60 templates with unique coordinates. That'll be a bit of work.

Thank you!

Note: The blue ellipses are currently being used to align elements by using "Align to Key Object".

pixxxelschubser
Community Expert
Community Expert
January 17, 2019

Is this really correct?

0.1 mm is a very long distance (or tolerance? for a laser)