Author Topic: Question for Lee Mac or another code master here: Ortho point with SNAPMODE  (Read 3171 times)

0 Members and 1 Guest are viewing this topic.

PKENEWELL

  • Bull Frog
  • Posts: 320
Hi Lee,

I was trying out a subfunction you posted on your website to translate a point to Ortho. Very nice work!:

Code: [Select]
;;---------------------=={ Ortho Point }==--------------------;;
;;                                                            ;;
;;  Returns a point transformed relative to a basepoint to    ;;
;;  account for activation of Orthmode in the current UCS.    ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  base  - basepoint for transformation (UCS)                ;;
;;  point - point to be transformed (UCS)                     ;;
;;------------------------------------------------------------;;
;;  Returns:  Point (UCS) transformed to account for Ortho    ;;
;;------------------------------------------------------------;;

(defun LM:OrthoPoint ( base point )
  (if (zerop (getvar 'ORTHOMODE)) point
    (apply 'polar
      (cons base
        (
          (lambda ( n / a x z )
            (setq x (- (car   (trans point 0 n)) (car   (trans base 0 n)))
                  z (- (caddr (trans point 0 n)) (caddr (trans base 0 n)))
                  a (angle '(0. 0. 0.) n)
            )
            (if (< (abs z) (abs x)) (list (+ a (/ pi 2.)) x) (list a z))
          )
          (trans (getvar 'UCSXDIR) 0 1)
        )
      )
    )
  )
)

However, I noticed that this code does not account for the value of SNAPANG. I would like to do something to account for SNAPANG, but since I am a bit more mathematically challenged  :ugly:, I do not completely understand your code, nor how to alter it to do so. If you or another here could put me in the right direction, it would be much appreciated.

Thanks!
"When you are asked if you can do a job, tell 'em, 'Certainly I can!' Then get busy and find out how to do it." - Theodore Roosevelt

Crank

  • Water Moccasin
  • Posts: 1503
Re: Question for Lee Mac or another code master here: Ortho point with SNAPMODE
« Reply #1 on: September 30, 2011, 11:28:56 AM »
[...] If you or another here could put me in the right direction, it would be much appreciated.

Thanks!
Stop using SNAPANG: You can rotate the UCS since '87 !  :laugh:
Vault Professional 2023     +     AEC Collection

PKENEWELL

  • Bull Frog
  • Posts: 320
Re: Question for Lee Mac or another code master here: Ortho point with SNAPMODE
« Reply #2 on: September 30, 2011, 11:38:03 AM »
 :kewl: I do realize you can rotate the UCS! I would think a good coder however would try to account for anything someone using his routine might do - such as changing the snap angle... Besides sometimes changing the snapang is alot faster and easier than rotating the UCS if you don't need to.
"When you are asked if you can do a job, tell 'em, 'Certainly I can!' Then get busy and find out how to do it." - Theodore Roosevelt

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Question for Lee Mac or another code master here: Ortho point with SNAPMODE
« Reply #3 on: September 30, 2011, 11:48:06 AM »
At a guess ... though I've not tested this in the least: that last line may need changing:
Code: [Select]
(trans (getvar 'UCSXDIR) 0 1)You might need to incorporate a polar with the value of the snapang.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

cmwade77

  • Swamp Rat
  • Posts: 1447
Re: Question for Lee Mac or another code master here: Ortho point with SNAPMODE
« Reply #4 on: September 30, 2011, 11:50:41 AM »
I actually use the following routine for Polar Snapping, it also allows for Ortho mode as well, the following should account for SnapAng as well:

Code: [Select]
(defun PolarRound (ang deg)
  (* (/ pi (/ 180 (r2d deg))) (fix (/ (+ (/ pi (/ 360 (r2d deg))) ang) (/ pi (/ 180 (r2d deg))))))
)

Here is how I call it:
Code: [Select]
(cond
((= (getvar "orthomode") 1)
(setq SnAng (d2r 90))
)
        ((= (bitcodef (getvar "autosnap") 8) T)
(setq SnAng (getvar "polarang"))
)
        (T
               (setq SnAng 0)
        )
)
(setq SnAng (+ SnAng (getvar "SnapAng")));This was added to allow SnapAng, it has not been fully tested, but should work.
(setq Pt1 (polar Pt (PolarRound Angle SnAng) Dst))

Lee Mac

  • Seagull
  • Posts: 12928
  • London, England
Re: Question for Lee Mac or another code master here: Ortho point with SNAPMODE
« Reply #5 on: September 30, 2011, 12:02:54 PM »
Try something like this:

Code: [Select]
;;---------------------=={ Ortho Point }==--------------------;;
;;                                                            ;;
;;  Returns a point transformed relative to a basepoint to    ;;
;;  account for activation of Orthmode in the current UCS.    ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  base  - basepoint for transformation (UCS)                ;;
;;  point - point to be transformed (UCS)                     ;;
;;------------------------------------------------------------;;
;;  Returns:  Point (UCS) transformed to account for Ortho    ;;
;;------------------------------------------------------------;;

(defun LM:OrthoPoint ( base point )
  (if (zerop (getvar 'ORTHOMODE)) point
    (apply 'polar
      (cons base
        (
          (lambda ( n / a x z )
            (setq x (- (car   (trans point 0 n)) (car   (trans base 0 n)))
                  z (- (caddr (trans point 0 n)) (caddr (trans base 0 n)))
                  a (angle '(0. 0. 0.) n)
            )
            (if (< (abs z) (abs x)) (list (+ a (/ pi 2.)) x) (list a z))
          )
          (polar '(0.0 0.0 0.0) (getvar 'SNAPANG) 1.0)
        )
      )
    )
  )
)

Crank

  • Water Moccasin
  • Posts: 1503
Re: Question for Lee Mac or another code master here: Ortho point with SNAPMODE
« Reply #6 on: September 30, 2011, 12:48:19 PM »
OK, I haven't used lisp for a few years....
But I thing now this doesn't work for a rotated UCS.
How about:
Code: [Select]
(polar '(0. 0. 0.) (+ (angle '(0. 0. 0.)(getvar 'UCSXDIR))(getvar 'SNAPANG)) 1.0)
Vault Professional 2023     +     AEC Collection

Lee Mac

  • Seagull
  • Posts: 12928
  • London, England
Re: Question for Lee Mac or another code master here: Ortho point with SNAPMODE
« Reply #7 on: September 30, 2011, 01:16:25 PM »
But I thing now this doesn't work for a rotated UCS.

Did you try it Crank?

PKENEWELL

  • Bull Frog
  • Posts: 320
Re: Question for Lee Mac or another code master here: Ortho point with SNAPMODE
« Reply #8 on: September 30, 2011, 01:20:18 PM »
But I thing now this doesn't work for a rotated UCS.

Did you try it Crank?

Lee is Correct. I have tested it with both the UCS and snap angle set to different values and all work! Thanks to all however for the replies!  :lol:
« Last Edit: September 30, 2011, 01:26:51 PM by PKENEWELL »
"When you are asked if you can do a job, tell 'em, 'Certainly I can!' Then get busy and find out how to do it." - Theodore Roosevelt

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Question for Lee Mac or another code master here: Ortho point with SNAPMODE
« Reply #9 on: September 30, 2011, 01:53:51 PM »
Just a question: How would this perform if your UCS is rotated around something else than the Z axis?

Edit: Oh! Hang on ... the result is only a 2D point in any case  :-[
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

PKENEWELL

  • Bull Frog
  • Posts: 320
Re: Question for Lee Mac or another code master here: Ortho point with SNAPMODE
« Reply #10 on: September 30, 2011, 02:17:23 PM »
Just a question: How would this perform if your UCS is rotated around something else than the Z axis?

Edit: Oh! Hang on ... the result is only a 2D point in any case  :-[

For one of the tests, I orbited to some arbitrary viewing angle, then set the UCS to View, and then changed the snapang. Lee's code still worked properly. At least for what I am working on, at 3D ortho is not necessary.
"When you are asked if you can do a job, tell 'em, 'Certainly I can!' Then get busy and find out how to do it." - Theodore Roosevelt