Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Preselect objects for routine

10 REPLIES 10
Reply
Message 1 of 11
Anonymous
524 Views, 10 Replies

Preselect objects for routine

I have written a small routine to nudge selected objects a specified distance in any direction of 45 degree increments,
but would prefer to be able to use a preselected set of objects occasionally rather than have the routine cancel any
existing selection set such that I have to reselect them.

So I actually want the option of using an existing selection set, or if there is none prompt as it does now. Any help
would be appreciated, thanks.

[code]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Nudge - gets selection set, sets polar angle to 45 ;;;
;;; & offers preset nudge distance to accept or change ;;;
;;; Gordon Stephens 28-10-2007 ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun c:nudge-g ()
(getnudge)
(setq ortho (getvar "orthomode"))
(if (= ortho 1) (setvar "orthomode" 0)) ; if
(setq pang (getvar "polarang"))
(if (/= pang 45.0) (command "polarang" "45.0")) ; if
(setq asnp (getvar "autosnap")) (princ asnp)
(if (/= asnap 47) (setvar "autosnap" 47)) ; if
(princ (rtos ndg1))
(prompt "\nobjects to nudge")
(setq sset (ssget))
(setq pntdir1 (getpoint "\npick any reference/start point"))
(prompt "\npick point in direction of nudge")
(command "line" pntdir1 pause "")
(setq elist (entget (entlast))) (command "erase" "Last" "")
(setq angdir (angle (cdr (assoc 10 elist)) (cdr (assoc 11 elist))))
(setq angdir-d (rtd angdir))
(cond
((= angdir-d 0.0) (command "move" sset "" "d" (list ndg1 0.0)))
((= angdir-d 45.0) (command "move" sset "" "d" (list ndg1 ndg1)))
((= angdir-d 90.0) (command "move" sset "" "d" (list 0.0 ndg1)))
((= angdir-d 135.0) (command "move" sset "" "d" (list (- ndg1) ndg1)))
((= angdir-d 180.0) (command "move" sset "" "d" (list (- ndg1) 0.0)))
((= angdir-d 225.0) (command "move" sset "" "d" (list (- ndg1) (- ndg1))))
((= angdir-d 270.0) (command "move" sset "" "d" (list 0.0 (- ndg1))))
((= angdir-d 315.0) (command "move" sset "" "d" (list ndg1 (- ndg1))))
) ; cond
(setvar "orthomode" ortho)
(setvar "polarang" pang)
(setvar "autosnap" asnp)
) ; defun

(defun rtd (r) (* (/ 180.0 pi) r))

(defun dtr (r) (* (/ n 180.0) pi))

(defun getnudge ()
(if (= ndg1 nil)
(progn
(setq ndg1 20)
)
)
(initget 2)
(setq message (strcat "\nCurrent distance to nudge objects horz/vert <" (rtos ndg1 2) ">:"))
(setq ndg (getreal message))
(if (/= ndg nil)
(progn
(setq ndg1 ndg)
)
)
)
[/code]
--
Gordon
10 REPLIES 10
Message 2 of 11
Anonymous
in reply to: Anonymous

Your (command "polarang") is emptying your current selection set either set
this using (setvar "polarang" (/ pi 2)) and ssget will grab what is
highlighted

OR

or use (ssget "i") before this to get the contents of the current selection
set
this returns nil if nothing is selected or returns the selection set if
there is something selected.


"Gordon Stephens" wrote in message
news:5762817@discussion.autodesk.com...
I have written a small routine to nudge selected objects a specified
distance in any direction of 45 degree increments,
but would prefer to be able to use a preselected set of objects occasionally
rather than have the routine cancel any
existing selection set such that I have to reselect them.

So I actually want the option of using an existing selection set, or if
there is none prompt as it does now. Any help
would be appreciated, thanks.

