TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: qwrtz on July 25, 2023, 01:00:50 PM
-
I want to get user input X and Y values and then use them as relative coordinates of the endpoint of a line (relative to the start point). If I weren't in a lisp function, I would just type something like @36,42. In a lisp function I can get the relative coordinates this way:
(setq y1 (rtos (getreal "Rise: ")))
(setq x1 (rtos (getreal "Run: ")))
Then I thought I could draw the line this way:
(command "Line" p1 "_non" "@" x1 "," y1 "")
But that doesn't work. What's the right way to do it?
-
Untested...
(command "_.LINE" "_non" p1 "_non" (strcat "@" x1 "," y1) "")
-
That works! Concatenation.
Thank you, Marko.
-
Alternatively, (and to avoid the string conversion and potential loss of precision), you might consider the following:
-
Thanks very much, Lee. I don't fully understand it yet, but it works, and I'm glad to be able to eliminate any possibility of imprecision caused by strcat.
I've noticed some imprecision in another function I wrote. I'll have to try to remember which function it was, and see if strcat is involved.
-
You're welcome :-)
and I'm glad to be able to eliminate any possibility of imprecision caused by strcat.
Note that the imprecision is caused by the conversion to a string (i.e. rtos in this particular example); strcat merely concatenates two or more strings. Without the conversion, the point coordinate values will be expressed using the maximum precision afforded by a double-precision floating point value, around 15-16 significant figures.
-
ENTMAKE might work in your example as well.
(setq p1 (getpoint "\nSpecify first point:"))
(setq p2 (getpoint p1 "\nSpecify next point:"))
(entmake (list '(0 . "LINE") (cons 10 p1) (cons 11 p2)))
https://help.autodesk.com/view/OARX/2023/ENU/?guid=GUID-D47983BA-1E5D-417D-85B8-6F3DE5F506BA