Accessing the Civil Application and Document Objects in VBA

Accessing the Civil Application and Document Objects in VBA

stephen_mitchell
Contributor Contributor
1,824 Views
1 Reply
Message 1 of 2

Accessing the Civil Application and Document Objects in VBA

stephen_mitchell
Contributor
Contributor

I have been using the following function in Civil3D 2020 to access the Civil Application Object and it works fine. It does not seem to work in Civil3D 2021?

 

I get an error on the line "Set g_oDocument = g_oCivilApp.ActiveDocument".

 

I guess it is something to do with being an AcadDocument and not an AeccDocument??? Any ideas?

 

Public oAcadApp As AcadApplication
Public g_oCivilApp As AcadApplication
Public g_oDocument As AeccDocument
Public g_oDatabase As AeccDatabase


Function GetGlobalCivilObjects() As Boolean


Set oAcadApp = ThisDrawing.Application

If InStr(oAcadApp.Name, "Autodesk Civil 3D 2021") > 0 Then
Set g_oCivilApp = oAcadApp.GetInterfaceObject("AeccXUiLand.AeccApplication.13.3")
Else
MsgBox oAcadApp.Name & " is not supported by this program", vbCritical
GetGlobalCivilObjects = False
Exit Function
End If

If g_oCivilApp Is Nothing Then
GetGlobalCivilObjects = False
MsgBox "Error getting Civil3D Interface object", vbCritical, "GetGlobabCivilOjbects Error Message"
Exit Function
End If

Set g_oDocument = g_oCivilApp.ActiveDocument
Set g_oDatabase = g_oDocument.Database

GetGlobalCivilObjects = True

End Function

 

 

0 Likes
Accepted solutions (1)
1,825 Views
1 Reply
Reply (1)
Message 2 of 2

stephen_mitchell
Contributor
Contributor
Accepted solution

Hi I figured it out. It was a problem with the References to the Civil Object libraries.

 

I had loaded my 2020 vba project into Civil3D 2021. While the references appeared to be fine, I unticked them and then loaded again and it worked. I loaded the type libraries from the following directory on my pc and it worked fine:

 

C:\Program Files\Common Files\Autodesk Shared\Civil Engineering 133

 

Thanks