[code]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Nudge - gets selection set, sets polar angle to 45 ;;;
;;; & offers preset nudge distance to accept or change ;;;
;;; Gordon Stephens 28-10-2007 ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun c:nudge-g ()
(getnudge)
(setq ortho (getvar "orthomode"))
(if (= ortho 1) (setvar "orthomode" 0)) ; if
(setq pang (getvar "polarang"))
(if (/= pang 45.0) (command "polarang" "45.0")) ; if
(setq asnp (getvar "autosnap")) (princ asnp)
(if (/= asnap 47) (setvar "autosnap" 47)) ; if
(princ (rtos ndg1))
(prompt "\nobjects to nudge")
(setq sset (ssget))
(setq pntdir1 (getpoint "\npick any reference/start point"))
(prompt "\npick point in direction of nudge")
(command "line" pntdir1 pause "")
(setq elist (entget (entlast))) (command "erase" "Last" "")
(setq angdir (angle (cdr (assoc 10 elist)) (cdr (assoc 11 elist))))
(setq angdir-d (rtd angdir))
(cond
((= angdir-d 0.0) (command "move" sset "" "d" (list ndg1 0.0)))
((= angdir-d 45.0) (command "move" sset "" "d" (list ndg1 ndg1)))
((= angdir-d 90.0) (command "move" sset "" "d" (list 0.0 ndg1)))
((= angdir-d 135.0) (command "move" sset "" "d" (list (- ndg1) ndg1)))
((= angdir-d 180.0) (command "move" sset "" "d" (list (- ndg1) 0.0)))
((= angdir-d 225.0) (command "move" sset "" "d" (list (- ndg1) (- ndg1))))
((= angdir-d 270.0) (command "move" sset "" "d" (list 0.0 (- ndg1))))
((= angdir-d 315.0) (command "move" sset "" "d" (list ndg1 (- ndg1))))
) ; cond
(setvar "orthomode" ortho)
(setvar "polarang" pang)
(setvar "autosnap" asnp)
) ; defun

(defun rtd (r) (* (/ 180.0 pi) r))

(defun dtr (r) (* (/ n 180.0) pi))

(defun getnudge ()
(if (= ndg1 nil)
(progn
(setq ndg1 20)
)
)
(initget 2)
(setq message (strcat "\nCurrent distance to nudge objects horz/vert <"
(rtos ndg1 2) ">:"))
(setq ndg (getreal message))
(if (/= ndg nil)
(progn
(setq ndg1 ndg)
)
)
)
[/code]
--
Gordon
Message 3 of 11
Anonymous
in reply to: Anonymous

