TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: SMadsen on October 10, 2003, 08:12:08 AM

Title: Setting snapang
Post 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:

Code: [Select]
(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)
        )
  )
)
Title: Setting snapang
Post by: JohnK on October 10, 2003, 09:43:08 AM
Hey now that's cool. I cant break it.
Title: Setting snapang
Post by: Mark on October 10, 2003, 10:46:10 AM
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........

Code: [Select]

;;; 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)
  )
Title: Setting snapang
Post by: SMadsen on October 10, 2003, 11:04:50 AM
Nice work :)  but what a monster! Heh
Title: Setting snapang
Post by: JohnK on October 10, 2003, 11:11:11 AM
lmao!
Title: Setting snapang
Post by: Mark on October 10, 2003, 11:20:09 AM
Quote from: SMadsen
Nice work :)  but what a monster! Heh

Most definitely. But I had to do it, I just had to.<g>

Quote from: Se7en
lmao!

Alright....... where is your version smart a$$........ :D
Title: Setting snapang
Post by: JohnK on October 10, 2003, 11:49:34 AM
Quote from: Mark Thomas
Alright....... where is your version smart a$$........ :D


Code: [Select]
(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)
)
Title: Setting snapang
Post by: Mark on October 10, 2003, 12:00:37 PM
SWEEEEEEEEEEET I tell ya, if there was an award for code craftsmanship you would have won Se7en.






















* yea............ right..........*
Title: Setting snapang
Post by: JohnK on October 10, 2003, 12:07:48 PM
Quote from: Mark Thomas
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!
Title: Setting snapang
Post by: SMadsen on October 10, 2003, 12:21:31 PM
WOW, nice piece of work, Se7en!

*smadsen kneels before the champ*

:lol:  :lol:  :lol:
Title: Setting snapang
Post by: JohnK on October 10, 2003, 12:28:31 PM
LMAO!

Ahe, with friends like you guys, who needs enemies?!