Creating New Command in AutoCAD

 Creating New Command in AutoCAD If I’m not mistaken, AutoCAD use CUI since 2006. Not MNU or MNS as it used to be. CUI (customize user interface) is a XML file. It’s easier to manage. In this post, I will create a new command to set all properties to ByLayer. This is a request from my colleague. He likes to override color and linetype when he draw, and want to be able to reset all of the properties back to ByLayer. By clicking my new command, every properties will be set to By Layer.

First you may want to take a look to what I want to achieve. Click here to see animation.

Let’s do it. First open CUI by accessing menu tools>customize>interface… or by typing CUI then [enter] from command line. You will see browser like this. If you use ribbon, find it in manage tab, customization section.

 cui browser

CUI browser is easier to use than creating old AutoCAD menu. There are 3 areas I would like to highlight

  1. All customization. Here is where you can put all your command. Either you want to put it in ribbon, tool bar, right click context menu, and even double click.
  2. Command list. Here is all your AutoCAD commands. When you create a new command, it will appear here.
  3. Properties. Here is your command properties. After creating new command, you will have to define what it should do.

Let’s start with creating a new command. Right click on command list (2), and select new command from context menu. Rename it. Give it name ‘All ByLayer’ without quote. You can see the animation here.

Now, we have created a command. But it doesn’t know what to do yet. We have to tell it what it should do by typing macro command in properties area (3). Type this macro on the macro field.

^C^C(setvar "cecolor" "ByLayer") (setvar "celweight" -1) (setvar "celtype" "ByLayer")

^C^C will cancel all running command. Similar to pressing [esc] twice. Then we tell AutoCAD to change current color to ByLayer. Then current lineweight to ByLayer, and finally current line type to ByLayer.

Give a description for this command.

We have created a new command, and give instruction what it should do when it’s executed. But AutoCAD doesn’t know yet, where you want the command can be accessed. Now find your command in command list. We named it ‘All ByLayer’ before.

Click and drag it to the place where you want it appear. In this example below, I put it on my layer toolbar. You can also put it on right click context menu (more about this later) or double click!

command position

Click OK on this CUI browser to finish our work. Now take a look on your layer toolbar (or anywhere you put it before). Is it there? Try it!

Not so hard right? Learning macro is one thing, but creating customization with CUI is a lot easier than MNU or MNS. Good luck!

Share this Post!


Rate This Post

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

About the Author

Application Engineer. Jakarta, Indonesia. 5+ years experience as CAD engineering application. AutoCAD, MicroStation, Inventor, Autodesk Revit Architecture 2010 certified professional, and certified CATIA part design specialist. Here are some topics I am currently focusing on

You might also interested to these posts:

  1. How to: See Your Complete AutoCAD System Variable List
    If you are going to do some customization in AutoCAD, then it’s unavoidable that you will have to change some system variables. I’m not good in customization. So having a...
  2. Adding Command to Your Right Click
    We have discussed how to add new command to AutoCAD. We added our new command to Now let’s discuss how to add it to context menu. We want this command...
  3. Set All Your Objects Properties Back to ByLayer
    I don’t like when I receive drawings with the properties overridden to other than ByLayer. It’s a bit hard to distinguish between layers when people do that. There are many...