Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Lisp - Set point based on a previous point / variable

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
Anonymous
2180 Views, 2 Replies

Lisp - Set point based on a previous point / variable

At work we have an Autolisp where the user enters distances for b, c & d and picks a start point.  The lisp then draws a line from start point (pt1) 180 degrees at length d.  Then draws a second line from pt1 to pt2 where pt2 = pt1 + [b,c]

We are unable to get the lisp to draw the second line to pt2.  We tried two different approaches.  See below for the lisp portions not working for both options.  Option 1 would draw the second line from pt1 to pt2 where pt2 is defined in the line command using a cal function.  Option 2 would draw the second line from pt1 to pt2 where pt2 is set prior to the line command.

The error for option 1 appears as “error: no function definition: CAL

The issue for option 2 is it prompts to enter another start point for pt1+[b,c].

How can we get the lisp to draw a line from pt1 to pt2?

 

Option 1

 (setq pt1 (getpoint “\nEnter start point: “))

 (command “line” pt1 (polar pt1 (dtr 180.0) d) ““)

 (setq e1 (entget (entlast)))

 (setq e1a (entlast))

 (command “line” pt1 (setq pt2 (cal “[@b,c]”)) ““)

 

Option 2

 (setq pt1 (getpoint “\nEnter start point: “))

 (command “line” pt1 (polar pt1 (dtr 180.0) d) ““)

 (setq e1 (entget (entlast)))

 (setq e1a (entlast))

 (setq pt2 (getpoint “pt1+[b,c]”))

 (command “line” pt1 pt2 ““)

2 REPLIES 2
Message 2 of 3
Kent1Cooper
in reply to: Anonymous

The cal AutoLisp function is an external one, and must be called with (c:cal ...) -- see Help.  [Whether or not you got the rest of the cal expression right, I couldn't say.]  But there's a "native" AutoLisp function you can use:

 

 (setq pt1 (getpoint “\nEnter start point: “))

 (command “line” pt1 (polar pt1 pi d) ““)

....

 (command “line” pt1 (setq pt2 (mapcar '+ pt1 (list b c))) ““)

Kent Cooper, AIA
Message 3 of 3
ВeekeeCZ
in reply to: Anonymous

Very common way...

 

 

(setq pt2 (list (+ (car pt1) b) (+ (cadr pt1 c))))
(command "line" "_non" pt1 "_non" pt2 "")

 

Also possible... your @b,c   ...but limited precision.

 

(command "line" "_non" pt1 "_non" (strcat "@" (rtos b 2 10) "," (rtos c 2 10)) "")

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report