Thank you Rod, that is great - two ways to do it! I'll try both and see which I prefer. Fatty did add a comment on the
previous posting 'Constrain line direction after pick point' regarding the setting of the polarang variable in the same
way you have suggested, but since I had gone down the route of (command . . . I didn't think to go back and amend it
whilst it 'appeared' to be working.
Thanks for rapid response too.
--
Gordon.


"Rod" wrote in message news:5762833@discussion.autodesk.com...
Your (command "polarang") is emptying your current selection set either set
this using (setvar "polarang" (/ pi 2)) and ssget will grab what is
highlighted

OR

or use (ssget "i") before this to get the contents of the current selection
set
this returns nil if nothing is selected or returns the selection set if
there is something selected.
Message 4 of 11
Anonymous
in reply to: Anonymous

No worries.
Hope that works

"Gordon Stephens" wrote in message
news:5762819@discussion.autodesk.com...
Thank you Rod, that is great - two ways to do it! I'll try both and see
which I prefer. Fatty did add a comment on the
previous posting 'Constrain line direction after pick point' regarding the
setting of the polarang variable in the same
way you have suggested, but since I had gone down the route of (command . .
. I didn't think to go back and amend it
whilst it 'appeared' to be working.
Thanks for rapid response too.
--
Gordon.


"Rod" wrote in message
news:5762833@discussion.autodesk.com...
Your (command "polarang") is emptying your current selection set either set
this using (setvar "polarang" (/ pi 2)) and ssget will grab what is
highlighted

OR

or use (ssget "i") before this to get the contents of the current selection
set
this returns nil if nothing is selected or returns the selection set if
there is something selected.
Message 5 of 11
Anonymous
in reply to: Anonymous

Actually, I tried both, but I can't get a choice - either a pre-existing selection set or if none, prompt for one. Not
sure what I'm missing.

HOWEVER - more importantly, in testing this, even though I can get the correct angle direction, the moving of the
objects selected seems to be somewhat arbitrary and unpredictable. I can't think what I have programmed incorrectly, but
sometimes it doesn't move the objects at all, and other times it moves them a peculiar distance - is it my cond
statements, or the way I have set up the move points?

Latest version:-
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Nudge - gets selection set, sets polar angle to 45 ;;;
;;; & offers preset nudge distance to accept or change ;;;
;;; Gordon Stephens 28-10-2007 ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
[code]
(defun c:nudge-g ( / ortho pang asnp pntdir1 sset elist angdir) ; angdir-d)
(setvar "cmdecho" 0)
(setq sset nil)
(getnudge)
(setq ortho (getvar "orthomode"))
(if (= ortho 1) (setvar "orthomode" 0)) ; if
(setq pang (getvar "polarang"))
(if (/= pang 45.0) (setvar "polarang" (/ pi 4))) ; if
(setq asnp (getvar "autosnap"))
(if (/= asnap 47) (setvar "autosnap" 47)) ; if
(prompt "\nobjects to nudge")
(setq sset (ssget))
(setq pntdir1 (getpoint "\npick any reference/start point"))
(prompt "\npick point in direction of nudge")
(command "line" pntdir1 pause "")
(setq elist (entget (entlast))) (command "erase" "Last" "")
(setq angdir (angle (cdr (assoc 10 elist)) (cdr (assoc 11 elist))))
(setq angdir-d (rtd angdir))
(cond
((= angdir-d 0.0) (command "move" sset "" "d" (list ndg1 0.0)))
((= angdir-d 45.0) (command "move" sset "" "d" (list ndg1 ndg1)))
((= angdir-d 90.0) (command "move" sset "" "d" (list 0.0 ndg1)))
((= angdir-d 135.0) (command "move" sset "" "d" (list (- ndg1) ndg1)))
((= angdir-d 180.0) (command "move" sset "" "d" (list (- ndg1) 0.0)))
((= angdir-d 225.0) (command "move" sset "" "d" (list (- ndg1) (- ndg1))))
((= angdir-d 270.0) (command "move" sset "" "d" (list 0.0 (- ndg1))))
((= angdir-d 315.0) (command "move" sset "" "d" (list ndg1 (- ndg1))))
) ; cond
(setvar "orthomode" ortho)
(setvar "polarang" pang)
(setvar "autosnap" asnp)
(princ)
) ; defun

(defun rtd (r) (* (/ 180.0 pi) r))

(defun dtr (r) (* (/ n 180.0) pi))

(defun getnudge ()
(if (= ndg1 nil)
(progn
(setq ndg1 20.0)
)
)
(initget 2)
(setq message (strcat "\nCurrent distance to nudge objects horz/vert <" (rtos ndg1 2) ">:"))
(setq ndg (getreal message))
(if (/= ndg nil)
(progn
(setq ndg1 ndg)
)
)
)

[/code]
--
Gordon.


"Rod" wrote in message news:5762833@discussion.autodesk.com...
Your (command "polarang") is emptying your current selection set either set
this using (setvar "polarang" (/ pi 2)) and ssget will grab what is
highlighted

OR

or use (ssget "i") before this to get the contents of the current selection
set
this returns nil if nothing is selected or returns the selection set if
there is something selected.


"
Message 6 of 11
Anonymous
in reply to: Anonymous

Gordon Stephens wrote:
> Actually, I tried both, but I can't get a choice - either a pre-existing selection set or if none, prompt for one. Not
> sure what I'm missing.
>
> HOWEVER - more importantly, in testing this, even though I can get the correct angle direction, the moving of the
> objects selected seems to be somewhat arbitrary and unpredictable. I can't think what I have programmed incorrectly, but
> sometimes it doesn't move the objects at all, and other times it moves them a peculiar distance - is it my cond
> statements, or the way I have set up the move points?
>
> Latest version:-
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> ;;; Nudge - gets selection set, sets polar angle to 45 ;;;
> ;;; & offers preset nudge distance to accept or change ;;;
> ;;; Gordon Stephens 28-10-2007 ;;;
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> [code]
> (defun c:nudge-g ( / ortho pang asnp pntdir1 sset elist angdir) ; angdir-d)
> (setvar "cmdecho" 0)
> (setq sset nil)
> (getnudge)
> (setq ortho (getvar "orthomode"))
> (if (= ortho 1) (setvar "orthomode" 0)) ; if
> (setq pang (getvar "polarang"))
> (if (/= pang 45.0) (setvar "polarang" (/ pi 4))) ; if
> (setq asnp (getvar "autosnap"))
> (if (/= asnap 47) (setvar "autosnap" 47)) ; if
> (prompt "\nobjects to nudge")
> (setq sset (ssget))
> (setq pntdir1 (getpoint "\npick any reference/start point"))
> (prompt "\npick point in direction of nudge")
> (command "line" pntdir1 pause "")
> (setq elist (entget (entlast))) (command "erase" "Last" "")
> (setq angdir (angle (cdr (assoc 10 elist)) (cdr (assoc 11 elist))))
> (setq angdir-d (rtd angdir))
> (cond
> ((= angdir-d 0.0) (command "move" sset "" "d" (list ndg1 0.0)))
> ((= angdir-d 45.0) (command "move" sset "" "d" (list ndg1 ndg1)))
> ((= angdir-d 90.0) (command "move" sset "" "d" (list 0.0 ndg1)))
> ((= angdir-d 135.0) (command "move" sset "" "d" (list (- ndg1) ndg1)))
> ((= angdir-d 180.0) (command "move" sset "" "d" (list (- ndg1) 0.0)))
> ((= angdir-d 225.0) (command "move" sset "" "d" (list (- ndg1) (- ndg1))))
> ((= angdir-d 270.0) (command "move" sset "" "d" (list 0.0 (- ndg1))))
> ((= angdir-d 315.0) (command "move" sset "" "d" (list ndg1 (- ndg1))))
> ) ; cond
> (setvar "orthomode" ortho)
> (setvar "polarang" pang)
> (setvar "autosnap" asnp)
> (princ)
> ) ; defun
>
> (defun rtd (r) (* (/ 180.0 pi) r))
>
> (defun dtr (r) (* (/ n 180.0) pi))
>
> (defun getnudge ()
> (if (= ndg1 nil)
> (progn
> (setq ndg1 20.0)
> )
> )
> (initget 2)
> (setq message (strcat "\nCurrent distance to nudge objects horz/vert <" (rtos ndg1 2) ">:"))
> (setq ndg (getreal message))
> (if (/= ndg nil)
> (progn
> (setq ndg1 ndg)
> )
> )
> )
>
> [/code]
> --
> Gordon.
>
>
> "Rod" wrote in message news:5762833@discussion.autodesk.com...
> Your (command "polarang") is emptying your current selection set either set
> this using (setvar "polarang" (/ pi 2)) and ssget will grab what is
> highlighted
>
> OR
>
> or use (ssget "i") before this to get the contents of the current selection
> set
> this returns nil if nothing is selected or returns the selection set if
> there is something selected.
>
>
> "
You may need to set the system variable osmode (object snap) to zero
after saving its initial value then restoring it at the end of the routine

