Run macros from commandline

Run macros from commandline

sterling.parker
Contributor Contributor
1,536 Views
5 Replies
Message 1 of 6

Run macros from commandline

sterling.parker
Contributor
Contributor

It's entirely possible I'm missing something here, but I've googled several variations on this problem and can't seem to figure out what.

 

From what I can tell there are two ways of creating simple "custom commands" in AutoCAD: Action Recorder, and Command Macros.

 

With Action Recorder, when I create a new Action Macro, whatever the name is can be run from the command line. So for example, I can type DRB and it runs my "draw order, back" action macro. 

sterlingparker_0-1676310274656.png

 

With Command Macros, such as this one from Insights ("Select and Erase Similar Objects"), it can be assigned to a button in the interface, or a keyboard shortcut, but I cannot seem to find a way to run it by name from the command line by typing a short command or name. Giving it a "command display name" such as "SSE" doesn't work, even though it seems like that would be the place to do it.

sterlingparker_1-1676310431433.png

 

Now, for most of my purposes, Action Recorder is... fine. It's just fine. But command macros seem much more powerful and I'd like to start learning to use them. However the fact I can't seem to type them by name (in the same fashion as PLINE or QS) is really hanging up my workflow. I hate clicking buttons.

 

Is it possible to create a command macro such as

 

^C^C_.circle \5

 

and assign some kind of shortname to run it from the command line by typing?

 

0 Likes
1,537 Views
5 Replies
Replies (5)
Message 2 of 6

cadffm
Consultant
Consultant

Hi,

 

You can define new commands by actionmacro recorder, but never by a button  menu or toolpalette-tool.

 

"Command Macros" aka Menu macros

 

 

In your case (not LT user), you can use some simple Lisp functions!

 

 

(defun C:NEWCOMMANDNAME nil (command-s "CIRCLE" Pause "5"))

 

Copy and paste it into commandline as a first try.

In this drawing, in this file session, the new command NEWCOMMANDNAME works.

 

 

 

 

Sebastian

0 Likes
Message 3 of 6

TomBeauford
Advisor
Advisor

Change the Command Name to SSE if that's what you want to use to start the command.

After placing it in the Ribbon you can add what you have as the Command Name now as the Display Name.

64bit AutoCAD Map & Civil 3D 2023
Architecture Engineering & Construction Collection
2023
Windows 10 Dell i7-12850HX 2.1 Ghz 12GB NVIDIA RTX A3000 12GB Graphics Adapter
0 Likes
Message 4 of 6

sterling.parker
Contributor
Contributor

@TomBeauford Unfortunately this doesn't seem to work. I tried adding the macro to the ribbon as shown, but even after restarting AutoCAD it doesn't invoke by typing the name. Clicking the button runs the macro as expected, but the commands shown in the console output are just the commands that make up the macro, it doesn't invoke the macro by name.

sterlingparker_0-1676318707049.png

 

 

@cadffm I am aware of LISP and if that's my only option to add new commands then I suppose I may have to learn, but at the moment that's outside the scope of my question. I'm really hoping that there's some native way to use macros as commands, besides Action Recorder (which is sometimes very trial-and-error process and not very flexible)

0 Likes
Message 5 of 6

pendean
Community Legend
Community Legend

@sterling.parker You cannot easily call a button macro or action-recoding by just typing a couple of letters: it's just not a thing in AutoCAD. It's the wrong coding tool for that type of access. Those CUI category entries are not there to create such access either, they are just informational for the various pop-ups, so that can be confusing for users too.

 

pendean_0-1676321573480.png

 

LISP is not that hard to master for your needs if I just look at your posted macros: if you change your mind there are lots of good start tutorials to get you beyond your hesitation-point.

0 Likes
Message 6 of 6

cadffm
Consultant
Consultant

As I said (and Pendean confirmed it), it is not an option.

 


@sterling.parker  schrieb:

 

>>"but at the moment that's outside the scope of my question."

The question ended with my answer, sorry.

 

>>"I am aware of LISP and if that's my only option to add new commands then I suppose I may have to learn"

You don't need to learn the great world of API programming, you can easily use your menu macro knowledge

and write it in a bit different manner with prefix part in front and another suffic part at the end.

 

Your sample:

^C^C_.circle \5

(defun C:NEWCOMMANDNAME nil

 (command-s "CIRCLE" Pause "5")

)

 

With just 3 lispfunctions you can do what you want and with 3-4 function more you can do much more than without lisp setq&ssget are the next you will learn and never want to miss again.


 

Sebastian

0 Likes