Choosing the programming language to use for an AutoCAD development project

I just received this excellent question from a developer in Italy:

We've been developing a quite complex AutoCAD application based on ObjectARX (gear) and VB (GUI) and we're wondering if, after a migration in C#(?) we could maintain  same results in term of entities control, performances and so on. In few words, is it time to leave the thorny and painful ARX world to embrace the .NET heaven 🙂 ?

Before answering this question, I'm going to take a step back for a second…

Over the years I've been asked many times what "the best" API is to use for an AutoCAD development project. The answer has been pretty consistent, even if the technologies themselves have shifted. I almost always say "it depends" (and yes, I know that makes me sound like a lawyer ;-). The choice depends on a number of factors, some of which I've attempted to list here, in no particular order:

  • Legacy codebase – is there an existing legacy codebase, and does it work well for your customers? If so, are there interoperability paths to/from the legacy language to the language you're considering adopting?
  • Functionality coverage – what type of functionality is required from the language? Does it require hardcore number-crunching capabilities or is it all about a fancy or intuitive GUI? How do these requirements match up with the capabilities of a) the language and b) the API-set exposed via that particular API for AutoCAD?
  • Performance - related to the previous question is the question or performance. Does what you know about the performance of the language you're considering match the performance required by your customers?
  • Integration with other technologies – do you have a requirement to integrate with other products or services, and does the language have a track record of being able to support such integrations?
  • Version support - are the platforms you're required to support (both OS and AutoCAD version) all allow use of this language?
  • Skills – do you and your colleagues have experience of/competence in/confidence you'll be able to learn the language? How available are those skills on the market today – if you had to hire someone to work on your code, would it be easy to find the skills, or would their scarcity add a premium?
  • Vendor commitment – does the vendor (in this case we could consider Microsoft and Autodesk as being the primary technology providers) have a long-term commitment to that technology – not just in its availability but in its evolution? One obvious example here is VBA, which is – unless things have changed while I was napping – not being made available as a 64-bit version. Which effectively means there is little to no long-term commitment from Microsoft's side for this technology, which clearly limits the possible commitment from downstream vendors such as Autodesk.
  • Support – is there a solid knowledgebase available to you on this technology, and qualified, experienced support personnel? If you need to get out of a hole at short notice, is there someone you can call?

OK, so far I've managed to answer a question with about 17 others. 🙂 Let's try to tackle this one more directly…