--
George Drayton CD-CAD Ltd New Zealand
Message 7 of 11
Anonymous
in reply to: Anonymous

(defun c:nudge-g ()
(getnudge)
(setq ortho (getvar "orthomode"))
(if (= ortho 1)
(setvar "orthomode" 0)
) ; if
(setq pang (getvar "polarang"))
(if (/= pang 45.0)
(setvar "polarang" (/ pi 2)) ;;this is the line I have
edited
) ; if
(setq asnp (getvar "autosnap"))
(princ asnp)
(if (/= asnap 47)
(setvar "autosnap" 47)
) ; if
(princ (rtos ndg1))
(prompt "\nobjects to nudge")
(setq sset (ssget))
(setq pntdir1 (getpoint "\npick any reference/start point"))
(prompt "\npick point in direction of nudge")
(command "line" pntdir1 pause "")
(setq elist (entget (entlast)))
(command "erase" "Last" "")
(setq angdir (angle (cdr (assoc 10 elist)) (cdr (assoc 11 elist))))
(setq angdir-d (rtd angdir))
(cond
((= angdir-d 0.0) (command "move" sset "" "d" (list ndg1 0.0)))
((= angdir-d 45.0) (command "move" sset "" "d" (list ndg1 ndg1)))
((= angdir-d 90.0) (command "move" sset "" "d" (list 0.0 ndg1)))
((= angdir-d 135.0) (command "move" sset "" "d" (list (- ndg1) ndg1)))
((= angdir-d 180.0) (command "move" sset "" "d" (list (- ndg1) 0.0)))
((= angdir-d 225.0) (command "move" sset "" "d" (list (- ndg1) (-
ndg1))))
((= angdir-d 270.0) (command "move" sset "" "d" (list 0.0 (- ndg1))))
((= angdir-d 315.0) (command "move" sset "" "d" (list ndg1 (- ndg1))))
) ; cond
(setvar "orthomode" ortho)
(setvar "polarang" pang)
(setvar "autosnap" asnp)
) ; defun

