Loop ray command

Loop ray command

Philip-John
Advocate Advocate
355 Views
6 Replies
Message 1 of 7

Loop ray command

Philip-John
Advocate
Advocate

I need a lisp routine to draw ray lines and that should draw multiple ray lines with separate start point where I click until I press Escape key. I have a code as follows. But it takes same start point for each click. Can some help me to modify this routine.

(defun c:RayLoop (/ pt1 pt2)
(while (setq pt1 (getpoint "\nSelect the start point for the ray: ")) ; Continue until the user cancels
(setq pt2 (getpoint pt1 "\nSelect the direction point for the ray: ")) ; Get the direction point
(if pt2
(command "ray" pt1 pt2) ; Execute the ray command
)
)
(princ "\nRay loop ended.")
(princ)
)

0 Likes
Accepted solutions (2)
356 Views
6 Replies
Replies (6)
Message 2 of 7

ВeekeeCZ
Consultant
Consultant
Accepted solution

@Philip-John wrote:

I need a lisp routine to draw ray lines and that should draw multiple ray lines with separate start point where I click until I press Escape key. I have a code as follows. But it takes same start point for each click. Can some help me to modify this routine.

(defun c:RayLoop (/ pt1 pt2)
(while (setq pt1 (getpoint "\nSelect the start point for the ray: ")) ; Continue until the user cancels
(setq pt2 (getpoint pt1 "\nSelect the direction point for the ray: ")) ; Get the direction point
(if pt2
(command "ray" pt1 pt2 "") ; Execute the ray command
)
)
(princ "\nRay loop ended.")
(princ)
)


 

Add "" there... ?

Message 3 of 7

Philip-John
Advocate
Advocate

Thanks a lot brother.

It works as I wish..

0 Likes
Message 4 of 7

ВeekeeCZ
Consultant
Consultant
Accepted solution

Or try this version with a better preview.

 

(defun c:RayLoop (/ pt1 )
  (while (setq pt1 (getpoint "\nSelect the start point for the ray: ")) ; Continue until the user cancels
    (command "ray" pt1 pause "")) ; Execute the ray command
  (princ "\nRay loop ended.")
  (princ)
  )

 

BTW you shouldn't exit the command by ESC.. or at least you don't have to. I would consider that as a bad habit. Most built-in commands are designed to be ended by RT click. This routine as well.

Message 5 of 7

Philip-John
Advocate
Advocate

Oh great.. 

Even better than the previous one as you said.

Thanks bro

0 Likes
Message 6 of 7

annoisscary
Advocate
Advocate

This is simple enough that it doesn't even really need to be a lisp. You could make this as a Shortcut Key or Button in CUI easily.

*^C^C_ray;\\;

Message 7 of 7

Philip-John
Advocate
Advocate

Perfect (Without lisp)

Thanks brother.

0 Likes