TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: johnshar123xx on November 30, 2009, 02:24:19 PM

Title: Tough Questions - Override "Z" Elevation Lisp
Post by: johnshar123xx on November 30, 2009, 02:24:19 PM
Tough Questions - Override "Z" Elevation Lisp


AutoCAD 2007
I have a quite a few tough questions/requests and I am currently looking for some lisps to solve them.  I have been doing some searching online to find the lisps I need, and although I have been able to find some stuff, I still have some things that I can't seem to find exactly what I am looking for.  I would like to take the opportunity ahead of time to thank every who views my questions and for any help that is given.

Wondering if anyone knows of an override that will allow you to temporarily turn off "Z" elevations set to lines in your drawing.
For example, lets say you have contour lines in a site plan that have "Z" elevations set to them.  If you try to get a 2d distance from line to line, the distance command factors in the "Z" elevation giving you an inaccurate distance reading.
Another example, when you want to draw a 2D line and you snap your line to a contour line that has a "Z" elevation set to it, the line in essence snaps to the "Z" elevation of the line making it 3D as opposed to 2D.
Does anyone know of a variable or a lisp that will allow you to temporarily override the "Z" elevations in a drawing?
Title: Re: Tough Questions - Override "Z" Elevation Lisp
Post by: Lee Mac on November 30, 2009, 02:29:29 PM
Well.. FLATTEN.. but thats the point of no return...  :wink:
Title: Re: Tough Questions - Override "Z" Elevation Lisp
Post by: Matt__W on November 30, 2009, 02:34:24 PM
Just thinking out loud....

You can write a LSP that allows the user to select two points (I.E. your different contour lines) and then from those two points extract their X & Y values.  Then create a list for the first point using the X & Y value extracted in addition to adding 0 for the Z elevation.  Do the same for point 2, then draw a line from point 1 to point 2.

I haven't done LSP in quite some time now, but I've got some code kicking around (unless someone beats me to it).
Title: Re: Tough Questions - Override "Z" Elevation Lisp
Post by: Maverick® on November 30, 2009, 02:37:51 PM
Wow.  "Tough questions" here, on Cadtutor, and on Augi.  That oughta get 'er done.
Title: Re: Tough Questions - Override "Z" Elevation Lisp
Post by: Matt__W on November 30, 2009, 02:38:57 PM
I think it's called "covering your bases".   :wink:
Title: Re: Tough Questions - Override "Z" Elevation Lisp
Post by: Lee Mac on November 30, 2009, 02:47:33 PM
Just thinking out loud....

You can write a LSP that allows the user to select two points (I.E. your different contour lines) and then from those two points extract their X & Y values.  Then create a list for the first point using the X & Y value extracted in addition to adding 0 for the Z elevation.  Do the same for point 2, then draw a line from point 1 to point 2.

I haven't done LSP in quite some time now, but I've got some code kicking around (unless someone beats me to it).

Like this?

Code: [Select]
(defun c:2DDist (/ 2dp x1 lst x2 d)

  (defun 2dp (p) (list (car p) (cadr p) 0.))
 
  (if (setq x1 (getpoint "\nSelect First Point: "))
    (progn
      (setq lst (cons (2dp x1) lst) d 0.)
      (while (setq x2 (getpoint (car lst) "\nSelect Next Point: "))
        (setq lst (cons (2dp x2) lst) d (+ d (distance (car lst) (cadr lst))))) 
      (princ (strcat "\n<< 2D Distance: " (rtos d 2 3) " >>"))))
 
  (princ))
Title: Re: Tough Questions - Override "Z" Elevation Lisp
Post by: Chris on November 30, 2009, 03:20:37 PM
I think it's called "covering your bases".   :wink:
yeah, but the questions here are different than the ones at AUGI
Title: Re: Tough Questions - Override "Z" Elevation Lisp
Post by: Lee Mac on November 30, 2009, 03:24:47 PM
I think it's called "covering your bases".   :wink:
yeah, but the questions here are different than the ones at AUGI

