TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: CAB on November 15, 2014, 03:11:40 PM

Title: Nudge Command for ACAD2006
Post by: CAB on November 15, 2014, 03:11:40 PM
Wishing I had the Nudge ability in ACAD2012.
Has anyone seen a reactor that would simulate the Nudge Command?
Title: Re: Nudge Command for ACAD2006
Post by: Rod on November 16, 2014, 01:54:35 AM
For me NUDGE is highlight object/s then CTRL+SHIFT+ARROW KEY.
AUTOCAD CIVIL 2015 and AUTOCAD MAP 2015 but I assumed this was a Vanilla ACAD shortcut.

or are you talking about something different?
Title: Re: Nudge Command for ACAD2006
Post by: CAB on November 16, 2014, 09:52:05 AM
Same thing. I am using Chief Architect for a month now & it has that command.
Select an object or objects, hit [arrow] and they move a preset distance.
[Shift] [Arrow] would be 10 times the distance. Distance is in a variable.
Maybe two variables so you can set each separately.
Or three if you can use [Ctrl] [Arrow] too.

I see ACAD2012 has that feature but thought someone would have created a routine for older ACAD versions.
Did not think I would use it when it came out in ACAD but using it lately I kinda like it.
Title: Re: Nudge Command for ACAD2006
Post by: danallen on November 16, 2014, 10:03:08 AM
I have a rough shortcut routine that I use the numpad arrows to set dimension line offset at standard 3/8" * drawing scale. Uses keyboard accelerators in menu file. I haven't had time to work out right way to due with new CUI. You could modify to check if objects are selected, then issue move command.

Code: [Select]
//
//      menu file
//

***MENUGROUP=XYZ_ACCEL

***ACCELERATORS
["NUMPAD5"]^P(XYZ_keydist "get" nil)
["NUMPAD6"]^P(XYZ_keydist "0" nil)
["NUMPAD9"]^P(XYZ_keydist "45" nil)
["NUMPAD8"]^P(XYZ_keydist "90" nil)
["NUMPAD7"]^P(XYZ_keydist "135" nil)
["NUMPAD4"]^P(XYZ_keydist "180" nil)
["NUMPAD1"]^P(XYZ_keydist "-135" nil)
["NUMPAD2"]^P(XYZ_keydist "-90" nil)
["NUMPAD3"]^P(XYZ_keydist "-45" nil)
[CONTROL+"NUMPAD5"]^P(XYZ_keydist "get" 2.0)
[CONTROL+"NUMPAD6"]^P(XYZ_keydist "0" 2.0)
[CONTROL+"NUMPAD9"]^P(XYZ_keydist "45" 2.0)
[CONTROL+"NUMPAD8"]^P(XYZ_keydist "90" 2.0)
[CONTROL+"NUMPAD7"]^P(XYZ_keydist "135" 2.0)
[CONTROL+"NUMPAD4"]^P(XYZ_keydist "180" 2.0)
[CONTROL+"NUMPAD1"]^P(XYZ_keydist "-135" 2.0)
[CONTROL+"NUMPAD2"]^P(XYZ_keydist "-90" 2.0)
[CONTROL+"NUMPAD3"]^P(XYZ_keydist "-45" 2.0)

;;; lisp code
;;;=========================================================================
;;; XYZ_KEYDIST - Combines input distance with direction for use with numeric keypad accelerators
;;;=========================================================================
(defun XYZ_keydist ( ang mult / return)
  (if (and (= 0 (getvar "cmdactive")) (/= "get" ang))
    ;; pan if no command active
    (progn
      (command "-pan" (getvar "viewctr") (strcat "@" (rtos (/ (getvar "viewsize") -4.0)) "<" angle))
    )
    ;; return number if active
    (progn
      (if (not mult)(setq mult 1))
      (if (or (not XYZ_KEYDIST_VALUE)
              (= ang "get")
          ) ;or
        (setq XYZ_KEYDIST_VALUE
                 (dos_getreal "Distance" 
                              "Enter distance for keypad entry" ;prompt
                              7 ;no zero, negative, or null
                              (* 0.375 (getvar "dimscale"))
               ) ;cbc_getdist
        ) ;setq
      ) ;if
      (setq return (strcat "@" (rtos (* mult XYZ_KEYDIST_VALUE)) "<" ang))
    )
  )
  (if return return (princ))
) ;defun

Title: Re: Nudge Command for ACAD2006
Post by: CAB on November 16, 2014, 12:30:32 PM
Very interesting solution. Thanks for sharing.

