[Search tip detail and code files using keywords, tip number, author name, etc ]
Draw a 2D Line with LISP
Tip# 4152 By R. Clayton Harrison On 01-Jul-2013
Rated By 0 users
Categories : Linear Objects
Software type : AutoCAD 2014
Rename File To : No Files to download.
Draw lines and polylines and keep them in two dimensions.

R. Clayton Harrison, PE, shares a few LISP routines in response to CAD Tip No. 4129 that will help draw lines and polylines and keep them in two dimensions.

"If you just need to draw 2D lines when snapping to points or other entities that have a Z elevation other than zero, you can use this LISP routine to accomplish that.

    (defun c:2d (/ p1 p2)
      (setq p1 (getpoint " From Point: "))
      (setq p2 (Getpoint " To Point: " p1))
      (command "LINE" ".xy" p1 0.0 ".xy" p2 0.0 "")
      (setq p1 p2)
         (while (setq p2 (getpoint " To Point: " p1))
           (command "LINE" ".xy" p1 0.0 ".xy" p2 0.0 "")
           (setq p1 p2)
    );end defun

"To draw a PLINE at elevation 0: If you need a polyline at Z=0, I would suggest using the Point Filter .xy. When prompted for a point, type .xy then press Enter; apply the osnap that you want and pick the point. AutoCAD will respond with (need Z): type 0 and press Enter."

Notes from Cadalyst tip reviewer Brian Benton: It can be a pain to work in a mixed environment of 2D and 3D objects. Sometimes it is too time-consuming to fully convert from one to another. These routines and tips can help you work in this hybrid state of data.


Average Rating:

User comments
Comment by Grutter,Michael
Posted on 2013-07-01 20:37:11
These lisp routines can be very useful if they actually save time or keystrokes. Sorry, I'm don't really see the savings in this one. I've had this same problem of working with 2D entities that may get off track as far as the "z" coordinate goes or snapping to 3D objects in an ortho view that just don't work out, but I find this simple command added to the Acaddoc.lsp file to be invaluable, quick to execute and just as easily reversible when working in 3D. (defun c:zc () (setvar "osnapz" (abs (1- (getvar "osnapz"))))) It is a simple toggle of the OSNAPZ system variable. Once it is toggled to "off" you can pick osnap locations in any "z" coordinate and the resulting "pick point" will be Z=0 (zero) unless you are working on a different "z" plane by changing the ELEVation to either a positive or negative non-zero value.
Comment by Grutter,Michael
Posted on 2013-07-01 20:48:19
OOps, Second sentence: Sorry, I don't... D@mn autocorrect anyway!!!
Comment by Azbell,Nicholas
Posted on 2013-07-02 10:09:40
Pretty sure the original tip is the best way to go.
Comment by Alexander,Ron
Posted on 2013-07-05 13:38:14
a similar command I ran into using Land Development desktop I believe was flatten all z coordinates. I am not sue if it is still around though.
Comment by Jacobsen,Don
Posted on 2014-02-21 10:07:52
Just to make this a bit more user friendly, I added this to hte end of the routine so it dsplays a message showing you what the OsnapZ is set to: (princ (strcat " Osnapz set to" (getvar "osnapz"))) The entire routine looks like this: (defun c:zc () (setvar "osnapz" (abs (1- (getvar "osnapz")))) (princ (strcat " Osnapz set to: " (itoa (getvar "osnapz"))))(princ))