Commands

  • Here's an interesting question that came in from Kerry Brown: Is there a way to determine the names of Commands loaded into Acad from assemblies ... either a global list or a list associated with a specific assembly ... or both 🙂 I managed to put some code together to do this (although I needed to look into how AutoCAD does it to get some of the finer points). I chose to implement two types of command - one that gets the commands for all the loaded assemblies, and one that works for just the currently-executing assembly. The first one…

  • This very good question came in by email from Patrick Nikoletich: I was wondering what the preferred method for overriding the default "Open" common dialog in AutoCAD 2007 would be? I can catch the event but can't send AutoCAD a command to cancel the request so I can launch my Win Form instead. This is quite a common requirement - especially for people integrating document management systems with AutoCAD. The simplest way to accomplish this - and this technique goes back a bit - is to undefine the OPEN command, replacing it with your own implementation. The classic way to…

  • Thanks to Viru Aithal from the DevTech team in India team for this idea (he reminded me of this technique in a recent ADN support request he handled). A quick disclaimer: the technique shown in this entry could really confuse your users, if implemented with inadequate care. Please use it for good, not evil. I talked at some length in previous posts about MDI in AutoCAD, and how various commands lock documents when they need to work on them. When commands try to lock (or unlock) a document, an event gets fired. You can respond to this event in your…

  • Another case of planets aligning: two different people have asked me this question in two days... It's quite common for commands to require users to provide additional input during execution. This information might be passed in via a script or a (command) from LISP, or it may simply be typed manually or pasted in by the user. The fact is, though, that commands don't actually take arguments. It may seem like they do, but they don't. What they do is ask for user input using dialogs or the command-line. Here are a few tips on how to support passing of…

  • In this earlier entry I showed some techniques for calling AutoCAD commands programmatically from ObjectARX and from VB(A). Thanks to Scott Underwood for proposing that I also mention calling commands from .NET, and also to Jorge Lopez for (in a strange coincidence) pinging me via IM this evening with the C# P/Invoke declarations for ads_queueexpr() and acedPostCommand(). It felt like the planets were aligned... 🙂 Here are some ways to send commands to AutoCAD from a .NET app: SendStringToExecute from the managed document object SendCommand from the COM document object acedPostCommand via P/Invoke ads_queueexpr() via P/Invoke Here's some VB.NET code…

  • This is an interesting little problem that came in from Japan last week. Basically the issue is understanding how to call the DIMARC command programmatically from LISP using (command). The DIMARC command was introduced in AutoCAD 2006 to dimension the length of arcs or polyline arc segments. What's interesting about this problem is that it highlights different aspects of entity selection in LISP. Firstly, let's take a look at the DIMARC command (I've put the keyboard-entered text in red below): Command: DIMARC Select arc or polyline arc segment: Specify arc length dimension location, or [Mtext/Text/Angle/Partial/Leader]: Dimension text = 10.6887 The…

  • Thanks to Alexander Rivilis for this topic (he submitted a comment to my previous post that got me thinking about this addendum). When you're asking AutoCAD to execute commands by submitting them to its command-line, it helps to make sure no command is currently active. The accepted approach is to send two escape characters to the command-line... this is adopted by our menu & toolbar macros that consistently start with ^C^C in MNU and now CUI files. Why two? The first is to cancel the "most active" command, and the second is to drop out of either the dimension mode…

  • It's quite common to want to call commands from one or other of AutoCAD's programming environments. While it's cleanest (from a purist's perspective) to use an API to perform the task you want, the quickest way - and the one which will appeal to the pragmatists (and the lazy) among us is often to call a sequence of commands. And there are, of course, a few places in AutoCAD where APIs have not been exposed, so scripting commands is the only way to achieve what you want. Let's take the simple example of adding a line. Here's what you'd do…