Migrating .NET applications to work with AutoCAD 2013

I'm on my way to San Francisco for some internal meetings (including a Hackathon, over the weekend, which should be fun), but have unfortunately been held up at Heathrow by fog (it delayed my inbound flight, along with many others', but somehow didn't stop my outbound flight from leaving, which always seems to be the case… I then had to queue for 2.5 hours to get a new flight, the only highlight of which was standing behind members of the junior Kuwaiti ice hockey team [at least that's what they said they were – they may have been pulling my leg {it was that kind of day :-}]). And so, having spent the night at the Holiday Inn on junction 4 of the M4, I'm now at the airport waiting to catch my Virgin Atlantic flight (a change from BA) to SFO.

I've decided to skip talking about the other new APIs in AutoCAD 2013, for now – I'll look at that more closely next week – but did want to get back to the issue of migrating .NET applications to work with AutoCAD 2013.

Yes, there is a break in binary compatibility for .NET applications in this coming release. ObjectARX developers have been used to see application compatibility (only) broken every 3 releases since AutoCAD R14, but this is the first time that .NET applications will have needed to be rebuilt since AutoCAD 2007 – at least for developers relying on the core API capabilities made available in that release. Which means there are many applications out there with .NET modules that work for AutoCAD 2007-2012.

Mainly due to The Big Split mentioned in this previous post, we now have an additional DLL dependency in .NET projects for AutoCAD 2013: you need to include a project reference to AcCoreMgd.dll (in addition to AcMgd.dll and AcDbMgd.dll). If you use the opportunity to write "core" apps (which can, for instance, be loaded in the Core Console) then you will end up replacing your reference to AcMgd.dll with one for AcCoreMgd.dll.

That's the big change, and the reason why it will be impossible to load older applications in AutoCAD 2013 – the binary code implementing API functionality has physically moved – but for good reasons.

Along with API implementations moving from acad.exe to AcCore.dll (and their public declarations moving from AcMgd.dll to AcCoreMgd.dll), we've also added some namespaces to house extension methods for API capabilities that need to be used in full (rather than core) applications: DocumentExtension, DocumentCollectionExtension, EditorExtension, WindowExtension. You will find that certain methods can't be found when you reference the AutoCAD 2013 DLLs – in most cases it's a simple matter of adding the right namespace to your project, but in a few cases you'll find properties/methods have been renamed – mostly to make them more descriptive.

For instance, the existing property to get AutoCAD's status bar is:

Autodesk.AutoCAD.ApplicationServices.Document.StatusBar

In AutoCAD 2013, this has been changed to:

Autodesk.AutoCAD.ApplicationServices.DocumentExtension.GetStatusBar()

So a little different, but hopefully not to find to track down and manage. The ObjectARX SDK contains migration information that will help identify and make these changes.

An important point to note is that you'll also need to target .NET 4 for your applications to work with AutoCAD 2013.

Those are the main migrations steps, then:

  1. Change your project's settings to target .NET 4 (if it doesn't already)
  2. Add an assembly reference to AcCoreMgd.dll
  3. Fix your code to compile properly, which may mean:
    • Changing property and method names, as per the migration guide
    • Adding namespace references (Imports or using statements) to a few new namespaces

Stephen Preston tells me it took him about 10 minutes to migrate the MgdDbg sample project – which exercises a huge amount of the AutoCAD API, so is a pretty good reference for a real-world application.

A few additional points to note…

