TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: tcdan on August 01, 2005, 02:00:07 AM
-
Newbies will be able to do this as well as advanced LISPers.
Write a line of code (or more) that will set the NEArest object snap without modifying any of the other object snap settings.
It's a fun little math excercise :)
-
(SETVAR "OSMODE" (BOOLE 6 (GETVAR "OSMODE") 512)); on/off
(SETVAR "OSMODE" (- (GETVAR "OSMODE") -512 (LOGAND (GETVAR "OSMODE") 512))); on
or:
(SETVAR "OSMODE" (+ (LOGAND (GETVAR "OSMODE") 31231) 512)); on
-
... Write a line of code that will set the NEArest object snap without modifying any of the other object snap settings ...
(setvar "osmode"
(logior 512
(getvar "osmode")
)
)
-
Wow that's great! I knew you guys could come up with a faster way than this:
(setq snaps (getvar "osmode"))
(if ( = (rem (/ snaps 512) 2) 0) (setvar "osmode" (+ 512 snaps))) ;; set 'nearest' snap
-
Crank's first one's my personal favorite. It sets and unsets it. Boole is Coole.
-
Here is a neat little trick that doesn't require setting osnaps ... you can override it in lisp to the one you require.
(setq pt (osnap (getpoint "\nSelect point") "_nearest"))
-
Here is a neat little trick that doesn't require setting osnaps ... you can override it in lisp to the one you require.
(setq pt (osnap (getpoint "\nSelect point") "_nearest"))
That's probably the best solution. You don't have to restore the osnap when you finish the function.
But if you do want to change the OSMODE then it's just an OR-operation, so this should also work:
(SETVAR "OSMODE" (BOOLE 7 (GETVAR "OSMODE") 512)); on
-
(osnap pnt "_nea") fails on some objects. Therefore I use this solution:
(defun MeEntSel ( / CurEnt CurObj NeaPnt)
(if (setq CurEnt (entsel "\nSelect object: "))
(progn
(setq CurObj (vlax-ename->vla-object (car CurEnt))
NeaPnt (if (vl-position
(vla-get-ObjectName CurObj)
'("AcDbArc" "AcDbCircle" "AcDb2dPolyline")
)
(vlax-curve-getClosestPointToProjection
CurObj
(trans (cadr CurEnt) 1 0)
(trans (getvar "VIEWDIR") 1 0 1)
)
(osnap (cadr CurEnt) "_NEA")
)
)
(list (car CurEnt) (trans NeaPnt 0 1))
)
)
)