(defun rtd (r) (* (/ 180.0 pi) r))

(defun dtr (r) (* (/ n 180.0) pi))

(defun getnudge ()
(if (= ndg1 nil)
(progn
(setq ndg1 20)
) ;_ end of progn
) ;_ end of if
(initget 2)
(setq message (strcat "\nCurrent distance to nudge objects horz/vert <"
(rtos ndg1 2) ">:"))
(setq ndg (getreal message))
(if (/= ndg nil)
(progn
(setq ndg1 ndg)
) ;_ end of progn
) ;_ end of if
) ;_ end of defun
Message 8 of 11
Anonymous
in reply to: Anonymous

Opps that should have been

(defun c:nudge-g ()
(getnudge)
(setq ortho (getvar "orthomode"))
(if (= ortho 1)
(setvar "orthomode" 0)
) ; if
(setq pang (getvar "polarang"))
(if (/= pang (/ pi 4)) ;EDITED
(setvar "polarang" (/ pi 4)) ;EDITED
) ; if
(setq asnp (getvar "autosnap"))
(princ asnp)
(if (/= asnap 47)
(setvar "autosnap" 47)
) ; if
(princ (rtos ndg1))
(prompt "\nobjects to nudge")
(setq sset (ssget))
(setq pntdir1 (getpoint "\npick any reference/start point"))
(prompt "\npick point in direction of nudge")
(command "line" pntdir1 pause "")
(setq elist (entget (entlast)))
(command "erase" "Last" "")
(setq angdir (angle (cdr (assoc 10 elist)) (cdr (assoc 11 elist))))
(setq angdir-d (rtd angdir))
(cond
((= angdir-d 0.0) (command "move" sset "" "d" (list ndg1 0.0)))
((= angdir-d 45.0) (command "move" sset "" "d" (list ndg1 ndg1)))
((= angdir-d 90.0) (command "move" sset "" "d" (list 0.0 ndg1)))
((= angdir-d 135.0) (command "move" sset "" "d" (list (- ndg1) ndg1)))
((= angdir-d 180.0) (command "move" sset "" "d" (list (- ndg1) 0.0)))
((= angdir-d 225.0) (command "move" sset "" "d" (list (- ndg1) (-
ndg1))))
((= angdir-d 270.0) (command "move" sset "" "d" (list 0.0 (- ndg1))))
((= angdir-d 315.0) (command "move" sset "" "d" (list ndg1 (- ndg1))))
) ; cond
(setvar "orthomode" ortho)
(setvar "polarang" pang)
(setvar "autosnap" asnp)
) ; defun

