this code will do it using ActiveX
it add two commands to your system
doline and dopline
the doline drawing two lines
the dopline draw it using LIGHTWEIGHTPOLYLINE
the commands call the function myline and mypline
I have done it this way so if in other programs you have the points and need to drawing
the line all you need to do is call the function
Code:
;;Before you can use ActiveX functions with AutoLISP,
;;you need to load the supporting code that enables these functions.
;;Issue the following function call to load ActiveX support:
(vl-load-com) ;This should be the fisrt line in all
;AutoLisp programs that use Activex
;;function (myline mypt1 mypt2) draw two lines
;;the first line go form mypt1 to the y of mypt1 and the x of mypt2
;;the 2nd line go form the y of mypt1 and the x of mypt2 to mypt2
;;the function dose not ask for the point so it can be called
;;from other programs
(defun myline (mypt1 mypt2 / mypt3
acadObject acadDocument mSpace
myobject
)
;;After loading the ActiveX support functions, the first step in
;;accessing AutoCAD objects is to establish a connection to the
;;AutoCAD Application object. Use the vlax-get-acad-object function
;;to establish this connection.
;;The following AutoLISP command returns the AutoCAD Application.
(setq acadObject (vlax-get-acad-object))
;;Following the AutoCAD object model hierarchy, the ActiveDocument
;;property of the Application object leads you to a Document object.
;;This Document object represents the current AutoCAD drawing.
;;The following AutoLISP command returns the active document:
(setq acadDocument (vla-get-ActiveDocument acadObject))
;;The Document object has many properties. Access to non-graphical
;;objects (layers, linetypes, and groups, for example) is provided
;;through like-named properties such as Layers, Linetypes, and;;
;;Groups. To get to the graphical objects in the AutoCAD drawing,
;;you must access either the drawing's model space
;;(through the ModelSpace property) or
;;paper space (through the PaperSpace property).
;;The following AutoLISP command returns the ModelSpace
(setq mSpace (vla-get-ModelSpace acadDocument))
;;set up point three
(setq mypt3 (list (car mypt2) (cadr mypt1) (caddr mypt1)))
;;add the first line
(setq myobject (vla-addline
mspace
(vlax-3d-point mypt1)
(vlax-3d-point mypt3)
) ;_ end of vla-addline
) ;_ end of setq
;;if you need to set properties such as Layers, Linetypes, and Groups for
;;line one do it here
;;add the 2nd line
(setq myobject (vla-addline
mspace
(vlax-3d-point mypt3)
(vlax-3d-point mypt2)
) ;_ end of vla-addline
) ;_ end of setq
;;if you need to set properties such as Layers, Linetypes, and Groups for
;;line two do it here
) ;_ end of defun
;;command doline
;;Ask for the two line point and call myline
(defun c:doline (/ mypt1 mypt2)
(setq mypt1 (getpoint "Enter First Point"))
(setq mypt2 (getpoint "Enter 2ND Point" mypt1))
(myline mypt1 mypt2)
) ;_ end of defun
;;how do it useing LIGHTWEIGHTPOLYLINE
(defun mypline (mypt1 mypt2 / myarray
acadObject acadDocument mSpace
myobject
)
(setq acadObject (vlax-get-acad-object))
(setq acadDocument (vla-get-ActiveDocument acadObject))
(setq mSpace (vla-get-ModelSpace acadDocument))
;;set up point the array of points
(setq myarray (vlax-make-safearray vlax-vbDouble '(0 . 5)))
(vlax-safearray-put-element myarray 0 (car mypt1))
(vlax-safearray-put-element myarray 1 (cadr mypt1))
(vlax-safearray-put-element myarray 2 (car mypt2))
(vlax-safearray-put-element myarray 3 (cadr mypt1))
(vlax-safearray-put-element myarray 4 (car mypt2))
(vlax-safearray-put-element myarray 5 (cadr mypt2))
;;add the LIGHTWEIGHTPOLYLINE
(setq myobject (vla-addLIGHTWEIGHTPOLYLINE mspace myarray))
;;if you need to set properties such as Layers, Linetypes, and Groups for
;;pline do it here using myobject
) ;_ end of defun
;;command dopline do it using LIGHTWEIGHTPOLYLINE
;;Ask for the two line point and call myline
(defun c:dopline (/ mypt1 mypt2)
(setq mypt1 (getpoint "Enter First Point"))
(setq mypt2 (getpoint "Enter 2ND Point" mypt1))
(mypline mypt1 mypt2)
) ;_ end of defun