Jump to content

how to automate repeating part of a command


khoshravan

Recommended Posts

I want to draw many circles with "3P" options. Every time I have to hit the space bar for repetition and select the option.

 

A couple of weeks a go I read a post here in CT which taught how to automate this part of commands. I don't know how to find it.

 

Will be happy if somebody guide me how to find it

Link to comment
Share on other sites

The lisp works great when using or to repeat the last command, but when I tried to repeat the macro, it only repeated the circle command (without the 3P option).

 

This may or may not be the same thing the OP is asking, but I'd like AutoCAD to remember the circle option that was last used when using or to repeat a command.

Link to comment
Share on other sites

The lisp works great when using or to repeat the last command, but when I tried to repeat the macro, it only repeated the circle command (without the 3P option).

 

This may or may not be the same thing the OP is asking, but I'd like AutoCAD to remember the circle option that was last used when using or to repeat a command.

 

That's correct, the space will repeat the last used command, hence repeating the LISP command; however, since the macro doesn't define a command in itself, it isn't repeated, so you would have to press the toolbar button again.

Link to comment
Share on other sites

Of course not the "best" way of doing it:

(defun c:C3PR ( / ) (while t (command "._CIRCLE" "_3P" pause pause pause)) (princ))

No need for space even, but you have to use ESC to stop!

Link to comment
Share on other sites

As a macro:

 

^C^C_.circle;_3p

 

 

I thought it can be typed in command line. But it says:

 

Unknown command "CIRCLE;_3P". Press F1 for help.

 

Am I doing something wrong?

Link to comment
Share on other sites

 

As a LISP:

 

(defun c:c3po nil (command "_.circle" "_3p" pause pause pause) (princ))

 

It works good. Isn't it possible to add a "space bar" or "enter" to this code to make life easier?

Link to comment
Share on other sites

Also I should add that my question is in general. I raised drawing circle with 3p as an example. I want to know it for other commands as well.

Link to comment
Share on other sites

It works good. Isn't it possible to add a "space bar" or "enter" to this code to make life easier?
I don't follow :?
Uhmmm ... Yes :shock: ... see my reply #5 of yesterday. The only problem there is it requires you to press the Escape key to stop the command ... and then you'll see an error message at the command prompt.
Link to comment
Share on other sites

The macro is for use with toolbar buttons for example.

 

Do you mean ?I should make a button and assign the macro to it?

Or I lunch the command through its icon and then run the Macro?!?

Link to comment
Share on other sites

Of course not the "best" way of doing it:
(defun c:C3PR ( / ) (while t (command "._CIRCLE" "_3P" pause pause pause)) (princ))

No need for space even, but you have to use ESC to stop!

 

Dear Irneb

 

I checked your lisp today. Thanks it works as you say. I think clicking the esc at the end is better than clicking space every time.

I think the "while t" makes it to repeat. Am I correct? But why did you write : Of course not the "best" way of doing it?

I don't know LISP but out of curiosity why do you put three pause? Isn't one enough to pause or it is a security measure?

Link to comment
Share on other sites

Do you mean ?I should make a button and assign the macro to it?

Or I lunch the command through its icon and then run the Macro?!?

 

Create a new toolbar button and copy the macro code to the 'macro' part of the toolbar button properties.

Link to comment
Share on other sites

Do you mean ?I should make a button and assign the macro to it?

Or I lunch the command through its icon and then run the Macro?!?

Lee means that is the code for the macro of the "Command" inside the CUI. This command you can then assign to a button on a toolbar / ribbon, as an item in the menu, as a keyboard shortcut, as an item in a pop-up menu, etc. etc. etc.

 

Dear Irneb

 

I checked your lisp today. Thanks it works as you say. I think clicking the esc at the end is better than clicking space every time.

I think the "while t" makes it to repeat. Am I correct? But why did you write : Of course not the "best" way of doing it?

I don't know LISP but out of curiosity why do you put three pause? Isn't one enough to pause or it is a security measure?

Thanks I'm glad it works for you. You're correct the (while T ... is a loop which checks if the 1st item inside it is not nil, then runs everything inside it and checks again. The T (or "true") will simply never be nil, so actually it's what's called an "infinite loop".

 

The reason I say it's "not the best way" is because of this infinite loop. It relies on the user pressing the Escape, which for a Lisp function means: "Cancel everything, there's an ERROR!"

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...