TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: SMadsen on October 10, 2003, 08:12:08 AM
-
Mark, in C:PANG (http://theswamp.org/phpBB2/viewtopic.php?t=88) that you posted in Show Your Stuff, the error handling is assumed to be added by whomever copies the function so it's a minor thing, but what if the user changes SNAPANG in a non-WCS UCS?
A lines angle is given in OCS, so it will set SNAPANG to a WCS angle although the user might be in a UCS. ActiveX is cool for many things but as an old fart I can't see why to use it in much too many cases. For instance, in this case you'd either consult the current UCS to get a vector or you'd have to access the lines point arrays (and then the Utility object) in order to transform the angle. Too much hassle when plain ol' AutoLISP does it neatly and shortly :)
Just 2 cents (.. on an ongoing campaign of mine to avoid more work than necessary) :lol:
(defun C:PANGY (/ ent pt1 pt2 entl ang)
(cond ((and (setq ent (car (entsel "\nSelect a line: ")))
(setq pt1 (cdr (assoc 10 (setq entl (entget ent))))
pt2 (cdr (assoc 11 entl)))
)
(setq pt1 (trans pt1 0 1)
pt2 (trans pt2 0 1)
ang (angle pt1 pt2))
(setvar "SNAPANG" ang)
)
)
)
-
Hey now that's cool. I cant break it.
-
Arrggg..... that is one of my many pitfalls. Since working in anything other than WCS is taboo in my industry I tend to forget about it the UCS's.
Stig, as always, nice code. And to prove your are right........
;;; i think this is the correct method, please test.
(defun c:pang (/ utilobj v2l ent vlobj p1 p2)
(vl-load-com)
(setq utilobj (vla-get-Utility
(vla-get-ActiveDocument (vlax-get-acad-object))
)
)
(defun v2l (v)
(vlax-safearray->list (vlax-variant-value v))
)
(if (setq ent (car (entsel "\nSelect a line: ")))
(setq vlobj (vlax-ename->vla-object ent))
)
(if (and vlobj
(= (vlax-get-property vlobj 'ObjectName) "AcDbLine")
)
(progn (setq p1 (vla-TranslateCoordinates
utilobj
(vlax-get-property vlobj 'StartPoint)
acWorld
acUCS
:vlax-false
)
p2 (vla-TranslateCoordinates
utilobj
(vlax-get-property vlobj 'EndPoint)
acWorld
acUCS
:vlax-false
)
)
(setvar 'snapang (angle (v2l p1) (v2l p2)))
) ; else
(command "_.snapang")
) ;if
(princ)
)
-
Nice work :) but what a monster! Heh
-
lmao!
-
Nice work :) but what a monster! Heh
Most definitely. But I had to do it, I just had to.<g>
lmao!
Alright....... where is your version smart a$$........ :D
-
Alright....... where is your version smart a$$........ :D
(defun c:7ang ()
(setq line (entsel "Please select a line: "))
(cond
((= (* 180.0 (/ (getvar "snapang") pi)) 45) (command "snapang" "0"))
((= (* 180.0 (/ (getvar "snapang") pi)) 0) (command "snapang" "45"))
)
(princ "\n2 bad, dummy head. You only get two choices; 45 or zero!")
(princ)
)
-
SWEEEEEEEEEEET I tell ya, if there was an award for code craftsmanship you would have won Se7en.
* yea............ right..........*
-
SWEEEEEEEEEEET I tell ya, if there was an award for code craftsmanship you would have won Se7en.
'Dats right! Now kneel before the lisp god!
Take that Stig!
-
WOW, nice piece of work, Se7en!
*smadsen kneels before the champ*
:lol: :lol: :lol:
-
LMAO!
Ahe, with friends like you guys, who needs enemies?!