29 April 2012

How to draw line in AutoCAD using AutoLISP | Code for draw line in AutoLISP | Draw line using AutoLISP | getpoint in AutoLISP



                            Hi Friends,in this article i will explain about how to draw the line in AutoCAD using AutoLISP.

First of all open the Visual LISP Editor,If you want to know about how to open Visual LISP Editor in AutoCAD.


For drawing the line we have use the “line” command .

Syntax:

(command “line” p1 p2 “”)


In the above command,
Line: line represent the which command we have to use.
P1: p1 is the first point of the line.
P2: p2 is the second point of the line.
“” : It represents the end of the line.

I will explain this using small examples.

Example 1:
(defun c:DrawLINE()
  (setq p1(strcat "0" "," "20"))
  (setq p2(strcat "0" "," "40"))
  (command "line" p1 p2 "")
  )

Save the file as DRAWLINE.LSP
Then  write the below line in the AutoCAD Command prompt.

Command: (load “DrawLINE”)
Command:DRAWLINE

Then the output will like in the below figure.


If you want to draw the line using the picking the points then use the following code.


(defun c:DrawLINE()
  (setq p1(getpoint "\npick the first point"))
  (setq p2(getpoint "\npick the second point"))
  (command "line" p1 p2 "")
  )

In the above program getpoint  is allows the user to select a single point and also to create a point in reference to the total input from the user.

Save the file as DRAWLINE.LSP
Then  write the below line in the AutoCAD Command prompt.


Command: (load “DrawLINE”)
Command:DRAWLINE

Then the output will like in the below figure.


Thanks for reading my blog.I think it will may useful to you.

1 comment:

  1. Thank you! Jesus other websites make you jump through hoops to draw a simple line. That simple straight explanation is what is needed.

    ReplyDelete