Lisp to draw right angle lines?
Has anyone seen a lisp like this? I know someone in my local user group wrote one, but I dont have his contact info. One it would come in handy, but more importantly I want to try to write a different type of routine but use that as a guide and starting point (I am new at this). All the routine did was allow the user to pick to points and it would draw a line between them, always going horizontally first. It was used to connect points in wiring schematics. Any help would be appreciated
RE: Lisp to draw right angle lines?
Like this?
Code:
(defun c:TwoPoints (/ lstPoint1 lstPoint2)
(setq lstPoint1 (getpoint "\nSelect first point: ")
lstPoint2 (getpoint "\nSelect Second point: ")
)
(command "pline" lstPoint1(list (car lstPoint2) (cadr lstPoint1)) lstPoint2 "" )
)
RE: Lisp to draw right angle lines?
...or like this
Code:
(defun c:OrthoLine (/ Pkt1 Pkt2 )
(setq Pkt1 (getpoint "Start point: ") )
(while (setq Pkt2 (getpoint " next: ") )
(command "._line" Pkt1 (list (car Pkt2 ) (cadr Pkt1 )) Pkt2 )
(command )
(setq Pkt1 Pkt2 Pkt2 nil )
)
(princ)
)
: ) Happy Computing !
kennet
RE: Lisp to draw right angle lines?
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
RE: Lisp to draw right angle lines?
why did you put this line in the code
Quote:
Originally Posted by kennet.sjoberg
...or like this
Code:
(setq Pkt1 Pkt2 Pkt2 nil )
kennet
when this line in your code will set Pkt1 and Pkt2 to nill when the function exits
Quote:
Originally Posted by kennet.sjoberg
...or like this
Code:
(defun c:OrthoLine (/ Pkt1 Pkt2 )
kennet
RE: Lisp to draw right angle lines?
jwanstaett,
He is changing the variable to nil to continue the command until the user responds with an enter command to end the routine. Setting Pkt2 to nil does not really have any effect though. If you respond to a getpoint with an enter it would return a nil, which would set Pkt2 to nil anyway.
Code:
(defun c:OrthoLine (/ Pkt1 Pkt2 )
(setq Pkt1 (getpoint "Start point: ") )
(while (setq Pkt2 (getpoint " next: ") )
(command "._line" Pkt1 (list (car Pkt2 ) (cadr Pkt1 )) Pkt2 )
(command )
(setq Pkt1 Pkt2 Pkt2 nil )
)
(princ)
)
You could also add the Pkt1 to the following line to allow for the rubberband effect
Code:
(while (setq Pkt2 (getpoint Pkt1 " next: ") )
RE: Lisp to draw right angle lines?
Quote:
Originally Posted by jwanstaett
why did you put this line in the code ...
I can see that there is an answer already, thank you Richard.
The only reason to the Pkt switch is to let the command loop and continue from the previous Pkt.
: ) Happy Computing !
kennet
RE: Lisp to draw right angle lines?
I tried the first lisp wrote and it was perfect you guys are awesome. Someday, I will figure out how to write them!