0

I wrote a script to nudge by 1/10 in Illustrator (like in InDesign). It works, but only for the whole object, even if I only select some anchors. Is there a way for it to work as well when only anchors (or paths) are selected?

Here is the script:

var myDis = app.preferences.getRealPreference ('cursorKeyLength'); 
var myDis = myDis/10 
var myDoc = app.activeDocument;  
var mySel = myDoc.selection;  

for ( var i = 0; i < mySel.length; i++ ) {  
mySel[i].top = mySel[i].top-myDis; // so it moves by 1/10 of the cursorKeyLength to the top
}

Thanks!

0

2 Answers 2

2

I don't understand why you need a script for this.....

Set the Keyboard Increment in the preferences to 5:

  • Tap any arrow key - , , , ... the nudge is 5
  • Hold the Command/Ctrl key down and tap any arrow key - , , , ... the nudge is 0.5 (1/10 the increment setting) (this only works in InDesign, Illustrator won't recognize this)
  • Hold the Shift key down and tap any arrow key - , , , ... the nudge is 50 (10x the increment setting)

This works with any selection be it merely anchor points or whole objects.

You can get a 1/10 nudge of any value just by using modifier keys in InDesign. If using an action, the modifiers are recorded. If using Illustrator I just set my nudge to a very small amount, then use Shift when I need it larger.

But then, perhaps I just don't understand why you feel a script is necessary.

4
  • 1
    Your shortcut (cmd+shift) works very well in InDesign, but not in Illustrator, which is the app I was trying to code for. Thanks!
    – Raphaël
    Jun 18, 2015 at 19:45
  • @Raphaël It works perfectly in Illustrator. I use it daily.
    – Scott
    Jun 18, 2015 at 19:46
  • 1
    Your 1/10 nudge works in Illustrator with the cmd key? Not in mine... and I searched on forums and it is written everywhere that you can't in Illustrator (but cmd+shift works in InDesign).
    – Raphaël
    Jun 18, 2015 at 19:57
  • Oh.. hmm... guess not. Seems your'e right the command/ctrl does not work in AI. Always thought it did. I just set my nudge to very small, then use shift when I need it larger. I'll edit the answer....
    – Scott
    Jun 18, 2015 at 20:00
0

Here's what I came with, wich will move selected anchors to the left by 1/10 of the Keyboard Increment saved in the Preferences:

var myLength = app.preferences.getRealPreference('cursorKeyLength') / 10,
    mySelection = app.activeDocument.selection,
    myDistance = [0 - myLength, 0]; // move selected anchors to the left


for (var i = 0; i < mySelection.length; i++) {
    // for anchors 
    if (mySelection[i].typename === 'PathItem') {
        var p = mySelection[i].pathPoints;
        for (j = 0; j < p.length; j++) {
            if (p[j].selected === PathPointSelection.ANCHORPOINT) {
                with(p[j]) {
                    anchor = [anchor[0] + myDistance[0], anchor[1] + myDistance[1]];
                    leftDirection = [leftDirection[0] + myDistance[0], leftDirection[1] + myDistance[1]];
                    rightDirection = [rightDirection[0] + myDistance[0], rightDirection[1] + myDistance[1]];
                }
            }
        }
    }
    // for anything else 
    else {
        with(mySelection[i]) {
            position = [position[0] + myDistance[0], position[1] + myDistance[1]];
        }
    }
}

To move the anchors in another direction, change variable myDistance:

var myDistance = [0 - myLength, 0]; // leftward
var myDistance = [0 + myLength, 0]; // rightward
var myDistance = [0, 0 + myLength]; // upward
var myDistance = [0, 0 - myLength]; // downward
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.