Our Friends: Leaflet Printing , Presented by: Talia Cad Software

Sign In

Subscribe

Subscribe to Daily Autocad.


Feb 05
Thursday
AutoLISP, Download, Modify
A 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
Fig. 1.

First of all, let’s take a look at MIRROR command, which is very practical:

Command : MIRROR
Select objects: 1 found
( Let’s choose the vertical line )
Specify first point of mirror line: ( Fig. 2 )

Fig.2
Fig. 2.

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

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.

Viewed 10,009 times so far... This week: 67 Today: 2 Latest: 5 July 2009, 0:22

Post Tags: , ,

9 Responses to “ A Simple AutoLISP Application for Constructing Center Lines. ”
  1. 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

  2. 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

  3. 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.

  4. Fakhroddin Abolghasemi

    Apr 24, 2007
    Reply

    would you send vlisp lessons to my email.
    I’m very intrested to these lessons.
    thank you very much.

  5. I only use this:

    (DEFUN C:CLINES () (COMMAND “MIRROR” PAUSE “” “MID” “@” “@10

  6. why can’t i show the rest of the code: angle sign 45″ “”))

  7. 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

  8. 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

  9. 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


Post a Comment



All content and source © 2008 Daily Autocad | News Plus wordpress theme brought to you by Zidalgo.