LISP help

LISP help

Anonymous
Not applicable
830 Views
5 Replies
Message 1 of 6

LISP help

Anonymous
Not applicable

Hello!

I have this lisp routine, that creates a line, then asks for objects to stretch to that line, and then deletes said line. Simple and elegant:

(defun c:q5()
     (command "line" pause pause "")
     (setq e1 (entlast))
     (command "extend" e1 "_CP" "" pause pause "")
     (command "erase" e1 "" "")
     (princ)
 )

So the way it operates, one can only extend two objects before it ends the command and then comes up with "Unknown command "Q5". Press F1 for help." on the command line. How can I make the command continue asking for objects to extend indefinitely and also prevent that "Unknown command" message?

 

I added a screencast showing what I described. Of course, I pressed shift to trim instead of extend on the second object.

 

Thank you!

 

 

 

0 Likes
Accepted solutions (2)
831 Views
5 Replies
Replies (5)
Message 2 of 6

pbejse
Mentor
Mentor
Accepted solution
(defun c:q5()
     (command "line" pause pause "")
     (setq e1 (entlast))
     (command "extend" e1 "_CP" "")
	  (while (> (getvar "CMDACTIVE") 0)
	  (command pause)
	)
     (command "erase" e1 "")
     (princ)
 )
0 Likes
Message 3 of 6

Anonymous
Not applicable

Great! Thank you for the help!

 

-Michael

0 Likes
Message 4 of 6

Anonymous
Not applicable

So the "while" function works like this:

If the value of the system variable CMDACTIVE (meaning there is currently a command active?) is greater than 0 (meaning 1?) then the command will pause indefinitely?

I am VERY new to AutoLISP and have no other coding experience. It is interesting and exploring LISP I have found some SUPER handy codes and even created a few simple ones by analyzing others.

 

Thanks a bunch!

Michael

0 Likes
Message 5 of 6

ВeekeeCZ
Consultant
Consultant
Accepted solution

The code has some lacks... 

When selecting edge(s) you need to close the selection since a multiple selection is allow. 

Then not sure if you need to specify CP type of selection... doesn't work that without it too?

(defun c:q5 ( / e1)
  (command "line" pause pause "")
  (setq e1 (entlast))
  (command "extend" e1 "") 
  (while (> (getvar "CMDACTIVE") 0)
    (command pause))
  (command "erase" e1 "")
  (princ)
  )

 

BTW using 'cmdactive is, I would say, the 'traditional' way. Since version 2015 we could use the following trick that works the same. The COMMAND-S somehow keeps the user within the command until he decides to finish it.

(defun c:q6 ( / e1)
  (command "line" pause pause "")
  (setq e1 (entlast))
  (command-s "extend" e1 "")
  (command "erase" e1 "")
  (princ)
  )

 

0 Likes
Message 6 of 6

Anonymous
Not applicable

It looked like there was a "" (close) on the extend command already, after the "_CP", which I'm not sure about why it was in there, but you're right, doesn't seem necessary. I'll give it a try!

 

Thanks,

Michael

0 Likes