Still.. they are identical to those at CADTutor...  :wink:
Title: Re: Tough Questions - Override "Z" Elevation Lisp
Post by: CAB on November 30, 2009, 03:34:04 PM
Another way. 8-)
Code: [Select]
(defun c:2DDist (/ x1 x2 d)
  (if (setq x1 (getpoint "\nSelect First Point: "))
    (progn
      (while (setq x2 (getpoint x1 "\nSelect Next Point: "))
        (setq d   (sqrt (+ (expt (- (car x2) (car x1))2) (expt (- (cadr x2) (cadr x1))2) )))
        (princ (strcat "\n<< 2D Distance: " (rtos d 2 3) " >>"))
      )
    )
  )
  (princ)
)
Title: Re: Tough Questions - Override "Z" Elevation Lisp
Post by: VovKa on November 30, 2009, 04:04:31 PM
Code: [Select]
(initget 64)
(getdist)
Title: Re: Tough Questions - Override "Z" Elevation Lisp
Post by: Lee Mac on November 30, 2009, 04:19:45 PM
Code: [Select]
(initget 64)
(getdist)


 :-D
Title: Re: Tough Questions - Override "Z" Elevation Lisp
Post by: Lee Mac on November 30, 2009, 04:20:46 PM
Couldn't resist:

Code: [Select]
(defun c:2DDist (/ 2dp x1 lst x2 d gr)

  (defun 2dp (p) (list (car p) (cadr p) 0.))
 
  (if (setq x1 (getpoint "\nSelect First Point: "))
    (progn
      (setq lst (cons (2dp x1) lst) d 0. gr lst)
      (while (setq x2 (getpoint (car lst) "\nSelect Next Point: "))
        (setq lst (cons (2dp x2) lst) d (+ d (distance (car lst) (cadr lst)))
              gr  (append gr (if (< 1 (length gr)) (list (last gr) (car lst)) (list (car lst)))))
        (and (< 1 (length gr)) (grvecs (cons -3 gr))))
      (princ (strcat "\n<< 2D Distance: " (rtos d 2 3) " >>"))))
 
  (princ))

Title: Re: Tough Questions - Override "Z" Elevation Lisp
Post by: Lee Mac on November 30, 2009, 04:24:29 PM
Perhaps better programming:

Code: [Select]
(defun c:2DDist (/ 2dp x1 lst x2 d)

  (defun 2dp (p) (list (car p) (cadr p) 0.))
 
  (if (setq x1 (getpoint "\nSelect First Point: "))
    (progn
      (setq lst (cons (2dp x1) lst) d 0.)
      (while (setq x2 (getpoint (car lst) "\nSelect Next Point: "))
        (setq lst (cons (2dp x2) lst) d (+ d (distance (car lst) (cadr lst))))
        (apply 'grvecs
           (list
             (cons '-3
               (apply 'append
                 (mapcar 'list (reverse (cdr lst)) (cdr (reverse lst))))))))
      (princ (strcat "\n<< 2D Distance: " (rtos d 2 3) " >>"))))
 
  (princ))
Title: Re: Tough Questions - Override "Z" Elevation Lisp
Post by: CHulse on November 30, 2009, 07:14:45 PM
What about OSNAPZ?
Title: Re: Tough Questions - Override "Z" Elevation Lisp
Post by: Matt__W on December 01, 2009, 08:07:40 AM
What about OSNAPZ?
Why do you have to make it so easy?   :-D


I forgot about that one!  Is that just for the verticals or does it work in Vanilla, too?
Title: Re: Tough Questions - Override "Z" Elevation Lisp
Post by: Keith™ on December 01, 2009, 09:12:21 AM
Well, there are others posting solutions so I figured what the heck ... I'll add my 2p

Code: [Select]
(defun dist2D (pt1 pt2)
  (apply 'distance
    (mapcar
      '(lambda (x)
        (if (= (length x) 3)
         (reverse (cdr (reverse x)))
         x
        )
       )
       (list pt1 pt2)
    )
  )
)
Title: Re: Tough Questions - Override "Z" Elevation Lisp
Post by: alanjt on December 01, 2009, 09:15:08 AM
http://www.theswamp.org/index.php?topic=30416.0
Title: Re: Tough Questions - Override "Z" Elevation Lisp
Post by: johnshar123xx on December 01, 2009, 04:43:45 PM
Wow, I thank you all for taking the time to help me out with this and any of my other questions, it is greatly appreciated, it appears as if OSNAPZ does the trick.  I realize that some of my requests are rather complex, I wish I had the ability to write lisps myself, I am looking into it, but the lisps users are supplying to answer my questions help me to get an idea as to what it takes to create them.  I still have quite a few questions, so thanks again ahead of time to those willing to lend their time and knowledge to help.