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

Leave a Reply to Rosario DiloCancel reply