TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: qwrtz on July 25, 2023, 01:00:50 PM

Title: User input as relative coordinates in a (command) function
Post 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?
Title: Re: User input as relative coordinates in a (command) function
Post by: ribarm on July 25, 2023, 01:38:28 PM
Untested...

(command "_.LINE" "_non" p1 "_non" (strcat "@" x1 "," y1) "")
Title: Re: User input as relative coordinates in a (command) function
Post by: qwrtz on July 25, 2023, 02:38:15 PM
That works!  Concatenation.
Thank you, Marko.
Title: Re: User input as relative coordinates in a (command) function
Post by: Lee Mac on August 10, 2023, 05:38:39 AM
Alternatively, (and to avoid the string conversion and potential loss of precision), you might consider the following:
Code - Auto/Visual Lisp: [Select]
  1. (if (and (setq p1 (getpoint "\nFirst point: "))
  2.          (setq y1 (getreal  "\nRise: "))
  3.          (setq x1 (getreal  "\nRun: "))
  4.     )
  5.     (command "_.line" "_non" p1 "_non" (mapcar '+ p1 (list x1 y1)) "")
  6. )
Title: Re: User input as relative coordinates in a (command) function
Post by: qwrtz on August 27, 2023, 11:12:17 PM
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.
Title: Re: User input as relative coordinates in a (command) function
Post by: Lee Mac on August 29, 2023, 06:50:04 AM
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.
Title: Re: User input as relative coordinates in a (command) function
Post by: Mark on August 31, 2023, 11:06:54 AM
ENTMAKE might work in your example as well.

Code: [Select]
(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