I've personally always been an advocate of the right tool for the job. I believe that for professional programmers it's highly beneficial in today's world to know a number of different programming languages and methodologies. It increases your flexibility as the world inevitably shifts around you. I also believe that having a blend of technologies used on a major project – just as this Italian developer has described – is pragmatic. Having hardcore C++-heads work on the core engine while the UI developers work in VB would have been exactly the choice I'd have made several years ago (which is probably when the project was initiated). My choice today – if implementing a "green field" development project, with no legacy codebase to consider – would be oriented towards one or more .NET languages (given the performance profile of managed code inside AutoCAD, which is as close to native C++ as doesn't matter for most purposes, coupled with the UI possibilities provided by WinForms and – increasingly – WPF). The reason I say "one or more", is that there may be arguments for having different modules implemented in different languages, depending on the domain: C# and VB are pretty comparable at most levels (the decision tends to be made on religious grounds 😉 but throwing F# into the mix might be increasingly valid for certain domain areas where functional programming excels (mostly those domains with strong connections to the world of mathematics, but there are others, such as the example I showed in the last post).

Would I also choose ObjectARX? I might, depending on what was needed. Today it's still true that custom objects can only be implemented using ObjectARX (i.e. C++). I would consider the alternatives available to me carefully before heading down the path of implementing custom objects (we are continuing to work on ways to reduce the currently very significant resource investment needed to implement functionality currently only available through custom objects). I would personally invest in ObjectARX only if there was an absolute requirement for custom objects.

Having a homogeneous codebase does bring benefits, of course: all the code is in a particular language, uses the same tools and developers are able to dip in and out of different areas of the code without as much effort as might otherwise be required. But that's really an idealized scenario, and in this particular developer's case I'd look very carefully at the benefits that would be derived from migrating the entire codebase: I suspect the ObjectARX component would benefit very little from being ported to .NET, other than broadening the skillbase available to the company (and potentially reducing maintenance costs in the long run), but there might be more tangible benefit in refreshing the VB UI with something more modern-looking. The interoperability between native C++ and managed code is pretty comprehensive, so that should make life easier, especially if the ObjectARX components are already being exposed through COM for use from VB.

While this doesn't actually answer the question – which I can't do without knowing a lot more about the specific scenario – this does come a little closer, and hopefully gives a feel for what I would do when assessing the various options.

  1. Very well put, this is exactly what I've been thinking for our recent projects.

    As an ObjectARX developer my self, not long ago my answer would have been "ObjectARX, without a doubt", but as we've seen the .NET API mature and now we're having to consider interoperability with external .NET applications the choice is becoming more and more difficult!

    Since we have few ObjectARX developers the ability to leverage some of the C# knowledge we have elsewhere is a real advantage.

    Thanks for confirming what I'd already been half thinking!

  2. Thanks for such a precious article, It will definetly help many jr CAD Customization engineers and few new firms coming up and working in AutoCAD Customization.

  3. ObjectARX/C++ programmers should also consider C++/CLI when migrating to .NET.

    -The Ability to create mixed mode assemblies
    -Same language/environment for managed and unmanaged.
    -The ability to protect intellectual property by compiling
    sensitive code to native.

  4. Thanks, Daniel.

    Actually source code (IP) security is another factor I could have listed, thinking about it: although it may be acceptable to use obfuscation tools rather than compiling to native code.

    And yes - mixed mode modules provide great interoperability opportunities, although I would tend to use them to expose interfaces from C++ that can then be used by C#/VB.NET programmers. Having a completely homogeneous C++ environment isn't a path I'd recommend unless the domain in some way required it and the skills were readily available.

    Kean

  5. Fernando Malard Avatar
    Fernando Malard

    Hello,

    I would add a comment regarding the use of C++. I have worked on a project over Autodesk MAP which is supposed to access an Oracle database selecting and/or posting some objects.

    The first try was to use a .NET database provider which works great for a small set of objects but was a pain for a huge number.

    We have then switched to OO4O which is a C++ Oracle database provider which is really complex but a thousand times faster than the .NET provider.

    In this case, the use of C++ in this part of the project was mandatory.

    So the end of the story is that you really don't have one single magic API to use. A mix is welcome and you need to also consider other non-programming facts like team scalability, project cost, project development speed, code reuse, legacy APIs, etc.

    Good work Kean! 🙂

  6. Stephanie Winston Avatar

    we have been told that coldfusion is out dated and is not worth the computer it is coded on... how true is this?

  7. I know nothing whatsoever about ColdFusion, unfortunately.

    Kean

  8. Hello,

    I write applications for Autocad Map and Civil3d platforms, mostly with ObjectARX.
    I would like to do more with .NET but so far the main reason preventing this is not having the NETUNLOAD command..

    With arx I can just arxunload and arxload the application for modifications in a second.
    But with .NET I have to restart the heavy environment and do all kinds of lengthy initializations before being able to try even small changes in code, this can take a minute or more..

    Maybe it is possible to create an utility, for development purposes, to unload a .net assembly from Autocad ?

  9. Juhani -

    I was sure I'd posted about why NETUNLOAD doesn't exist, but I can't find the post. I'll try to put something together for next week. But that's not really your question, of course...

    It might be possible to create your own loader that would create a new AppDomain for each module loaded - that's what would need to happen to enable NETUNLOAD, unless Microsoft changes the way modules are loaded/unloaded in .NET. I don't know what would need to happen, but presumable some mapping would need to happen between the AutoCAD's AppDomain and the new one (I'm speaking largely from ignorance here - I haven't performed in-depth research on this topic).

    But the good news is that with Visual Studio 2005, Edit and Continue works well. So there should be a lot less reason to unload/reload.

    Regards,

    Kean

  10. Hi Kean, Some time has passed on this subject, I am interested to know if "it's still true that custom objects can only be implemented using ObjectARX (i.e. C++)"? Can or will Custom Objects be possible with C#? VS2010? Regards, Dale

  11. Hi Dale,

    Overrules are really the way forward. Admittedly they don't cover some of the edge cases (such as when people actually want to stored custom binary data in a drawing), but the existing custom object mechanism will continue to be available to people prepared to handle the complexity of using it from C++.

    At this stage we have no plans to extend the capability to define custom objects to the .NET API (but then again - with all that's going on in our industry - my crystal ball is looking increasingly murky, these days :-S).

    Kean

  12. Alexander Tohidi Avatar
    Alexander Tohidi

    Kean
    I need to ask the same question again as it is 2014 and 4 years have past since the last question was asked by Dale Bartlett:

    I am interested to know if "it's still true that custom objects can only be implemented using ObjectARX (i.e. C++)"? Can or will Custom Objects be possible with C#? VS2010?

    Regards

  13. Kean Walmsley Avatar

    Alexander,

    4 years have passed but my previous answer remains valid.

    Regards,

    Kean

  14. get_back_girlfriend Avatar
    get_back_girlfriend

    I run a website and I want to have a tool built for it to give quote automatically.

    I want to have them upload a .dxf file and I need to get the total area and the total line length (like if you use TLEN autolisp) of the drawing.

    Once I have these values I can plug them into a formula and give the customer a quote.

    I am looking to hire out having this done for me and have no idea where to start, what is needed or if it's even possible.

    Can you point me in the right direction?

    Thanks!

    1. You probably want to look at RealDWG, which can load DXF files and execute custom code to calculate areas and total lengths, etc.

      autodesk.com/realdwg

      You might also look at the Partner Products & Services website that lists ADN members who are available for contract work.

      autodesk.com/partner...

      Kean

      1. get_back_girlfriend Avatar
        get_back_girlfriend

        Thanks!

Leave a Reply to Stephanie Winston Cancel reply

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