TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Sam on May 27, 2016, 02:16:19 PM
-
DEAR ALL
WHAT IS WRONG IN CODE ???
AUTOCAD 2016, WINDOWS 10, 64 BIT
(defun c:retan (/ pl p2 p3 p4)
(setq pl (getpoint "\nfirst corner of rectangle: "))
(setq p3 (getcorner "\nsecond corner of rectangle: "))
(setq p2 (list (car pl)(cadr p3)))
(setq p4 (list (car p3)(cadr pl)))
(command "line" pl p2 p3 p4 "c")
(princ)
)
Command: RETAN
first corner of rectangle: ; error: base point is required
http://www.afralisp.net/autolisp/tutorials/quick-start.php (http://www.afralisp.net/autolisp/tutorials/quick-start.php)
-
Try adding _non and the base point for p3. Also I changed pl to p1 for clarity.
(defun c:retan
(/ p1 p2 p3 p4
) (command "line" "_non" p1
"_non" p2
"_non" p3
"_non" p4
"c") )
https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2016/ENU/AutoCAD-AutoLISP/files/GUID-21BE8290-7F11-400B-AC39-62A110F07545-htm.html
The getcorner function takes a base point argument, based on the current UCS, and draws a rectangle from that point as the user moves the crosshairs on the screen.
-
As a point of interest, I've noticed that some of the code on AfraLISP mixes lower case "L" with the numeral "1", so you have to pay special attention if you're doing a cut/paste from the examples. The result is that it "looks" (as in this case) like "P1" but it's actually "Pl".
It shouldn't affect the OP's code any - just bringing it up because it will cause problems if you don't notice this and try to use the variable later on, but enter it incorrectly.
Edit: Sorry Chris, missed your note about the change!
-
Chris's code should work fine but I prefer additional steps to catch errors.
(defun c:retan
(/ p1 p2 p3 p4
) )
(command "line" "_non" p1
"_non" p2
"_non" p3
"_non" p4
"c") )
)