I'll have some time tomorrow to test it out.  8)
Title: Re: Nudge Command for ACAD2006
Post by: irneb on November 17, 2014, 07:54:09 AM
Old one I made a while back: http://sourceforge.net/p/caddons/code/HEAD/tree/General/Editing.LSP

Uses the numpad keys to move in 45 degree directions. Distance moved depends on the zoom factor.
Title: Re: Nudge Command for ACAD2006
Post by: CAB on November 17, 2014, 08:18:39 AM
Thanks  Irné
I'll take a look
Title: Re: Nudge Command for ACAD2006
Post by: CAB on May 13, 2017, 07:19:21 PM
Well I'm back to this because I had some time today.
Decided to go with the accelerator key method.
Code: [Select]
;; CAB 05.12.2017
;;  Called from Menu Hot Keys
;;  [Ctrl]+[Right]    (NudgeObjects 0)
;;  [Ctrl]+[Left]     (NudgeObjects 180)
;;  [Ctrl]+[Up]       (NudgeObjects 90)       
;;  [Ctrl]+[Down]     (NudgeObjects 2700)
;;  [Ctrl]+[5]        (NudgeObjects -1)  Edit Nudge Distance


(defun NudgeObjects ( ang / ss sel p1 p2 )
  (if (not NudgeDist) (setq NudgeDist 1.0)) ; Globle Variable
 
  (setq ss (cadr(ssgetfirst))) ;  get anything already selected

  (cond
    ((< ang 0)  (setq NudgeDist (getdist "/nEnter new Nudge diatance : ")))
       
    ((= 0 (getvar "cmdactive"))  ; MOVE if no command active
        (if (and (null ss) (not (prompt "\nSelect the objects to move: ")))
                (setq ss (ssget "_:L"))   )
     
        (setq p1 (vlax-3D-point (trans '(0 0) 1 0))
                 p2 (vlax-3D-point (trans (polar '(0 0) (/ (* ang pi) 180.0) NudgeDist) 1 0))
        )
        (vlax-for obj  (setq sel (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object))))
            (vl-catch-all-apply 'vla-move (list obj p1 p2))
        )     
        (vla-Delete sel)
       (sssetfirst nil ss) ; activate the selection set again
    )

  ) ; cond
) ; defun
(vl-load-com)
Title: Re: Nudge Command for ACAD2006
Post by: BIGAL on May 13, 2017, 08:18:57 PM
This is similar chx chy chz done 1997

Code: [Select]
(defun C:CHX ()
  (SETVAR "CMDECHO" 0)
  (setq sn (getvar "osmode"))
  (command "osnap" "near")
  (setq x 0)
  (princ "\nalters object in X direction")
  (setq ht (getstring "\n What is amount of change: "))
  (setq newht (strcat ht ",0"))
  (while (= x 0)
    (setq newobj (entsel "\nPoint to object: "))
    (if (/= newobj nil)
    (progn
    (command "move" newobj "" "0,0" newht)
    ))
  (if (= newobj nil)(setq x 1))
  )
)
Title: Re: Nudge Command for ACAD2006
Post by: Grrr1337 on May 14, 2017, 04:57:02 AM
@CAB its impressive that you've done it without (grread)

BTW Thanks to you (or some old code example of yours) I managed to learn (grread), so heres another approach:

Code - Auto/Visual Lisp: [Select]
  1. (defun C:test ( / f SS grr Stop d k tmp )
  2.  
  3.   (setq d 50) ; default nudge distance
  4.  
  5.   (setq f
  6.     (lambda (SS d k / a p1 p2 i )
  7.       (and (setq a (cadr (assoc k '(("W" 90) ("S" 270) ("A" 180) ("D" 0)))))
  8.         (setq p1 (vlax-3D-point (trans '(0 0) 1 0))) (setq p2 (vlax-3D-point (trans (polar '(0 0) (/ (* a PI) 180.0) d) 1 0)))
  9.         (repeat (setq i (sslength SS)) (vla-Move (vlax-ename->vla-object (ssname SS (setq i (1- i)))) p1 p2) )
  10.       ); and
  11.     ); lambda
  12.   ); setq f
  13.  
  14.   (and (princ "\nSelect objects to nudge: ") (setq SS (ssget "_:L-I")) (sssetfirst nil nil)
  15.     (princ "\nPress [W/A/S/D] keys to nudge the SS | [TAB] to set new distance | [ENTER/RMB/LMB] if done: ")
  16.     (while (not Stop) (setq grr (grread)) (and (or (equal grr '(2 13)) (member (car grr) '(3 25))) (setq Stop T))
  17.       (cond ( (/= (car grr) 2) )
  18.         ( (setq k (strcase (chr (cadr grr))))
  19.           (if (= k "\t") (if (setq tmp (getdist "\nSpecify new distance: ")) (setq d tmp)) (f SS d k) )
  20.         )
  21.       ); cond                  
  22.     ); while
  23.   ); and
  24.   (princ)
  25. ); defun C:test

Do you guys ever played Counter-Strike? Try using <W> <A> <S> <D> keys for nudging/moving its quite easy. :)
Title: Re: Nudge Command for ACAD2006
Post by: chisinwolf on December 10, 2018, 11:01:48 PM
@CAB its impressive that you've done it without (grread)

BTW Thanks to you (or some old code example of yours) I managed to learn (grread), so heres another approach:

Code - Auto/Visual Lisp: [Select]
  1. (defun C:test ( / f SS grr Stop d k tmp )
  2.  
  3.   (setq d 50) ; default nudge distance
  4.  
  5.   (setq f
  6.     (lambda (SS d k / a p1 p2 i )
  7.       (and (setq a (cadr (assoc k '(("W" 90) ("S" 270) ("A" 180) ("D" 0)))))
  8.         (setq p1 (vlax-3D-point (trans '(0 0) 1 0))) (setq p2 (vlax-3D-point (trans (polar '(0 0) (/ (* a PI) 180.0) d) 1 0)))
  9.         (repeat (setq i (sslength SS)) (vla-Move (vlax-ename->vla-object (ssname SS (setq i (1- i)))) p1 p2) )
  10.       ); and
  11.     ); lambda
  12.   ); setq f
  13.  
  14.   (and (princ "\nSelect objects to nudge: ") (setq SS (ssget "_:L-I")) (sssetfirst nil nil)
  15.     (princ "\nPress [W/A/S/D] keys to nudge the SS | [TAB] to set new distance | [ENTER/RMB/LMB] if done: ")
  16.     (while (not Stop) (setq grr (grread)) (and (or (equal grr '(2 13)) (member (car grr) '(3 25))) (setq Stop T))
  17.       (cond ( (/= (car grr) 2) )
  18.         ( (setq k (strcase (chr (cadr grr))))
  19.           (if (= k "\t") (if (setq tmp (getdist "\nSpecify new distance: ")) (setq d tmp)) (f SS d k) )
  20.         )
  21.       ); cond                  
  22.     ); while
  23.   ); and
  24.   (princ)
  25. ); defun C:test

Do you guys ever played Counter-Strike? Try using <W> <A> <S> <D> keys for nudging/moving its quite easy. :)

This code is very useful for me.
Is there any way to add a Regen immediately after each individual nudge? Always after each nudge before exiting?

In any event thank you Grrr1337 for this code.
Title: Re: Nudge Command for ACAD2006
Post by: ribarm on December 11, 2018, 03:47:38 AM
Quote
(defun C:test ( / f SS grr Stop d k tmp )
 
  (setq d 50) ; default nudge distance
 
  (setq f
    (lambda (SS d k / a p1 p2 i )
      (and (setq a (cadr (assoc k '(("W" 90) ("S" 270) ("A" 180) ("D" 0)))))
        (setq p1 (vlax-3D-point (trans '(0 0) 1 0))) (setq p2 (vlax-3D-point (trans (polar '(0 0) (/ (* a PI) 180.0) d) 1 0)))
        (repeat (setq i (sslength SS)) (vla-Move (vlax-ename->vla-object (ssname SS (setq i (1- i)))) p1 p2) )
      ); and
    ); lambda
  ); setq f
 
  (and (princ "\nSelect objects to nudge: ") (setq SS (ssget "_:L-I")) (sssetfirst nil nil)
    (princ "\nPress [W/A/S/D] keys to nudge the SS | [TAB] to set new distance | [ENTER/RMB/LMB] if done: ")
    (while (not Stop) (setq grr (grread)) (and (or (equal grr '(2 13)) (member (car grr) '(3 25))) (setq Stop T))
      (cond ( (/= (car grr) 2) )
        ( (setq k (strcase (chr (cadr grr))))
          (if (= k "\t") (if (setq tmp (getdist "\nSpecify new distance: ")) (setq d tmp)) (progn (f SS d k) (vl-cmdf "_.REGEN")) )
        )
      ); cond         
    ); while
  ); and
  (princ)
); defun C:test

HTH., M.R.
Title: Re: Nudge Command for ACAD2006
Post by: chisinwolf on December 11, 2018, 06:49:39 AM
Hi Marko,

That works exactly how I wanted.
Thank you for taking time to help me.

Cheers.
Title: Re: Nudge Command for ACAD2006
Post by: GDF on December 11, 2018, 07:28:56 PM
Awesome Marko