This was a topic suggested by Scott Underwood (thanks, Scott! 🙂 to look at COM vs. NET and go through their respective advantages and disadvantages…

This is really an interesting discussion topic, and one that I'd like people to help turn into an interesting discussion. I can certainly talk about the differences and pros/cons of the two technologies from my own memory/experience/perspective, but others will have things to say on this, I'm sure... please feel free to do so! 🙂

Rather than going into low-level detail on either COM or .NET, I'd suggest looking into their respective Wikipedia sites. Both do a fair job of listing the criticisms made about the respective technologies, but not all will apply here (the .NET Framework is part of the AutoCAD install, so availability/deployment is not such a big issue for us, for instance).

So let's start with some generally AutoCAD API background…

Both COM and .NET APIs (and actually also AutoLISP, since it's re-implementation as Visual LISP back in R14.01) are implemented via ObjectARX – they are basically ARX modules loaded into AutoCAD that expose COM and managed interfaces respectively. That said, as more core AutoCAD development happens using .NET, it's no longer necessarily true that managed interfaces will always be exposed through (and available in) ObjectARX. The decision about which technology to use to expose an API is driven by its market requirements.

Now a little more specific history on each of the technologies…

COM Automation (originally OLE Automation, changed to ActiveX Automation, and now it's either COM Automation or just Automation)

AutoCAD's COM Automation API was first introduced with VBA back in R14.01. At the time it was pretty revolutionary, as it was an API that was implemented via a technology that genuinely allowed developers to choose their own development technology (as long as it was Visual Basic… just kidding ;-). It was also the technology that enabled some very clever features in AutoCAD: the Properties Palette uses COM Automation to query and edit properties of objects, for instance. QSELECT is another one.

One of the big problems with COM is the effort needed to expose COM interfaces: the COM Automation standard supports a relatively small set of data-types (unless you make nearly everything its own object, and that just gets unmanageable), which means that complex C++ interfaces need to be fundamentally re-designed (often flattened) to be exposed through COM.

.NET

When AutoCAD was first built using Visual Studio .NET (during the AutoCAD 2004 timeframe), the door was opened to expose a managed API. While this was prototyped on AutoCAD 2004, it first made it into the shipping product as part of AutoCAD 2005. Exposing a managed interface is much easier than a COM Automation interface... in fact the AutoCAD team has managed to semi-automate the process of exposing its managed interfaces. This definitely helps us keep the managed API in synch with ObjectARX, where - as mentioned earlier - much of it is exposed from.

Incidentally, a managed API to AutoCAD also enables Autodesk to do more internal development using .NET, rather than all of it being in unmanaged C++ (much of its feature development work is still done in C++/ObjectARX, but that's changing). It enables us to take advantage of many of the advantages of the .NET Framework, such as the tools around creating user interfaces, accessing data, etc.

And now let's compare some of the specific differences, stepping through some typical API comparison criteria, one-by-one... (I would have liked to make a little matrix showing this, but felt the need to flesh out the explanations.)

Performance

Both technologies are comparable in terms of speed of execution – neither introduce much execution overhead when compared with ObjectARX (unless you're using COM out-of-process – more on that later).

Future-proofness (if that's even a word 🙂

COM is being extended as per the needs of various AutoCAD features (Properties Palette support, etc.), but you will see more rapid expansion of .NET capabilities. Additionally Microsoft is 100% behind .NET, and I genuinely believe it has a much brighter future.

Simplicity

This is subjective, but overall I would say the COM object model is simpler to learn. That doesn't mean I prefer it, though. (How's that for subjective? 🙂

Power

.NET is more extensive in terms of its level of API exposure and also has more powerful platform capabilities (although that's more when you get into comparing VB6 with VB.NET).

Interoperability

COM environments such as VBA/VB6 can use all sorts of COM components and even DLL/EXE exports, but from .NET you can use much, much more (COM, .NET, native C++ etc.)

Support in shipping AutoCAD versions

COM is available throughout our shipping versions of AutoCAD while .NET is not quite there yet. Although it won't be long before all supported versions of AutoCAD have a managed API, our .NET implementation evolved substantially between 2005 and 2006, and AutoCAD 2005 will still be supported for some time. If you need to support multiple versions, this is something you need to be aware of.

IPC (Inter-Process Communication)

COM's big advantage – and frankly the main reason I use it at all – is that it was designed to be used across processes. While .NET Remoting is possible with some applications, AutoCAD's managed interface was not designed to work across the process boundary (just as ObjectARX was not).

Conclusion

If I had to learn a new API for AutoCAD at this stage (and didn't know any of them), I would choose .NET. It may be more complex to learn, but it is more extensive, it has better long-term potential both as an API and a programming environment (in terms of support from Microsoft and Autodesk), and frankly you can make very easily make use of AutoCAD's COM Automation interface from a .NET environment. It has very good coverage of the overall ObjectARX feature-set, and much of what isn't exposed can be accessed using P/Invoke. If you need to drive AutoCAD from an external executable, then I'd suggest using COM to drive AutoCAD out-of-process, loading a .NET component in-process to do the heavy lifting.

The main caveat about all this is around platform support. Until your customer(s) all use a version of AutoCAD that exposes the API set you need, you might well need to invest time developing with other technologies. This was also an issue when ADS, ObjectARX and COM/VB(A) were introduced (and probably even AutoLISP, although I don't go back quite that far).

32 responses to “COM vs. .NET in AutoCAD”

  1. What about the VSTA for AutoCAD?

  2. It's being considered. I can't comment on whether/when it might happen, though.

    Something I've been wondering about that you might be able to help me with... with the availability of the free Express versions of Visual Studio, how relevant is it for people to have an integrated .NET IDE such as VSTA?

  3. There's a couple issues with DLL versioning (between AutoCAD releases, as well as sometimes within an AutoCAD release) that are worth noting as down-sides to .NET.

    cadappdev.blogspot.c...

  4. Hi Matt,

    Thanks for your feedback (I’m impressed with how quickly it came, as well! 🙂

    A couple of comments on your blog post:

    “If 17.0.54.0 is not available later, you're out of luck...”

    Actually, no: acmgd.dll is no longer strongly signed, so the version of the assembly should not be considered during binding. Later versions of acmgd.dll should work, too, unless there’s been a signature change (more on this later). It was absolutely a problem with AutoCAD 2005, but we fixed it in 2006.

    “Each release of AutoCAD will have a different version of acmgd.dll... And as a result, your application will need to be recompiled for each version.”

    Again, this isn’t quite right. In theory you should not need to re-compile for each version unless there are signature changes.

    So, when do we allow signature changes?

    We introduced the managed API in AutoCAD 2005, but there was a lot more we needed to do to make it complete enough for serious use. So between AutoCAD 2005 and 2006 the decision was made not to enforce compatibility at a signature level.

    Between AutoCAD 2006 and 2007 we deliberately broke compatibility, yes, but that was in sync with the overall break in application compatibility.

    As we are aiming to maintain application compatibility between AutoCAD 2007 and the next two releases, you should experience the same level of compatibility you have enjoyed with ObjectARX.

    Cheers,

    Kean

  5. Kean,

    Is there a way to send a command from VBA to command line, such that you call a lisp interface exposed through ARX which takes some input parameters too?

    For example: I have a function written in ARX that is exposed through LISP. So you can type on command line (doSomethingWithThisFunction selectionset name)

    where:
    doSomethingWithThisFunction is the name of function exposed through LISP interface from ARX

    selectionset is an AutoCAD selectionset

    name is just a string

    Problem is when I use ThisDrawing.SendCommand () from VBA it treates the LISP function and its arguments as three separate commands

    To sum it up I need to be able to call a command line function from VBA, such that the function also takes some parameters.

    Is that possible?

    Thanks

  6. Reply posted to:
    keanw.com/...

  7. COM is very useful for scripting with ...scripting languanges (py,lua,tcl etc) but it all goes wrong when you try to pass points to autocad. COM defines them as variant arrays, autocad accepts them as (raw?) arrays of doubles (notice the declarations in VB code examples). A workaround for py exists but i haven't got it to work 🙁

    .NET is probably an even bigger mess than COM -use tcl instead!

  8. I've come across this problem when using JavaScript (which is unsupported for using our COM API). I'm not sure how tcl is meant to help, though.

    Kean

  9. The problem is in how your COM API exposes point arguments for your methods-a very generic variant array (12,1) instead of an array of doubles (8197,1) and "unsupported" languages can't transform data correctly. The only ones that do are VB and Delphi... (check google:A Sip From The Firehose: Tuesday, May 5, 1998 (! 10 years)).
    And by the way Intellicad doesn't have that problem...
    As for for tcl, if you can't feel the "love"...

  10. JavaScript was never a target client environment for our COM API, which we implemented from the beginning to use SafeArrays (the right way to implement type-safe arrays in COM). SafeArrays are not supported from JavaScript, only JScript. Type safety is an important feature of our API design and is currently more important than supporting JavaScript.

    If we were to suddenly receive significant feedback from customers that we needed to support JavaScript, then we would look at how best to do so (probably by exposing a new set of JavaScript-friendly methods, so as not to break the existing ones), but in all honesty this is not something we're hearing today.

    Incidentally, there's no magic behind our COM API implementation: someone with sufficient knowledge of C++ and COM could use ObjectARX to expose a JavaScript-friendly API layer, should they so wish.

    Kean

  11. Sorry, no more "aMeSs" programming for me. I'd rather tinker with tcl's com interface.
    Thanks for taking the time to answer.

    Loukas

  12. bonjour kean,
    Je suis entrain de programmer une application qui doit êtres s’exécuter sous autocad , j’ai choisi le.NET comme langage de programmation mais j’ai trouvé une difficulté pour trouver les fonctions qui existe déjà dans .COM comme par exemple : la fonction « Autodesk.AutoCAD.Interop.IAcadUtility.AngleFromXAxis(object, object) » , la fonction Rotate(point,angle) et la fonction Move(point,point) toute ces fonctions je les ai pas trouvé dans .NET, est ce qu’elles existent ou non ?.

  13. Asmaa -

    Not all the functions exposed through COM are there in .NET. You can still call the COM functions, if you wish to, but otherwise you will certainly be able to implement what you need using the managed (.NET) API.

    I unfortunately don't have time to provide personal support, so you have a few options for getting help, as mentioned in my last response to this question:

    The AutoCAD .NET Discussion Group
    The ADN website (if you're a member)
    Le forum francais pour AutoCAD

    Regards,

    Kean

  14. Hi
    I would like to know, the .NET compatablility between diffrent versions of AutoCAD ?

    i.e if I write a Code in 2005 will it be valid for Higher versions ?

    if AutoCAD is changing function names in .NET APIs, then the above one will become a big issue.
    for example

    say MText AcadMtext;
    AcadMtext.SetContent is available with 2005 and not with 2009

    say Leader AcadLeader ;
    ...
    AcadLeader.AttachAnnotation // method in 2005

    AcadLeader.Annotation // propety in 2009

  15. Not necessarily. A lot changed between 2005 and 2006, for instance (as 2005 was only our initial release - we ended up making a number of fundamental changes in 2006). Since 2006 things have stabilized substantially.

    A rule of thumb is: build against the managed assemblies for the various versions you wish to support (this will highlight any interface changes) and build the version you want to ship against the managed assemblies from the oldest version you wish to support.

    Kean

  16. Hi Kean,
    Thanks for the answer on Compatability of code over diffrent versions of AutoCAD,

    I have another question,

    to overcome this problem Can I opt for COM programming ?

    I do not need to anything great With AutoCAD fetures, other than basic drawing commands line and dimension.

    with COM I think if i re compile the code for the new version of AutoCAD it should work,
    unlike .NET where the function names itself have been removed or changed etc.

    please give your suggestions
    thanks again.
    regards
    ganti

  17. Kean Walmsley Avatar

    You might, but it creates other problems. You're actually more version dependent if you use a TypeLibrary (the best option in this case is late binding, but that's a pain even in VB).

    If you had only to support 2006 onwards, .NET would be by far the better way to go, IMO.

    Kean

  18. Coming from a longtime AutoLISP programmer who is (finally) ready to jump to .net, should I learn C++ or C#. Any suggestions?

  19. Hi Kean,
    this in reference to which is better COM or .NET,

    I do agree that .NET is a better way to go,

    but I have to support Multiple versions of AutoCAD from 2005 onwards, (for what ever reasons, many users have not upgraded to higher versions)

    in such a case when dealing with COM programming
    i just need to replace
    Autodesk.AutoCAD.Interop.dll
    Autodesk.AutoCAD.Interop.Common.dll
    Interop.AutoCAD.dll

    based on version of AutoCAD in use,
    and we need not change any code (not even re-compile).

    but in case of .NET, there is an inherent problem of functions becoming obsolete in the next version

    correct me if I am wrong
    please advice
    regards
    ganti

  20. Kean Walmsley Avatar

    Tim -

    I'd suggest starting with wither VB.NET or C#. Your pain will be significantly lower for similar capabilities (at least as far as AutoCAD is concerned).

    Ganti -

    I disagree. There are minor areas where funtionality has shifted from release to release, but that's to some degree to be expected from an evolving API (which COM is not). We break compatibility in a very controlled way, only allowing changes that affect application compatibility every 3 releases. And if you use a controlled subset of the managed API, you can build an application for AutoCAD 2006 that works on AutoCAD 2010.

    If you want to use COM Interop given your need to support AutoCAD 2005, please go ahead. You might want to post to the discussion groups to get some opinions from there, too.

    Kean

  21. Hi Kean,
    I've discovered this blog a while ago but I still discover some unread -but interesting- posts!

    I'm trying to introduce .net development in my application (full c++/objectarx) since a while but it would require me to develop a full set of managed wrappers for hundreds of AcDbXxx inherited custom objects and entities... yet, I've read here that "in fact the AutoCAD team has managed to semi-automate the process of exposing its managed interfaces[...]"... gosh!
    So, the question that follows is pretty obvious (!): Is AutoCAD team able to provide oarx/dbx developers with a such tool?
    (if not, Is AutoCAD team able to provide me with a such tool? 🙂
    I'm willing to deprive my kids of christmas presents to buy this tool... (joke (?!))

    Thank you

  22. Hi Loic,

    The tool was very much for internal use, and depended a great deal on the relative consistency of the function prototypes in the ObjectARX SDK headers. I'm also not sure it has been continued to be used as we moved to more recent versions of the .NET Framework (I don't know whether it was adapted to use newer versions of managed C++, for instance). I'll have a word with a few people and follow up separately by email.

    Regards,

    Kean

  23. Hi Kean
    I wonder if it is possible at all to drive Autocad 2004 (e.g. open the application)from a managed C# program compiled with vs2005.
    I can do it for 2008 but didn't succeed for 2004.
    The purpose is to open any Autocad version from the same program.
    Thanks
    alex

  24. Kean Walmsley Avatar

    Hi alex,

    You should certainly be able to launch and drive it via COM. Using .NET directly is another story - that won't work (firstly because there wasn't a .NET API in the 2004 release, and secondly because our .NET API isn't directly useable out-of-process).

    Regards,

    Kean

  25. Hi Kean
    Thanks for answering.
    I need to explain myself a little better:
    The program tries to connect to a running instance of Autocad. If it doesn't find one, it will try to launch a new session.
    It works ok for v2004 (if compiled against v16 assemblies) and also for v2008 if compiled against v17 assemblies.
    What I'm trying to do is to have the same program work for both versions.
    Can you help me here?
    Thanks
    alex

  26. Hi alex,

    Take a look at Type Embedding (although that was certainly introduced after VS2005), which will allow you to not depend on a specific Interop/Type Lib.

    You might also be able to use late binding (or the equivalent).

    Regards,

    Kean

  27. Thank you
    I shall try
    Regards
    alex

  28. Hi Kean.
    This probably belongs to a specific block page, but I couldn't find the right one, so here it is:
    I'm trying to modify Block definitions in dwg files from an out-of-process app. <ul>It has to work for ACAD 2004.</ul>
    I can add entities to the block definition but only when I know the entity type in advance (e.g. block.AddLine etc.)
    I notice there is no generic AcadBlock.Add() or AddObject() or AddEntity().
    Would it be possible to do it without this?
    Thanks
    alex

  29. Hi alex,

    This actually belongs more on the AutoCAD VB Discussion Group (as if you need to support 2004 you won't even be able to use .NET).

    I'm not sure what it means for you not to know the type of entity you want to add to the block in advance (it's not something you can decide later).

    Regards,

    Kean

  30. Hi Kean.
    No VB, I'm talking C#, and I get use .NET for 2004 (granted with some missing functionality which was added in 2005 and later).
    ..not knowing the type of entity to add:
    What I mean is I need to copy entities from a source (e.g. another drawing) and add them to the block definition, without checking the types.
    Thanks
    alex

  31. Hi alex,

    I mentioned the VB group because I assumed you're using COM (anything .NET related in 2004 would have been very unstable and at this point unsupportable).

    Please post to the discussion group you prefer - this blog really isn't the place to get support.

    Regards,

    Kean

  32. Kean
    Thank you.
    alex

Leave a Reply to Kean Walmsley Cancel reply

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