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

Simple script to move selected anchor point(s) by set amount

Community Beginner ,
Aug 19, 2018 Aug 19, 2018

Copy link to clipboard

Copied

Hello all, I've tried my best to find an existing script that I could modify for this with no luck. I want to be able to move a selected anchor point or points by a set amount, for example on the example below I want to shift those two anchor points 3mm to the right and 2mm up. I thought this was so simple I'd be able to find a script for it already made but no luck. I know enough about scripts to modify them but not to make from scratch.

2018-08-20_094438.jpg

Not very scripting related but the long story behind why I want this script is that I'm doing some isometric drawings of 3D shapes and so want to speed up shifting elements on the page. Ideally I suppose I should learn a 3D program but using InDesign is soooo much more comfortable!

TOPICS
Scripting

Views

2.1K

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 , Aug 20, 2018 Aug 20, 2018

Hi Steve,

you say "selected anchor point(s)", but I think you mean selected path points.

A single path point can be reached by its path.

If an object is selected like the one you are showing:

var pathPoints = app.selection[0].paths[0].pathPoints.everyItem().getElements();

Now you have all path points of the first path of that selected object stored in an array.

FWIW: An object could be constructed of one or more paths.

To get the ones you selected is difficult, because scripting does know nothing about

...

Votes

Translate

Translate
Community Expert ,
Aug 20, 2018 Aug 20, 2018

Copy link to clipboard

Copied

Hi Steve,

you say "selected anchor point(s)", but I think you mean selected path points.

A single path point can be reached by its path.

If an object is selected like the one you are showing:

var pathPoints = app.selection[0].paths[0].pathPoints.everyItem().getElements();

Now you have all path points of the first path of that selected object stored in an array.

FWIW: An object could be constructed of one or more paths.

To get the ones you selected is difficult, because scripting does know nothing about your selection on path points!

A big omission in the document object model.

You could test for their position and if the rule is move the ones that are right-most you could sort or compare x/y values that are present in property anchor of pathPoint. Or one could use the menu command for cut that is available by scripting and you compare the ones left by their anchor values to the ones that were before to single out the ones selected. After an undo of cut you can work with the ones you identified by their index.

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#PathPoint.html

Bottom line: There is no "simple script" to move selected path points.

Regards,
Uwe

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 ,
Aug 20, 2018 Aug 20, 2018

Copy link to clipboard

Copied

Hello Uwe

Many thanks for your response, I think I understand why what I thought would be simple is in fact not!

Taking another approach, can scripting be used to add or subtract values in the toolbar? See below the X & Y coordinates, could a script be written to add 3mm to X and 2mm to Y?

2018-08-21_073552.jpg

At the moment I place my cursor in the X box and type "+3mm" tab to the next box, right arrow to deselect, type "+2mm" then enter

Thanks again, Steve.

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 ,
Aug 20, 2018 Aug 20, 2018

Copy link to clipboard

Copied

steveh10657863  wrote

… can scripting be used to add or subtract values in the toolbar?

Hi Steve,

I don't think so.

Regards,
Uwe

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 ,
Aug 20, 2018 Aug 20, 2018

Copy link to clipboard

Copied

Thanks Uwe

OK last ditch approach! "Transform Sequence Again" can do what I want but only on the last two values used. Can  scripting insert values into InDesign's "memory" so performing "Transform Sequence Again" would make a move based on those values?

Many thanks, Steve.

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 ,
Aug 20, 2018 Aug 20, 2018

Copy link to clipboard

Copied

Sorry. Same answer, I think. And that is: No.

FWIW: If you manage to do a couple of actions that any of the transform menu items can do again, you could invoke the menu items by script.

Regards,
Uwe

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 ,
Aug 20, 2018 Aug 20, 2018

Copy link to clipboard

Copied

P.S. A way to do this would be to make a script to make an object, move it X 2mm and Y 3mm, then delete it. Then running "Transform Sequence Again" makes that same move. However it doesn't work too well because Transform Again doesn't move just the selected anchor points, it moves the whole object. Would still be useful though.

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 ,
Aug 20, 2018 Aug 20, 2018

Copy link to clipboard

Copied

Sorry, this also will not work.

Unless you find a way to move an object solely by using the menu commands and then use a script to use another menu command with transform.

Regards,
Uwe

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 ,
Aug 20, 2018 Aug 20, 2018

Copy link to clipboard

Copied

Sorry I don't know exactly what you mean by solely using menu commands, would Object -> Transform -> Move -> Horizontal: 3mm, Vertical: -2mm work?

Many thanks, Steve.

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
Guide ,
Aug 21, 2018 Aug 21, 2018

Copy link to clipboard

Copied

Hi,

Even if some surname me "M. 1-Click", just change the H/V increments in the ID general prefs. to '1mm" and use the "arrow" keyboards!

"3" clicks to the top, "2" clicks on the left!

Of course, you could select now others paths points and play 4 up / 3 right! …

Simple and quick! … The only true difficulty: … be able to count here until 4! 

Best,

Michel, for FRIdNGE

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 ,
Aug 21, 2018 Aug 21, 2018

Copy link to clipboard

Copied

Very good idea, Michel!

Best,
Uwe

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 ,
Aug 21, 2018 Aug 21, 2018

Copy link to clipboard

Copied

LATEST

Thanks Michel, unfortunately those figures were just examples, the actual figures I'm using have no common denominator and there's two more unique figures for the other plane as well!

I'll mark this thread answered and start a new one about just moving objects.

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