Adding aliases for custom AutoCAD commands

I had an interesting question come in by email and thought I'd share it via this post. To summarise the request, the developer needed to allow command aliasing for their custom commands inside AutoCAD. The good news is that there's a standard mechanism that works for both built-in and custom commands: acad.pgp.

acad.pgp is now found in this location on my system:

C:\Documents and Settings\walmslk\Application Data\Autodesk\AutoCAD 2008\R17.1\enu\Support\acad.pgp

We can edit this text file to add our own command aliases at the end:

NL,  *NETLOAD

MCC, *MYCUSTOMCOMMAND

Here we've simply created an alias for the standard NETLOAD command (a simple enough change, but one that saves me lots of time when developing .NET modules) and for a custom command called MYCUSTOMCOMMAND. If I type NL and then MCC at the AutoCAD command-line, after saving the file and re-starting AutoCAD, I see:

Command: NL

NETLOAD

Command: MCC

Unknown command "MYCUSTOMCOMMAND".  Press F1 for help.

Now the fact that MCC displays an error is fine - I don't actually have a module loaded that implements the MYCUSTOMCOMMAND command - but we can see that it found the alias and used it (and the MYCUSTOMCOMMAND name could also be used to demand-load an application, for instance).

13 responses to “Adding aliases for custom AutoCAD commands”

  1. Mr. Walmsley,
    I hope you don’t mind if I post this question for you. I'm the CAD Manager of a Civil Engineering firm. We're currently using Civil 3D 2008 and Land Desktop Companion 2008 with service pack 2. An employee that used to work with us still helps out when available. He is a programmer. He has written an application which he installed on the 2002 products and upgraded to the 2006 products. He has come across a problem trying to tweak this application and get it to work with our 2008 products. Programming is not my strong point. Is there anyway I could email you the document where he describes in programming language his issues, and hopefully you can lead us in the right direction? I'm not sure how to attach it here. Any help is greatly appreciated.

    Thanks
    Jason

  2. Hi Jason,

    Frankly, I doubt I'll be able to help: I have little to no knowledge of either LDT or Civil 3D development.

    The best source of help is likely to be the Civil 3D Customization Discussion Group, or the ADN website - where you can submit your questions if you happen to be an ADN member.

    You can certainly email me the document, in case I happen to be able to help off the top of my head, but unfortunately I don't have the luxury of being able to spend time working on this type of issue, myself.

    Regards,

    Kean

  3. Good morning Kean.

    You can also use the REINIT command to reload the PGP file after you change it. I use this command quite a lot, which saves me from closing all my drawings and restarting Autocad after I make some changes.

    Have a good day.

    Jason

  4. Very cool - thanks for the tip, Jason!

    Kean

  5. Mr. Walmsley,
    Thanks for your quick response. I have posted on the dicussion group and am waiting for responses. I totally understand you not having enough time to dig in to this problrm. I still appreciate your feedback. Even though programming is not my strong point, I think you have an interesting blog. Again, thanks. Take it easy.

    Jason

  6. Starting in 2006?, the pgp file can be edited from Express/ Tools/ Command Alias Editor. Not only does this allow edits on the fly, but when the ap closes it updates your current session. Also changes made to your pgp in a text editor do not migrate to new versions, saving time in getting started out of the box. Personally I find it much easier to use. The Command Alias Editor also allows you to scroll lists of available commands and abbreviatons/ aliases to add/ modify/ or remove.

  7. Interesting - thanks, Clint.

    Kean

  8. engr. juhairy Avatar

    hellllllllllo

  9. hello,
    I am recently having a trouble with adding alias to my custom command(command works fine when added as a new button to tool palette)

    so here's my problem described further:
    I've created new custom comman called "cu" using cui editor. I don't know if it matters but source of the command was set to "ACAD".

    Name: CUcs
    Desctiption: turns ucs & plan around z axis
    Extended hlp file: (blank)
    Command Disp. name: CUcs
    Macro: ^C^CUCS Z \\PLAN C ^C
    Tags: (blank)
    Element ID: MMU_CU

    After that I've added alias to acad.pgp
    CU,*CUcs

    I've done reninit but I still get error:
    cu Unknown command "CUCS".

    I'm using Autocad 2009 ('non LT')
    Any suggestions on the issue Guys?
    Thanks in advance

  10. The CUI editor doesn't actually define commands in the way you expect: such named commands can be added to menus, toolbars and ribbons, but it doesn't mean the new name will be callable via the command-line.

    The PGP would work fine with this:

    CU, *UCS

    But then you really want to specify a command string for the UCS command.

    The simplest way to achieve this would probably be via a simple LISP command:

    (defun CUCS()(command "_.UCS Z \\PLAN C"))

    (Although the string you've provided above seems a bit strange - perhaps there are characters missing because of the HTML comment editor.)

    Kean

  11. Why am I getting "unknown command", if I set CopyLocal of acad DLLs to false (VC# Express 2010, ACAD 2012)? Strange thing - it only happens when I include initialization (public class MyInit : IExtensionApplication) in the code. If not - the command is executed properly. But I really need Initialize()...
    More strange things - as I can remember, it started when I changed ACAD from 2011 to 2012.

  12. It's likely to be due to the use of .NET 4 in AutoCAD 2012, at a guess.

    I suggest posting a more complete description of your problem (including whether this is when run from a debugger, using demand-loading or NETLOAD, etc.) to the AutoCAD .NET discussion group.

    Kean

  13. You wrote a great article on I appreciate your work admin.. I hope i will get more AllNew Softwares articles from this site.. 🙂

Leave a Reply to Kean Walmsley Cancel reply

Your email address will not be published. Required fields are marked *