(defun rtd (r) (* (/ 180.0 pi) r))

(defun dtr (r) (* (/ n 180.0) pi))

(defun getnudge ()
(if (= ndg1 nil)
(progn
(setq ndg1 20)
) ;_ end of progn
) ;_ end of if
(initget 2)
(setq message (strcat "\nCurrent distance to nudge objects horz/vert <"
(rtos ndg1 2) ">:"))
(setq ndg (getreal message))
(if (/= ndg nil)
(progn
(setq ndg1 ndg)
) ;_ end of progn
) ;_ end of if
) ;_ end of defun
;|«Visual LISP© Format Options»
(200 2 40 2 T "end of " 100 20 0 0 0 T T nil T)
;*** DO NOT add text below the comment! ***|;
Message 9 of 11
Anonymous
in reply to: Anonymous

George, thanks for that - why do I always forget those pesky osnaps? That must have been what was affecting it since it
seemed entirely random as to when it worked correctly and when it didn't! I'll amend that now.
--
Gordon


"George Drayton" wrote in message news:5762784@discussion.autodesk.com...
Gordon Stephens wrote:

You may need to set the system variable osmode (object snap) to zero
after saving its initial value then restoring it at the end of the routine

--
George Drayton CD-CAD Ltd New Zealand
Message 10 of 11
Anonymous
in reply to: Anonymous

Rod, thanks so much for your continuing help - I will make those amendments too.
--
Gordon


"Rod" wrote in message news:5762879@discussion.autodesk.com...
Opps that should have been

(defun c:nudge-g ()
(getnudge)
(setq ortho (getvar "orthomode"))
(if (= ortho 1)
(setvar "orthomode" 0)
) ; if
(setq pang (getvar "polarang"))
(if (/= pang (/ pi 4)) ;EDITED
(setvar "polarang" (/ pi 4)) ;EDITED
) ; if
(setq asnp (getvar "autosnap"))
(princ asnp)
(if (/= asnap 47)
(setvar "autosnap" 47)
) ; if
(princ (rtos ndg1))
(prompt "\nobjects to nudge")
(setq sset (ssget))
(setq pntdir1 (getpoint "\npick any reference/start point"))
(prompt "\npick point in direction of nudge")
(command "line" pntdir1 pause "")
(setq elist (entget (entlast)))
(command "erase" "Last" "")
(setq angdir (angle (cdr (assoc 10 elist)) (cdr (assoc 11 elist))))
(setq angdir-d (rtd angdir))
(cond
((= angdir-d 0.0) (command "move" sset "" "d" (list ndg1 0.0)))
((= angdir-d 45.0) (command "move" sset "" "d" (list ndg1 ndg1)))
((= angdir-d 90.0) (command "move" sset "" "d" (list 0.0 ndg1)))
((= angdir-d 135.0) (command "move" sset "" "d" (list (- ndg1) ndg1)))
((= angdir-d 180.0) (command "move" sset "" "d" (list (- ndg1) 0.0)))
((= angdir-d 225.0) (command "move" sset "" "d" (list (- ndg1) (-
ndg1))))
((= angdir-d 270.0) (command "move" sset "" "d" (list 0.0 (- ndg1))))
((= angdir-d 315.0) (command "move" sset "" "d" (list ndg1 (- ndg1))))
) ; cond
(setvar "orthomode" ortho)
(setvar "polarang" pang)
(setvar "autosnap" asnp)
) ; defun

(defun rtd (r) (* (/ 180.0 pi) r))

(defun dtr (r) (* (/ n 180.0) pi))

