Categories

AutoCAD 2015 and AutoCAD LT 2015 Bible

The most comprehensive AutoCAD book around!

Tutorial: Create a custom command

If you find yourself using the same combination of commands and options over and over, you can easily create a custom command that executes the combination with a click of a button or a menu item. In this tutorial, I explain the basics of AutoCAD’s menu syntax so that you can create your own commands. No programming required!



  1. Enter cui at the command line/dynamic tooltip to open the Customize User Interface dialog box.
  2. In the Command List pane, click New (Create a New Command).
  3. In the Properties pane, enter a name for the command in the Name text box. Also enter a description in the Description text box.
  4. If you think your command will be long or need more than one line, click in the Macro text box and then click the Ellipsis button that appears on the right. Then enter your macro in the Long String Editor dialog box. Otherwise, enter the macro in the Macro text box. Start by writing out the combination of commands and options as you would enter them on the command line or in a script. Then add any necessary special characters.

Below are the special characters you need to know for menu macros:

Character Description
Space Equivalent to pressing Enter except when entering text to create a text object that contains spaces (between words). Use between the command and its options.
; (semi-colon) Equivalent to pressing Enter. The end of a line in a menu macro is also equivalent to pressing Enter. More helpful than using a space when you need to press Enter twice, because it shows the number of Enters more clearly. Also helpful at the end of the macro.
\ Pauses for user input, such as picking a point or entering a value.
+ At the end of a macro line, continues the macro to the next line
* At the beginning of a macro, before ^C^C, repeats the macro until you press Esc or choose another menu item.
^P Toggles the display of the menu macro on the command line; makes the macro look neater when you use it.

  1. From the Command List Categories drop-down list, choose Custom Commands to easily find your command. Select it and drag it to the desired menu or toolbar at the top of the Customize User Interface dialog box.
  2. If you drag it to a toolbar, use the Button Editor to give it an image. Usually, you choose an existing button to start with, click Edit, and modify it. Then click the Save As button to save the icon image.
  3. Click OK and try out your new command!
Ellen Finkelstein

71 comments to Tutorial: Create a custom command

  • […] For information on how to create a custom command, see this tip. What keyboard shortcuts do you use? Leave a comment! Please also explain what they do, in case it […]

  • Adel Moldovan

    Hi,

    How can I change the default behavior of Multiple Object Stretch command?

    Meaning:
    when I press the MOS command and hit enter or right click mouse button it executes defaults Crossing Window selection, but wish to go for a Crossing Polygon option. It’s annoying to keep entering CP or press down arrow keyboard button to select it over and over again since the CP option is the option I use most of the time.
    It’s Acad 2012
    Thx.

  • Ellen

    Are you just talking about the STRETCH command? I’ve never heard the phrase “Multiple Object Stretch,” although of course, you can stretch multiple objects with the STRETCH command.
    I would simply create a custom command and assign it to a keyboard shortcut or add it as a button to a ribbon panel. I have instructions here: https://allaboutcad.com/tutorial-create-a-custom-command/. This might also help — https://allaboutcad.com/create-a-custom-toolbar-in-autocad-2006-or-later/ — although it describes adding a button to a toolbar, rather than to the ribbon.

  • Adel Moldovan

    Dear Ellen,

    Thank for your quick replay.

    Yes, I meant the STRETCH command. “Multiple Object Stretch” is the tool tip displayed when you hover your mouse over the icon in “Modify” panel of the “Express Tools” tab. Also known as “Stretch Multiple”. Sorry for misunderstanding.

    The reason i look to edit or modify existing commands is that I’m not very familiar with writing codes and programing and I find it easier to change just a bit of the existing code rather then write a new one.

    See, when I open the CUI and look for “Multiple Object Stretch”, macro label shows “^C^Cmstretch”. Here I thought I can change that default behavior.

    And the STRETCH command shows “$M=$(if,$(eq,$(substr,$(getvar,cmdnames),1,4),GRIP),_stretch,^C^C_stretch)”
    so I don’t have a clue about where is the option of choosing Crossing Window or Crossing Polygon hidden.

    Or to make it simpler, if you type “MSTRETCH” the command line shows:

    Specify an option [CP/C]

    This is what I meant. It goes for C by default and I want to make CP to be default, not to type CP every time.

    When I wrote my question to you, i was already on https://allaboutcad.com/tutorial-create-a-custom-command/ so now I’ll give it a try with creating a custom command.

    Anyhow, thank you for your time.

  • Adel Moldovan

    Solved. Not exactly what I want but does the trick and it’s fast enough.

    After MSTRETCH long mouse right click and pick CP on a shortcut drop down menu. Good 🙂

  • sadegh

    hi.
    cool tutorial.
    i learn it but i have a question.
    i make a new command and put it into one pallet but when i type it in command line, it dosn’t run anything.
    is that normal?
    i like to create some custome command that i can type them in command line.is there any way!?
    (maybe i should use acad.pgp!)
    thanks

  • Ellen

    You can’t exactly type the command, but you can create a custom keyboard shortcut, such as Shift+L. I have instructions at https://allaboutcad.com/create-a-custom-keyboard-shortcut/.

  • slavic

    Hi I am trying to create a custom toolbar button that will turn on a layer. So i can just click that button and that layer turns on in the current drawing, instead of opening the layers manager to find my layer. How can I do that? Anybody have a suggestion? I have autocad 2004.

  • antony john

    how to change the command copy rotate command to multiple mode

  • mukesh ahlawat

    can i record steps as in excell?

  • Chris

    Fantastic tutorial! Saved me hours of work, thank you.

  • Chirag

    Hi, I am using AutoCAD Electrical 2010, I use a custom command that uses script. When I add command display name to it, it does not work in the command line. Can you pls assist?

  • Vincent

    Hi, I would like to know the possible macro command I can put in a custom command. I mean like setvar or getvar.

  • Marcus

    Hi,
    I have created a custom command to enter a block, ^C^CINSERT; TAB; RACETRACK
    I want to have multiple blocks handy to easily insert. but with this command i can only insert the last inserted block…
    This command opens the insert dialog box, then i want to go to the ‘browse’ button, open the block and then insert. Is this possible? your help is much appreciated.

    Thanks

  • Ellen

    I think you’d need some more sophisticated programming that would allow you to interface with Windows. But if you know the name & path, you might be able to put a pause in the custom command and type the file name and path at that point. You’d have to turn off the FILEDIA system variable. I haven’t tried this, just guessing.

  • Chris Eden

    Hi
    i have a macro that i have been using in autocad 2012 for a simple copy & rotate command as follows ^C^C_select;auto;\_copy;p;;0,0;0,0;_move;p;;\\_rotate;p;;\\redraw
    For some reason it does not work in 2013
    the macro just end after the copy command and fails to rotate the objects
    Any suggestions would be appreciated

  • Rob Rivard

    Hello,
    Why is it that after this macro the layer is not returned to “0”? The macro will change to “2D_WALL”.
    ^C^C_-LAYER;S;”2D_WALL”;^C_BREAKLINE;\\;^C^C_-layer;S;”0″;^C;;;

    Yet, with other commands ie. dimlinear it works.

  • Josh

    The company I work for is very strict on EVERYTHING being snapped together. I’m trying to figure out something I can run that will hilite things that’re snapped together and point out things that aren’t snapped. It’s an electrical systems company and I’m trying to streamline our QA process and make things easier on the drafters. Thanks

  • Harold

    Can anyone help me? I’m trying to create a toolbar that used to work in AutoCad 2006 but doesn’t work anymore with 2010.

    this used to work ^c^c-layer;freeze;selectobjects

    When I just type it out step by step on the command line it works but instead of selectobjects I just use enter.

    What am I missing???

    THANK YOU!!!

  • Ellen

    I’ve never heard of selectobjects in a custom command (which doesn’t mean it doesn’t exist). In a custom command, you can use ; (semi-colon) in the place of Enter or \ (back=slash) to pause for user input. See if one of those works.

  • I drew an object alongside with text in a specific scale. Is there anyway I can create a command to replicate that object?

  • sbeth

    I’ve tried following your instructions numerous times… I get to a point where I make the command properly (I hope)- including macros and choosing an icon, etc.

    BUT- when it comes time to drag the new command to a toolbar, none of my panels will allow the new command to lodge/stick there! This is also true for standard commands- i tried adding Trim to my Draw panel (so i don’t have to keep switching b/w Trim and Extend) and it won’t let me attach it to the panel!

    What am I doing wrong, anyone? thanks!

  • Andres Mee

    Hi.
    I need solution how I can execute more than one toolbutton macro sequentially In AcadLT2012.
    I have problem writing macro with diesel commands, because length of macro is limited with 460 symbols.
    Is it possible to call toolbuton macro from command line or other macro or script file (without toolbutton clicking)?

  • Irfan Ahmed

    hi.

    i need help to create short cut ..
    actually i want to update my cad from excel so i m using OEL option,
    for this first i copy a cell from excel and paste into CAD,

    for paste in cad i have to do these …

    from EDIT select *paste special*
    thn select *paste link *
    thn select *excel sheet*
    and ENTER

    for all above process can i creat one short cut ???
    please guide me how ..

    thnx

  • HI Ellen and thanks for this awesome site!

    Could you help me with a tricky problem?
    I tried to use an old macro I made years ago
    and it didn´t work anymore as it used to.

    Macro: ^C^C_layout;t;printtemplate.dwt;

    So basically I wont to make new layouts from template with
    all printing setups already made in. I am using AC2011LT in Windows 7.

    If I type that same string on a command line, Acad will open
    a popup window with all layouts listed in a template.
    For some reason when command is ran by the macro, it will show
    this text: Enter layout name(s) or [?]:
    So is there a way to get the pop up -window with all layouts listed?
    Putting Filedia -value to 1 didn´t help.

    Thanks!!

  • Ellen

    FILEDIA was the only idea I had…

  • Ranga

    Dear Ellen,

    I want to make macros for layers control buttons. so I have layers “0” “layer1, layer2, layer3” so i want to a button for layer one which i press this layer “0” and “layer1” will on

  • Wiley1

    I am trying to make a simple macro in AutoCAD LT 2012 to save a 2012 DWG file as a 2000 DXF file. I can get the saveas part, but how do I select the file type in the macro?

  • Ellen

    I’m not sure if you mean how to select the file itself.
    This might help: https://allaboutcad.com/tutorial-automate-tasks-with-a-script-file/
    The backslash, which lets the command pause for input, might also be of use.

  • Wiley1

    Hi Ellen, Thank you for replying so quickly. I am able to make the backslash work, but I am trying to accomplish this task with no manual intervention. When I have a DWG open and want to save as a DXF I click on the save as icon, then since I want the file name to remain the same other than the file extension, all I want to do is change the file type. If I did this manually I would just click on the “Files of type:” menu and select the “AutoCAD 2000/LT2000 DXF (*.dxf) selection and click on save. I am looking for a way to do this through a macro or script, but cannot figure out how to do the file type selection process.

  • J

    Hi,
    I wanted to create a keyboard shortcut for Zoom In and Zoom Out while working on a plan. I created the shortcuts SHIFT+I and SHIFT+O but need help for macro. Also, if there already is a keyboard shortcut which doesn’t need the icon clicking please lemme know.
    Regards,

  • Ellen Finkelstein

    I see what you mean now. It sounds to me as if you have to use AutoLISP for something like that. I’m not an AutoLISP programmer, but you might be able to find someone to help you on autodesk’s discussion groups.

  • gareth

    hi there im looking for a auto cad lisp to do with properts setting the colour the type and thicknes in one button. eg a single button that gives me green, continues & 0.15 can this be done. i use 3 sets of lines as draw block plans for a asbestose company. and thought it make life easyer to press one button rather than 3.
    thanks
    Gareth

  • Hussain

    I want to chorten a command like (Wipeout). When we enter wipeout, there are options (Polyline/Frame) if i enter F then come (On/Off). I want to go directly On or i want if i enter wipeout, its should not ask anything and directly ON the frames.

    Can some one help me please?

  • Habib

    Hi Ellen, I have a problem where some of my system varables are reset every time I open a acad file, I am forced to re-enter them every time, I tried re-installing Acad but to no avail, I keep getting the same error. Can you guide me on how to create a shortcut for setting several system variables, like HIGHLIGHT (1), FILL (on), MBUTTONPAN(1). Thank you

  • SUIRAD

    how can i create a short command for xref? can you give me the exact macro?

  • Mikael

    Hello!
    I often need to change a lot of annotative TEXT-objects (eg “123”) to/from being underlined and I am trying to make a macro that helps me. My code jams when I click on the first TEXT item (“\” in the code) – how do I resolve this?
    Code: *^C^C_ddedit \^U;
    (I am using Autocad LT 2012.)
    Can someone help me please!?

  • Robert

    I’m trying desperately to create a custom macro that would allow me to rotate the ucs on the z axis and then initiate the plan command to follow the rotation. I’m away of using the ucsfollow command but it makes my viewports crazy when using paperspace. I’m no good at script or writing any kind of script. Any and all help would be appreicated. I’m using autocad 2002. I’ve got the button created already just need help with the script.

  • TOM

    ROBERT

    TRY PASTING THIS INTO YOUR BUTTON “Ucs;z;\plan;;”
    IT WORKED IN MODEL SPACE AND IN MODEL SPACE INSIDE A VIEW PORT
    THE \ SLASH IS USER INPUT FOR THE DESIRED ANGLE FOR Z.

  • TOM

    Robert

    Paste this macro into your tool button.
    The slash is user input for the z angle desired.

    Ucs;z;\plan;;

    work inside a viewport and in the model tab/space.

  • Randy

    Robert
    This is what I use. ^C^C^R_ucs_ob\_3 plan c. You pick an object, it rotates the ucs to that object, and aligns the view to the z axis.

  • John

    So I have a lisp routine that works perfectly to apply text to a dimension line, however, it will not put the text below it because the command for putting text below a dim line is “\X” the “\” represents waiting for user input. how do I get CAD to look at “\X” as complete command rather than seeing “\” then “X”?

    hopefully that all makes sense

  • Belen

    How to enter a wblock in the macro when the wblock name contains spaces? The spaces are seen by macro as “enter”.

  • Belen

    I got my answer already by using quotes ex. -insert;”file master logo”

  • hi, how can I assign the key (delete) in the keyboard to execute the command (erase) ?..thanx

  • Hans Graveman

    Basima

    In autocad 2010/2014 de delete button wil work as erase.

    Hans Graveman

  • They all can give you powerful tools with a small learning curve.
    (Or a minimum of it did, I haven’t seen it in 10 years).

    This engine has integrated support for some of the most powerful tools out
    there today and is creating relationship with many 3rd party developers, like Mixamo for example, that is allowing
    for even more tool integration.

  • Geordie Pete

    Hi, I am trying to make a makro or custom command to draw two lines 60mm apart snapped to two entities then when finished have one line 60mm shorter than the other. This is to connect a number of pipes in a plumbing drawing, cheers and any help would be greatly appreciated.

  • Tim

    I want to make a dropdown list of .dwg drawings that I can insert into .dwg drawings as I go. I work with a/c, and want to use a library off a dropdown list.

  • TY

    Hi,

    After creating and saving a new command, AutoCAD does not recognize the command and simply says “unknown”.

    Thanks

  • sree hari

    Hi All,

    i need a macro code for opening autodesk AUTOCAD 2013 and load template file(from specific location).After loading it should draw a basic circle or rectangle diagram.

    Can any one please let me know the macro command ,So that it will be help ful for me .

    I want to insert a button for this ,so that once i press this button ,automatically it should undergo the above process in Autocad software

    Please let me know asap.

  • Harold

    Hi All,

    Trace command is removed from 2014. I created a macro for it to trace my shearwalls in previous versions. I have been messing with the pline command but I can’t seem to get it right.

    This was my old macro with trace… ^C^C-COLOR 253 TRACE 5.5 MIDPOINT

    The code below is what I have been messing with but doesn’t work. Tried different way but no luck still:

    ^c^c-color 253;; pl; midpoint; \; w; 5.5; 5.5;

    I created a hatch one. I first have to set my hatch then I use the W to draw the boundary. These are 2 separate toolbars screen menu items.

    ^c^c-color;8;-hatch;p;ansi31;3;0;;

    ^c^c-hatch;w;n;

    If anyone knows what I’m missing for the pline macro that would be great. I’m assuming that it’s not possible. I can work with using the -hatch.

    Thanks in advance 🙂

  • saman

    Hi.I will learn build customized toolbar in autocad.plz help me.

  • george issac george

    i want to know how to numbering done continuousily frm 1 to 100.
    pls help how it is.

  • Taylor George

    I desperately need help learning how to program/create new commands, as well as adding blocks and tools to my pallets that do not currently exist… Does anyone know of a dummy-proof site/forum/tutorial that can help me out?

  • Kamal

    is there any command line option available for ‘FILTER’ command?? I want to creat macro using that. I am using 2010.

  • moro

    After creating and saving a new command, AutoCAD does not recognize the command and simply says “unknown”.

    Thanks

  • Mark

    Hi,

    i am trying to use a custom icon in my custom toolbar to run appload and the load a lisp routine and i am not sure what need to go into the macro line.

    can you help

  • DON

    I HAVE AN OLD CUSTOM SIDE BAR MENU THAT I WROTR FOR r19. I AM NOW RUNNING AUTOCAD 2004 AND LOOKING TO UPGRADE. mY PROBLEM IS INSERTING BLOCKS FORM THE SIDEBAR. I PONCE USED THE cinert COMMAND BUT THAT DOES NOT SEEM TO WORK ANY MORE. iS THERE A NEW COMMAND I CAN USE?

  • SYED

    HI C BUTTON DOES NOT WORKING IN AUTOCAD

  • Floris

    Hi, I’d like to always insert a block in layer 0.
    Then after I done so, I’d like to return to the previous layer.
    I came up with something like this but it doesn’t seem to work..

    ^C^C-layer;set;0;;insert;\\\layerp

    Does anyone know a fix for this?

    Thanks in advance

  • Daniel Kemack

    Hello,

    I want to copy a line, down a column (like a casing), and have a classification follow it at half the distance that I copy it down.

    i.e. Soil boring’s with each soil type at certain depths and the classification to follow it at half the distance.

  • DAVID A MILLER

    Is it possible to create a keyboard shortcut to switch between layout tabs

  • Ctrl+Page Down moves you from tab to tab going to the right
    Ctrl+Page Up goes left

  • 4runner

    Hi,
    I was hoping someone could help me with a macro.
    I usually have zero lines of prompt history. ( in my workspace )

    But when i measure a distance.
    I’d like to have 3 lines of history displayed. ( so i see my measurement )
    Then click, and the history would return to zero.
    And i would continue working as usual.

    I can get it to change from zero to 3,then the distance command,

    ^C^CCLIPROMPTLINES;3;^C^CDIST;\\ < works, but doesn't reset to 0

    if i add
    ^C^CCLIPROMPTLINES;3;^C^CDIST;\\CLIPROMPTLIN ES;0;
    it doesnt display right.

    Mark,

  • Manoj Naik

    could you tell me how can getting in excel coordinate (X,Y) is adding offset to obtained new XY coord

  • amirah e kahil

    I created a custom command in an empty file and it worked perfectly but when I try to use it in other files it doesn’t work
    why?

  • sharar khan

    I want how I can make coordinats in Auto Cad in 2015
    now I live in Qatar my WhatsApp number 0097466505023 if you can send me I shall be very thanks for that

  • Yo Stein

    yo stein
    april 15, 2018
    How to create commands for Autocad 2014.
    Like “ew” for the command “erase window”?
    Thank you for your help
    Yo.

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>