Is a Civil 3D instance?

By Augusto Goncalves

This is a .NET version of the code posted by a colleague, see original here, redesigned to Civil 3D naming.

When we get a running instance of AutoCAD, we don’t know which vertical is actually running as all of them are basically the same root object. To determine which version we have, we need to try. And that’s what this code is doing.

' get the running instance of AutoCAD (or any vertical)Dim acadApp As Object = GetObject(, "Autocad.Application")' is it a Civil 3D? let's try!Dim civilLandApp As ObjectTry  ' the 10.4 stands for 2015 release  civilLandApp = acadApp.GetInterfaceObject                 ("AeccXUiLand.AeccApplication.10.4")Catch ex As Exception  Return ' not Civil 3DEnd Try ' now we know is Civil 3D' do something

And in C# it’s basically the same, except that you need to decide whenever to use var or dynamic. The above code uses Object, that enables late-binding. If that is your option, then use the C# equivalent: dynamic


Comments

4 responses to “Is a Civil 3D instance?”

  1. Anton Huizinga Avatar
    Anton Huizinga

    You also could check for a valid Civil3D command to be available:
    internal static bool IsCivil3D() {
    if (!(Autodesk.AutoCAD.Internal.Utils.IsCommandNameInUse(“AeccToolSpace”) == Autodesk.AutoCAD.Internal.CommandTypeFlags.NoneCmd)) {
    return true;
    } else {
    return false;
    }
    } // function

  2. Anton,
    That’s a nice idea, thanks for sharing.
    In fact your code will work in-process, but not for automation (e.g. driving AutoCAD or Civil 3D from an external application), unless you expose your idea through a COM Interface.
    My post was not clear on the scenario: COM Automation
    Thanks again!
    Cheers,
    Augusto Goncalves

  3. Rosario Dilo Avatar
    Rosario Dilo

    Hi, Augusto
    Hi, iam trying to create a macro in AutoCAD Civil 3D using vba that asks me to select a general segment label (Feature is LWPOLYLINE) and after selects he shown me the informations of
    Side (Eg L1)
    Start Easting
    Start Northing
    Segment Length
    Azimuth
    End Easting
    End Northing
    Waiting feedback
    Regards

  4. Rosario, I would suggest you to post as a question on http://forums.autodesk.com/t5/autocad-civil-3d-customization/bd-p/190
    Regards,
    Augusto Goncalves

Leave a Reply to Rosario DiloCancel reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading