Author Topic: Setting snapang  (Read 7294 times)

0 Members and 1 Guest are viewing this topic.

SMadsen

  • Guest
Setting snapang
« on: October 10, 2003, 08:12:08 AM »
Mark, in C:PANG 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)
        )
  )
)

JohnK

  • Administrator
  • Seagull
  • Posts: 10157
Setting snapang
« Reply #1 on: October 10, 2003, 09:43:08 AM »
Hey now that's cool. I cant break it.
TheSwamp.org (serving the CAD community since 2003)

Donate to TheSwamp.org

Mark

  • Custom Title
  • Seagull
  • Posts: 28725
Setting snapang
« Reply #2 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)
  )
TheSwamp.org  (serving the CAD community since 2003)

SMadsen

  • Guest
Setting snapang
« Reply #3 on: October 10, 2003, 11:04:50 AM »
Nice work :)  but what a monster! Heh

JohnK

  • Administrator
  • Seagull
  • Posts: 10157
Setting snapang
« Reply #4 on: October 10, 2003, 11:11:11 AM »
lmao!
TheSwamp.org (serving the CAD community since 2003)

Donate to TheSwamp.org

Mark

  • Custom Title
  • Seagull
  • Posts: 28725
Setting snapang
« Reply #5 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
TheSwamp.org  (serving the CAD community since 2003)

JohnK

  • Administrator
  • Seagull
  • Posts: 10157
Setting snapang
« Reply #6 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)
)
TheSwamp.org (serving the CAD community since 2003)

Donate to TheSwamp.org

Mark

  • Custom Title
  • Seagull
  • Posts: 28725
Setting snapang
« Reply #7 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..........*
TheSwamp.org  (serving the CAD community since 2003)

JohnK

  • Administrator
  • Seagull
  • Posts: 10157
Setting snapang
« Reply #8 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!
TheSwamp.org (serving the CAD community since 2003)

Donate to TheSwamp.org

SMadsen

  • Guest
Setting snapang
« Reply #9 on: October 10, 2003, 12:21:31 PM »
WOW, nice piece of work, Se7en!

*smadsen kneels before the champ*

:lol:  :lol:  :lol:

JohnK

  • Administrator
  • Seagull
  • Posts: 10157
Setting snapang
« Reply #10 on: October 10, 2003, 12:28:31 PM »
LMAO!

Ahe, with friends like you guys, who needs enemies?!
TheSwamp.org (serving the CAD community since 2003)

Donate to TheSwamp.org