Can anyone help me write a lisp routine for a triangle that ask for 3 points using the poly line command. It also with a circle at each vertex with a diameter of 1.5
the 3 points can be random.
thank you
@trevon1191 wrote:
Can anyone help me write a lisp routine for a triangle that ask for 3 points using the poly line command. It also with a circle at each vertex with a diameter of 1.5
the 3 points can be random.
thank you
(defun c:example() (setq pt1 (getpoint "Pick first point: ") pt2 (getpoint "Pick next point: " pt1) pt3 (getpoint "Pick next point: " pt2) ) (command "._pline" pt1 pt2 pt3 "c" "._circle" pt1 "d" 1.5 "._circle" pt2 "d" 1.5 "._circle" pt3 "d" 1.5) )
Don Ireland
Engineering Design Technician
@trevon1191 wrote:
Can anyone help me write a lisp routine for a triangle that ask for 3 points using the poly line command. It also with a circle at each vertex with a diameter of 1.5
....
There are quite a few ways that could be done. The first of these is essentially the same as doni49's, but I had it underway before that went up:
(defun C:TriCirA (/ p1 p2 p3); = Triangle with Circles at corners
(command
"_.pline"
(setq p1 (getpoint "\nFirst corner of Triangle: "))
(setq p2 (getpoint p1 "\nSecond corner of Triangle: "))
(setq p3 (getpoint p2 "\nThird corner of Triangle: "))
"_close"
"_.circle" p1 0.75
"_.circle" p2 0.75
"_.circle" p3 0.75
); command
(princ)
); defun
Or, if you can count on the User not to invoke any options within a Polyline command, but just to give it points, here's another way that uses no variables:
(vl-load-com)
(defun C:TriCirB (); = Triangle with Circles at corners
(command "_.pline" pause pause pause "_close")
(foreach pt
(list
(vlax-curve-getStartPoint (entlast))
(vlax-curve-getPointAtParam (entlast) 1)
(vlax-curve-getPointAtParam (entlast) 2)
); list
(command "_.circle" pt 0.75)
); foreach
(princ)
); defun
Consider object-snap control, command-echo suppression in places, error handling if you change any settings, ensuring the Polyline width setting is 0 if appropriate, undo begin-end wrapping, in TriCirA asking for points first [as doni49 does] so that you can check whether the User picked 3 points and that they're all distinct before proceeding, etc. And it could also be done with (entmake), and so on....
If the purpose of the polyline is just to show a graphical representation of the triangle while the user selects the three points and then the three circles are to be drawn at the vertices, then try out the following:
(defun c:example( / pt pt1 pt2) (setq pt1 (getpoint "Pick first point: ")) (setq pt2 (getpoint "Pick next point: " pt1)) (grdraw pt1 pt2 -1) (princ "Pick the last point: ") (while (/= (car (setq pt (grread 1))) 3) (grdraw pt1 pt2 -1) (grdraw pt1 (cadr pt) -1) (grdraw pt2 (cadr pt) -1) ) (command "._circle" pt1 "d" 1.5 "._circle" pt2 "d" 1.5 "._circle" (cadr pt) "d" 1.5 "._regen") )
Don Ireland
Engineering Design Technician
@Kent1Cooper wrote:
Consider object-snap control, command-echo suppression in places, error handling if you change any settings, ensuring the Polyline width setting is 0 if appropriate, undo begin-end wrapping, in TriCirA asking for points first [as doni49 does] so that you can check whether the User picked 3 points and that they're all distinct before proceeding, etc. And it could also be done with (entmake), and so on....
What Kent said RE error checking and all that. That's all important.
Don Ireland
Engineering Design Technician
I like doni49's code...but perhaps instead of a _.Regen at the end, I would replace it with a _.Redraw
Area Object Link | Attribute Modifier | Dwg Setup | Feet-Inch Calculator | Layer Apps | List on Steroids | VP Zoom Scales
Exchange App Store
When i pull up autolisp editor, I get two windows one being a trace window and the other is a visual lisp console window. Which do i type this in?
It sounds like you're in the Visual Lisp IDE. (Command name is VLIDE).
The CONSOLE is used for writing the code. Sorry -- like I said, I don't typically use the VLIDE. I guess it's got its uses though.
File>New or File>Open
You'll do your editing there.
I for one don't usually even use the VLIDE. I just stick with plain old notepad.
Don Ireland
Engineering Design Technician
So where do I actually type the code in to see if it draws what I need it to draw?
You can save your file and then LOAD it into acad. OR you can paste the code into Acad's command line.
During the development & testing phase, I typically copy/paste it in.
Don Ireland
Engineering Design Technician
Do any of these look right? I have added the points into the code.
(defun c:tri1()
(setq pt1 (getpoint "1,1: ")
pt2 (getpoint "3,5: " pt1)
pt3 (getpoint "6,1: " pt2)
)
(command "._pline" pt1 pt2 pt3 "c" "._circle" pt1 "d" 1.5 "._circle" pt2 "d" 1.5 "._circle" pt3 "d" 1.5)
)
(defun c:example( / pt pt1 pt2)
(setq pt1 (getpoint "1,1: "))
(setq pt2 (getpoint "3,5: " pt1))
(grdraw pt1 pt2 -1)
(princ "6,1: ")
(while (/= (car (setq pt (grread 1))) 3)
(grdraw pt1 pt2 -1)
(grdraw pt1 (cadr pt) -1)
(grdraw pt2 (cadr pt) -1)
)
(command "._circle" pt1 "d" 1.5 "._circle" pt2 "d" 1.5 "._circle" (cadr pt) "d" 1.5 "._regen")
)
I have copy and pasted both of those codes into the command prompt and nothing was drawn on the screen.
@trevon1191 wrote:
So where do I actually type the code in to see if it draws what I need it to draw?
There are instructions about this kind of thing somewhere, but quickly:
Select/highlight a function definition's code here, and hit Ctrl+C to copy it to the Windows Clipboard. Open Notepad or another plain-text editor, and hit Ctrl+V to paste it in. Save that to a file with a .lsp filetype ending, in any folder location you choose. In AutoCAD, type APPLOAD [or just the alias, AP], navigate to the file you just saved, and Load it. If all goes well, you can then type the command name, which is the part following the C: in the (defun... line [in my suggested routines, TriCirA or TriCirB].
I took a screen shot of the lisp being successfully loaded, but nothing was drawn on the screen. The second file is my lisp routine. It is suppose to be a 3 points and uses the poly line command to actually connect the triangle. then 3 circles should be drawn at the vertices of each point with a diameter of 1.5
Did you follow Kent1Cooper's instructions?
After loading the Lisp function you have to execute it from the AutoCAD command line by typing the name of the command following defun c:
which in this case is:
example
Area Object Link | Attribute Modifier | Dwg Setup | Feet-Inch Calculator | Layer Apps | List on Steroids | VP Zoom Scales
Exchange App Store
the lisp routine is called tri1 so I typed that into the commant prompt and it gave me 1,1 which is the first point in the lisp routine.
You think you could run the lisp routine to see if it works and tell me if anything is wrong with it?
I've edited the tri1.lsp with the following changes:
- the command name is no longer called: example. But now the command name matches with the name of the lisp file: tri1
- I've changed the prompts so they are more clear in requesting you to pick the points and not just 1,1
- I've replaced the Regen call at the end with Redraw
enjoy!!!
Area Object Link | Attribute Modifier | Dwg Setup | Feet-Inch Calculator | Layer Apps | List on Steroids | VP Zoom Scales
Exchange App Store