If you're using COM Interop, you'll find the interop assemblies are no longer registered in the GAC (i.e. you won't find them on the COM tab in the Add Project References dialog). You'll now need to browse to Autodesk.AutoCAD.Interop.dll and Autodesk.AutoCAD.Interop.Common.dll (I believe) in the AutoCAD Program Files folder or on the ObjectARX SDK. Hopefully Visual Studio will know to embed types from these assemblies, which will make deployment more straightforward.

Speaking of deployment… yes, you will need to have (at least one) different module(s) to support AutoCAD 2013 along with AutoCAD 2007-2012 (the number will depend on your application and how it is structured), but using the Autoloader will definitely simplify your deployment of these modules for different releases.

It should also be possible to have the same source files build to different modules (you may need to add some conditional compilation settings – something I should address in a blog post, at some point).

My flight's gate is about to open, so I'd better sign off. I don't want to miss this one!

Update:

Stephen Preston just pointed me to a thread on The Swamp where the question of the terminology used to describe the containers housing these extension methods (namespaces vs. static classes) has come up. Stephen has addressed the question in a post on the AutoCAD DevBlog, where he explains the reason for the confusion. It seems I'd unwittingly propagated this confusion in this blog post, so be sure to check Stephen's post if you're in any doubt on this issue.

41 responses to “Migrating .NET applications to work with AutoCAD 2013”

  1. Any idea on where/when we can get our hands on the 2013 version of MgdDbg and its aec sibling?

  2. Hi Kean:

    I was wondering if we can utilize the Civil 3D API to create tables with same level of customization that is available to AutoCAD tables.

    At present, AutoCAD table are more flexible with style and formatting but when imported in Civil 3D, they don't dynamically update with the modifications done in Civil 3D document. However, the Civil 3D tables does the job of dynamic update but they lack the flexible styling component.

    I would appreciate if you can share some ideas or provide a sample code for this issue.

    Thank you.

  3. Good question, and I don't know the answer. I suggest contacting ADN (assuming you're a member), to get it from them.

    Kean

  4. Hi James,

    I think I already answered this.

    Regards,

    Kean

  5. Thanks for the reply Kean. Prior to posting I had checked if it was up there, and only the 2012 versions were. I will submit a request for it.

    On a side note, a very useful thing for us would be SVN repository access to projects like that and others like you create, so we could compare revisions and see what exact changes were made. Food for thought.

  6. Hi Kean,
    I use vs2005 and acad2007. In VB.net, reference to the COM ( Autocad 2007 Type Library ; Autocad / objectDBX common 17.0 Type Library), found that with AcadSelectionSet have filter conditions unsuccessful. Code as follows:

    Public app As AcadApplication = Application.AcadApplication
    Public thisdrawing As AcadDocument = app.ActiveDocument
    Dim ss As AcadSelectionSet
    Dim gpcode (0) As Integer
    Dim datavalue (0) As Object
    gpcode (0) = 8
    datavalue (0) ="0"
    Dim groupCode As Object
    Dim dataCode As Object
    groupCode = gpcode
    dataCode = datavalue
    ss = thisdrawing.SelectionSets.Add ("ss0")
    ss.Select (AcSelect.acSelectionSetAll,,, groupCode, dataCode)

    Finally did not select the entities,What is the reason? Thank you!
    li

  7. Hi li,

    This isn't a support forum: please post your question via ADN (if you're a member) or to the AutoCAD .NET discussion group.

    Regards,

    Kean

  8. To target 2010 and 2013 what I'm doing so far is creating one configuration for each platform, editing by hand the .csproj file and adding a Condition attribute on the references. Like this:

    To target 2010 and 2013 what I'm doing so far is creating one configuration for each platform, editing by hand the .csproj file and adding a Condition attribute on the references. Like this:

    <Reference Include="AcCoreMgd" Condition=" '$(Configuration)' == 'Debug 2013' Or '$(Configuration)' == 'Release 2013' ">
    <HintPath>C:ObjectARX 2013incAcCoreMgd.dll</HintPath>
    <Private>False</Private>
    </Reference>
    <Reference Include="AcDbMgd" Condition=" '$(Configuration)' == 'Debug 2013' Or '$(Configuration)' == 'Release 2013' ">
    <HintPath>C:ObjectARX 2013incAcDbMgd.dll</HintPath>
    <Private>False</Private>
    </Reference>
    <Reference Include="AcMgd" Condition=" '$(Configuration)' == 'Debug 2013' Or '$(Configuration)' == 'Release 2013' ">
    <HintPath>C:ObjectARX 2013incAcMgd.dll</HintPath>
    <Private>False</Private>
    </Reference>
    <Reference Include="AcDbMgd" Condition=" '$(Configuration)' == 'Debug 2010' Or '$(Configuration)' == 'Release 2010' ">
    <HintPath>C:ObjectARX 2010inc-x64AcDbMgd.dll</HintPath>
    <Private>False</Private>
    </Reference>
    <Reference Include="AcMgd" Condition=" '$(Configuration)' == 'Debug 2010' Or '$(Configuration)' == 'Release 2010' ">
    <HintPath>C:ObjectARX 2010inc-x64AcMgd.dll</HintPath>
    <Private>False</Private>
    </Reference>

    This works, but I duplicate the condition for each reference. Is there a way to avoid that
    This works, but I duplicate the condition for each reference. Is there a way to avoid that?

    I've tried with choose (msdn.microsoft.com/fr-fr/library/ms164282.aspx) but VS doesn't like. Have you find a better solution?

  9. I can see this isn't quite ideal, although it's good to know you've found something that at least works. 🙂

    I admit I haven't looked into this myself, as yet. It may be that someone on the AutoCAD .NET Discussion Group has something to share...

    Kean

  10. This is the same approach we take, although we have it worse as we support 2010, 2011, 2012 and now 2013. Oh and we have switches to build 64-bit and 32-bit versions of out plugin to suit the two versions.

    Luckily we found away of compiling the DLL so it works in both Civil3D and vanilla AutoCAD otherwise we'd be at 16 DLLs!!

  11. Kean,

    Thanks for the post, its been a really useful article - it seems a long time since this was discussed at the ADN day in Farnborough in December!

    One thing though, do you have a link to the 'Migration Guide' you mentioned? I have looked but can't seem to find it :/

    Cheers

    Mat

  12. Mat,

    Yes, time flies...

    Hmm - I assume it's there in the docs download for the ObjectARX SDK (which I don't have, at the moment).

    If it isn't, please do ping ADN, and they'll point you in the right direction.

    Cheers,

    Kean

  13. Mathew, Could you elaborate on this: "we have switches to build 64-bit and 32-bit versions"?

  14. In your post you mention "changing property and method names as per the migration guide". Where is this migration guide you refer to? I have tried searching the web but only get a reference back to this post.

  15. If you download the ObjectARX SDK Documentation (a 100MB download you can get to via objectarx.com), you should find it in the docs folder (at least I assume so - I'm on holiday and so can't confirm).

    Kean

  16. Martin Müller Avatar
    Martin Müller

    Is an old post, however, probably somebody searching for this will find it usable: I copy the project file, rename it to something useful, like xyz2013, xyz2014, change its internal GUID in an editor, attach it as an existing project to the solution and change the references to point to the new libraries. Then I define a compiler constant in each project file to distinguish code between the differen Acad versions, while basing on the same source files. Then I create different configurations for each platform at the configuration manager and activate/deactivate the relevant/irelevant projects here. I find this much more simple, than editing the project file.

  17. Stanislav Okhvat Avatar

    Hello, Kean,

    I have been following your blog for some time, especially with regard to AutoCAD VBA support. I have a question concerning binary compatibility in AutoCAD VBA projects which I find really confusing.

    Lately, one user of my DVB library reported a binary compatibility error in Autocad 2014. The DVB file was compiled in Autocad 2010, and upon installing the trial version of Autocad 2014 I discovered that the reference to Autocad 2010 (v. 18) was broken. Removing the old reference and adding a reference to 2014 fixed things, of course. But here's the interesting part. I have the same DVB file compiled in Autocad 2008 and it works fine in Autocad 2010, 2012 and 2014. To add to the confusion, I tested the 2014 file in Autocad 2012 and 2008 and it worked fine in both of them! Also, the 2010 version works fine in version 2008. I have always believed (and testing verified this) that a DVB add-in compiled against a version after 2002 works correctly in all older versions. Clearly, this rule is broken as far as v. 2010-2012 (18) is concerned. I would appreciate your help.

    Thanks a lot.

    Best regards,
    Stanislav

  18. Станислав Охват Avatar
    Станислав Охват

    Hello, Kean,

    I have been following your blog for some time, especially with regard to AutoCAD VBA support. I have a question concerning binary compatibility in AutoCAD VBA projects which I find really confusing.

    Lately, one user of my DVB library reported a binary compatibility error in Autocad 2014. The DVB file was compiled in Autocad 2010, and upon installing the trial version of Autocad 2014 I discovered that the reference to Autocad 2010 (v. 18) was broken. Removing the old reference and adding a reference to 2014 fixed things, of course. But here's the interesting part. I have the same DVB file compiled in Autocad 2008 and it works fine in Autocad 2010, 2012 and 2014. To add to the confusion, I tested the 2014 file in Autocad 2012 and 2008 and it worked fine in both of them! Also, the 2010 version works fine in version 2008. I have always believed (and testing verified this) that a DVB add-in compiled against a version after 2002 works correctly in all older versions. Clearly, this rule is broken as far as v. 2010-2012 (18) is concerned. I would appreciate your help.

    Thanks a lot.

    Best regards,
    Stanislav

  19. Hello Станислав,

    Sorry for the delay - both of your comments were flagged as spam, for some reason.

    I'm no expert on VBA compatibility between versions: I would think that if you build with the oldest product version you support then you would be able to load the DVB in earlier versions. Going backwards is always more tricky, even if the COM API hasn't evolved significantly in recent years there is a greater risk.

    It could also be some kind of compatibility issue was introduced when we decoupled VBA in the 2010- timeframe, but then I haven't heard of anything like that, myself.

    Best regards,

    Kean

  20. Hi,I am going to migrate autocad 2005 to autocad2014 and instead of using LISP routines I am using VB.Net.What will be the steps that I need to carry out in order to achieve it.There will be slide libraries and block symbols in autocad 2005 that need to be migrated from 2005 to 2014,how is that Possible?
    Thanks in advance

  21. Hi andy,

    AutoCAD 2014 should read all the formats used in 2005. You can choose to open and save back to the newer DWG format, for instance, or just leave any DWGs as is. It's up to you.

    Regards,

    Kean

  22. Thanx Kean..!!!

    I have some arx files in my existing code alongwith exe files with same name and I noticed that in the lisp code these arx files are being loaded and arx files are in compiled form nt able to open so is there any way out to decompile them so that i can have understanding of it...:(

    regards,
    Andy

  23. Native executables (whether .EXE, .DLL or .ARX) are going to be next to impossible to decompile into anything meaningful (you would have much more luck with .NET DLLs in that sense).

    Is there no way of tracking down the source?

    Kean

  24. Hi Kean,
    I have got the source code of arx files they are coded in c/c++ .I am trying to understand it but the problem is I dunno where to start from confused abt how to approach this upgradation..If you can help me in this..it will be grt...:)

    Thanks
    andy....:)

  25. Hi andy,

    If you want to learn ObjectARX then I recommend attending training or going through the material on the AutoCAD Developer Center.

    If you want to get someone else to help then I suggest posting to the ObjectARX Discussion Forum (also linked from the DevCenter) or search for consultants that might help via the Partner Products & Services website.

    I, unfortunately, don't have time to help you through this, personally.

    Regards,

    Kean

  26. its ok kean..I understand that....thnx alot for ur valuable suggestions....
    🙂

    Andy...

  27. Hi mr. Walmsley,
    Please describe a little about how can we add a reference to Autodesk.Autocad.Interop.Common.dll (AXDBLib) to a C# winform application in x64 bit windows?

    I have added this dll as AutoCAD/ObjectDBX Common 17.0 Type Library from COM references in x32 but now i could not find it there in x64.

  28. Excuse me because of my previous question.
    I had not read your article carefully.

    I tried to find Autodesk.Autocad.Interop.Common.dll by browsing it in the AutoCAD Program Files but i could not.
    What do you think? What is my mistake?

    Excuse me again...

  29. Try installing the ObjectARX SDK for your version of AutoCAD (autodesk.com/objectarx) and using the DLLs provided in the relevant "inc" folder.

    Kean

  30. Hi Kean, sorry to pickup a so old thread...
    Do you know where I can get AcMgd.xml, AcCoreMgd.xml and AcCoreMgd.xml for AutoCAD2013's API?

    1. Hi Carlos,

      Sorry - I don't know that we make these available. You might try asking ADN.

      Kean

      1. These files are already available for public by AD Comunity, but only for 2006: forums.autodesk.com/
        I see no reason to make available for newer versions too

        1. Hopefully whoever provided them back then can do so now.

          Kean

  31. when you refer to
    Changing property and method names, as per the migration guideWhere can I find this migration guide?

    1. Kean Walmsley Avatar

      If you download the ObjectARX SDK (objectarx.com) you should find it in the docs folder. The file is called arxmgr.chm, if I recall correctly.

      Kean

  32. did anyone have a namespace problem with: "AeccAlignmentReturnValue"

    it changes from "Autodesk.AECC.Interop" to "Autodesk.AECC.Interop.Land"

    Anyone have also this issue?
    I made the changes but did not tried yet. I am migration a code that is not mine. :S

    best regards,
    John

    1. Hi John,

      Please post support questions to the appropriate online discussion group.

      Thanks,

      Kean

      1. Kean, iam sorry..
        this is a migrating issue. i did think that here was the right place.
        my mistake.

        Maybe a didn't formulate my question properly.

        best regards,
        John

  33. We have some AutoCAD .Net code for Brep reading and was giving correct result in AutoCAD 2015. But when we used the same code with AutoCAD 2016, its giving wrong result and our code goes in infinite loop. In the Whats new section of the SDK we did not find any clue. Is there any known issue with the Brep Geoemtry in AutoCAD 2015 & 2016 ?

    1. Not that I'm aware of. I suggest posting a sample that reproduces the problem to the ADN team or the AutoCAD .NET Discussion Group.

      Kean

      1. Hi Kean , looks we solved the issue. For us, it seems there is some changes in the LineContainment test in ObjectARX 2015 and 2016.

Leave a Reply to Jeff Mishler Cancel reply

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