(defun getnudge ()
(if (= ndg1 nil)
(progn
(setq ndg1 20)
) ;_ end of progn
) ;_ end of if
(initget 2)
(setq message (strcat "\nCurrent distance to nudge objects horz/vert <"
(rtos ndg1 2) ">:"))
(setq ndg (getreal message))
(if (/= ndg nil)
(progn
(setq ndg1 ndg)
) ;_ end of progn
) ;_ end of if
) ;_ end of defun
;|«Visual LISP© Format Options»
(200 2 40 2 T "end of " 100 20 0 0 0 T T nil T)
;*** DO NOT add text below the comment! ***|;
Message 11 of 11
Anonymous
in reply to: Anonymous

Well, after some fiddling around, I managed to place the ssget so that it will accept an existing selection set or
prompt if there is none and added an 'initget' to change the nudge distance if desired (to avoid an additional ).
I also pre-selected the centre of the screen for the first pick point to get the rubber-banded direction which works
quite well. I also found that sometimes the 45 degree directions would not move the objects, and decided that it must be
connected with precision in the equality comparison, so I changed it to 'equal and added a precision which seems to have
done the trick.

Here is the routine updated and amended (but no error trapping as yet):

[code]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Nudge - gets selection set, sets polar angle to 45 ;;;
;;; & offers preset nudge distance to accept or change ;;;
;;; Gordon Stephens 28-10-2007 ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun c:nudge-2 ( / ortho pang asnp pntdir1 pntdir2 sset elist angdir) ; angdir-d)
(if (null ndg1) (setq ndg1 20))
(prompt "\nobjects to nudge")
(setq sset (ssget))
(setvar "cmdecho" 0)
(setq pdist (getvar "polardist"))
(setq osm (getvar "osmode"))
(setvar "osmode" 0)
(setq ortho (getvar "orthomode"))
(if (= ortho 1) (setvar "orthomode" 0)) ; if
(setq pang (getvar "polarang"))
(if (/= pang (/ pi 4)) ;EDITED
(setvar "polarang" (/ pi 4))) ;EDITED
(setq asnp (getvar "autosnap"))
(if (/= asnap 47) (setvar "autosnap" 47)) ; if
;(getnudge)
(princ "\nCurrent nudge distance <")(princ ndg1)(princ ">: N to change")
(setvar "polardist" (fix (/ (getvar "viewsize") 10)))

(setq pntdir1 (getvar "viewctr"))

(initget "N")

(setq pntdir2 (getpoint pntdir1 "\npick point in direction of nudge"))

(if (= pntdir2 "N") (progn
(setq ndg1 (getreal "\nNew Nudge distance? "))
(setq pntdir2 (getpoint pntdir1 "\npick point in direction of nudge"))
) ; progn
) ; if

(setq angdir (angle pntdir1 pntdir2))

(cond
((equal angdir 0.0 0.1) (command "move" sset "" "d" (list ndg1 0.0)))
((equal angdir (/ pi 4) 0.1) (command "move" sset "" "d" (list ndg1 ndg1)))
((equal angdir (/ pi 2) 0.1) (command "move" sset "" "d" (list 0.0 ndg1)))
((equal angdir (* 3 (/ pi 4)) 0.1) (command "move" sset "" "d" (list (- ndg1) ndg1)))
((equal angdir pi 0.1) (command "move" sset "" "d" (list (- ndg1) 0.0)))
((equal angdir (* 5 (/ pi 4)) 0.1) (command "move" sset "" "d" (list (- ndg1) (- ndg1))))
((equal angdir (* 3 (/ pi 2)) 0.1) (command "move" sset "" "d" (list 0.0 (- ndg1))))
((equal angdir (* 7 (/ pi 4)) 0.1) (command "move" sset "" "d" (list ndg1 (- ndg1))))
) ; cond
(setvar "orthomode" ortho)
(setvar "polarang" pang)
(setvar "autosnap" asnp)
(setvar "osmode" osm)
(setvar "polardist" pdist)
(princ)
) ; defun


(defun c:nu () (c:nudge-2))
[/code]

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost