Commands


  • Using IronPython with AutoCAD

    I've been meaning to play around with the Python language for some time, now, and with the recent release of IronPython 2 it seems a good time to start. Why Python? A number of people in my team – including Jeremy Tammik and the people within our Media  & Entertainment workgroup who support Python's use with Maya and MotionBuilder – are fierce proponents of the language. I'm told that it's an extremely easy, general-purpose, dynamic programming language. All of which sounds interesting, of course, although I have to admit I'm less convinced of the importance of the dynamic piece: I've…


  • Displaying a context menu during a custom AutoCAD command using .NET

    Some of you may have stumbled across these previous posts, which show how to add custom context menu items for specific object types and to the default AutoCAD context menu. There is a third way to create and display context menus inside AutoCAD, and this approach may prove useful to those of you who wish to display context menus during particular custom commands. One word of caution: I've been told that this technique does not currently work for transparent commands, so if your command needs to be called transparently then this may not be the approach for you (you should…

  • The question of how to perform a "NETLOAD" programmatically has come in a few times. Well, it turns out the answer - provided by someone in our Engineering team - is refreshingly simple. The NETLOAD command actually has a bare-bones implementation: the hard work of parsing the metadata defining commands etc. is done from an AppDomain.AssemblyLoad event-handler. To recreate the NETLOAD command, all you need to do is call Assembly.LoadFrom(), passing in the path to your assembly. Here's some C# code to demonstrate this: using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.EditorInput; using Autodesk.AutoCAD.Runtime; using System.Reflection; namespace LoadModule {   public class Commands   {  …


  • More quiet command-calling: adding an inspection dimension inside AutoCAD using .NET

    I'm still a little frazzled after transcribing the 18,000 word interview with John Walker (and largely with two fingers - at such times the fact that I've never learned to touch-type is a significant cause of frustration, as you might imagine). I'm also attending meetings all this coming week, so I've gone for the cheap option, once again, of dipping into my magic folder of code generated and provided by my team. The technique for this one came from a response sent out by Philippe Leefsma, from DevTech EMEA, but he did mention a colleague helped him by suggesting the…

  • This is an interesting one that came up recently during an internal discussion: During my module's Initialize() function, I want to decide that the module should not actually be loaded. How can I accomplish that? The answer is surprisingly simple: if you throw an exception during the function, AutoCAD's NETLOAD mechanism will stop loading the application. For an example, see this C# code: using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.EditorInput; using Autodesk.AutoCAD.Runtime; namespace PreventLoad {   public class Commands   : IExtensionApplication   {     public void Initialize()     {       // This will prevent the application from loading  …

  • Since posting three different options for Zooming to a Window or Entity inside AutoCAD, I've had a few discussions with a developer on how best to implement this cleanly. The requirement is to change the AutoCAD view via a smooth view transition (currently not exposed via any kind of view-modification API, only via the ZOOM command), but also to hide the fact we're sending commands to the command-line to do so. While we were discussing, I remembered an old friend, the NOMUTT system variable, which allows almost all command-line noise to be filtered out - even the "Command:" prompt disappears.…


  • Catching exceptions thrown from dialogs inside AutoCAD using .NET

    Another juicy tidbit from an internal Q&A session. The question... How can I throw an exception from within a modal form on mine inside AutoCAD, and catch it in the calling command? I have tried try/catch, but nothing seems to work. Here's my command definition: using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.Runtime; using System.Windows.Forms; using MyApplication; using acApp =   Autodesk.AutoCAD.ApplicationServices.Application; namespace CatchMeIfYouCan {   public class Commands   {     [CommandMethod("CATCH")]     static public void CatchDialogException()     {       try       {         MyForm form = new MyForm();         DialogResult res =  …


  • Using the P/Invoke Interop Assistant to help call ObjectARX from .NET

    Thanks to Gopinath Taget, from DevTech Americas, for letting me know of this tool's existence. I've often battled to create Platform Invoke signatures for unmanaged C(++) APIs in .NET applications, and it seems this tool is likely to save me some future pain. The tool was introduced in an edition of MSDN Magazine, earlier this year. [For those unfamiliar with P/Invoke, I recommend this previous post.] While the Interop Assistant can be used for creating function signatures to call into .NET assemblies from unmanaged applications, I'm usually more interested in the reverse: calling unmanaged functions from .NET. Let's take a…

  • 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…

  • Most members of my team (DevTech) have a background in software development, having developed code professionally in previous jobs. People often join DevTech because they enjoy the variety and flexibility the role brings as well as the direct communication we have with the Autodesk development community. That said, we still like to hone our coding skills - some of this we get from fielding questions we receive from ADN members but it's also helpful to work on the odd software project. Back in the day - during my stint living in India - DevTech was part of Autodesk Consulting and…