Thursday
AutoLISP, Download, ModifyA Simple AutoLISP Application for Constructing Center Lines.
All of us suffer clogging while drawing a center lines that is made up of only two lines. Because, the hard part is not to draw those two lines, but to attach one over another in the middle. Most of the time, we draw the second line outside and move the first one by holding from its midpoint onto the second one. Second difficult thing is that second line must have the same length as the first one. Thus, in this article, I will explain how to do this in a practical way and also we will see a AutoLISP application that works with the same principle.

Fig. 1.
First of all, let’s take a look at MIRROR command, which is very practical:
Command : MIRROR( Let’s choose the vertical line )
Select objects: 1 found
Specify first point of mirror line:( Fig. 2 )

Fig. 2.
Specify second point of mirror line: @10<45( Fig. 3 )

Fig. 3.
Erase source objects? [Yes/No] :( press ENTER )
If we show the mirror line as 45° as shown in Fig.3, then we make a copy so that two lines have 90° between each other. This is the most practical way you can do this in AutoCAD (Except CENTERLINE in DIM command ). Of course, we can do this much more practical. By using the AutoLISP example, I am just about to show, on the condition to work only with the lines, we can create a set of axis by just one click. AutoLISP code is given in Fig. 4. Readers of AutoLISP pages can include their own modifications by following the comments.
; <----------------------- CL ---------------------------> ; Copy And Mirror with 45 degrees ; This utulity mirrors the selected line 90 degrees and ; takes a copy of it. This will convert a single line to ; center lines. ; ; (c) 1994-2006 Taliasoft Ltd. www.taliasoft.com ; Written by Erhan TOKER ; ---------------------------------------------------------> (defun c:clines(/ p10 p11 mpt x1 y1 z1 d1 a1 p2) (setq _objtype nil) ; reset _objtype global variable (setq _objtype "_") ;Check if the selected object is LINE or not! (while (/= _objtype "LINE") (get_obj "\nSelect a LINE:") ) ;Calculate start and end point of seelected line... (setq p10 (cdr (assoc 10 _entlst)) p11 (cdr (assoc 11 _entlst)) ) ;Calculate midpoint of selected line (setq x1 (/ (+ (car p10) (car p11)) 2.0) y1 (/ (+ (cadr p10) (cadr p11)) 2.0) z1 (/ (+ (caddr p10) (caddr p11)) 2.0) mpt (list x1 y1 z1) ) ;Calculate length (setq d1 (distance p10 p11)) ;Calculate angle in ( RADIANS ) (setq a1 (angle p10 p11)) ;Second point of center line (setq p2 (polar mpt (+ a1 (/ pi 4.0)) d1)) ;Execute MIRROR command (command "_MIRROR" _ename "" mpt p2 "N") (princ) ) ; Function (get_obj) ; Returns type and pickpoint of selected entity ; ---------------------------------------------------------> ; GLOBALS ; _objtype : STRING, object's DXF name ; e.g. "LINE", "ARC", "INSERT" ; _objpick : POINT, object's picked point ;----------------------------------------------------------> (defun get_obj (prmt / o1 e1 ent1) (setq o1 (entsel prmt) e1 (car o1) ent1 (entget e1) _objtype (cdr (assoc 0 ent1)) _objpick (cadr o1) _entlst ent1 _ename e1 ) ) (princ)
Fig. 4 – AutoLISP code for drawing centerlines.
Write this code yourself or download centerlines.lsp from our download page and load. Then enter “clines” from command line. Program will ask you to select a LINE and wait until you select a LINE or pressing ESC. Hope you like this utility. Bye…
Registered users can dowload program from fallowing link.
centerlines.zip (921 bytes, 203 hits)
You need to be a registered user to download this file.
Post Tags: AutoLISP, Download, Programming
Related Posts
Popular
- Hip tip: Increasing view resolution with VIEWRES system variable
07/03/2009 04:39 am
7 Comments - Sirince – IZMIR
07/02/2009 11:02 am
1 Comment - Visual LISP: Programming user interfaces with OpenDCL
07/01/2009 10:15 pm
10 Comments - 3D Modeling 7: EXTRUDE
06/30/2009 02:14 pm
10 Comments - Ask DailyAutoCAD: Which Notebook to Buy?
06/30/2009 12:17 pm
1 Comment
Featured Articles
- AutoCAD 2009 Update 3 Released
- Speed Up As AutoCAD 2009 Ribbon Menu Helps You!
- MEP Analysis Extension for AutoCAD MEP extended to March 31, 2009
- Recap of AutoCAD-related technologies on Autodesk Labs
- Technology Preview of MEP Analysis Extension extended to 12/31/08
- Autodesk Labs: Forward and Backward utility for AutoCAD
|


Mar 20, 2007
Reply
I just draw the first center line then make a copy of itself by copy-select midpoint-and the type in @0,0 enter. Then select the line and the center grip. Go to the rotate command.Type in 90 degrees and enter.
this rotates the “top” line. then you have two line the same length attached at the center!
Richard
Mar 21, 2007
Reply
The way that Richard has suggested works and was my first guess but as i am just a rookie and need all the help i can get with autolisp i thank you immeasurably Erhan.
Rick
Mar 22, 2007
Reply
Richard,
Thanks for comment. Your method is OK. We’re just trying to explain LISP infrastructure. I’m sure that CLINES command defined in this rouitne is the shortest way to do it.
Apr 24, 2007
Reply
would you send vlisp lessons to my email.
I’m very intrested to these lessons.
thank you very much.
Apr 26, 2007
Reply
I only use this:
(DEFUN C:CLINES () (COMMAND “MIRROR” PAUSE “” “MID” “@” “@10
Apr 26, 2007
Reply
why can’t i show the rest of the code: angle sign 45″ “”))
Sep 4, 2008
Reply
Hi,
I need to delete all the radius and lines greater than 2 mm in a drawing layout LISP program.
Can you help?
Thanks,
Ilan
Sep 4, 2008
Reply
Hello Ilan,
You do not need to have a LISP macro to do this. You can do this by QUICKSELECT. Please see the article : http://www.dailyautocad.com/autocad/a-practical-way-of-selecting-entities-quickselect/ .
Thanks for commenting
Feb 14, 2009
Reply
Looks quite effective. It solves problem of drawing exact equal length lines. Specially when you are drawing center line for bolts hole etc. It saves some amount of time .
Tom
http://www.indovance.com