Community
Civil 3D Customization
Welcome to Autodesk’s AutoCAD Civil 3D Forums. Share your knowledge, ask questions, and explore popular AutoCAD Civil 3D Customization topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Trouble with C3d 2012 COM

3 REPLIES 3
Reply
Message 1 of 4
AnthonyGraham7907
483 Views, 3 Replies

Trouble with C3d 2012 COM

Hello All,

 

I am having trouble getting the COM application objects, after trying a number of different methods that I managed to find in the (scant) literature and elsewhere.  I am using VB2010, w7 64 bit and C3D 64 bit. 

 

The code in question reads...

 

Imports Autodesk.AutoCAD.EditorInput

Imports Autodesk.AutoCAD.ApplicationServices

Imports Autodesk.AutoCAD.DatabaseServices

Imports Autodesk.AutoCAD.Interop

Imports Autodesk.AECC.Interop.UiLand

Imports Autodesk.Civil.ApplicationServices


Module Civil3DObjects

   

FriendConst ACAD_VERSION AsString = "AutoCAD.Application"

FriendConst CIVIL3D_VERSION AsString = "AeccXUiLand.AeccApplication.9.0"

   

'net

Friend netDOC AsCivilDocument

Friend netEDITOR AsEditor

   

'com

Friend comAcadApp As Autodesk.AutoCAD.Interop.IAcadApplication

Friend comAeccApp As Autodesk.AECC.Interop.UiLand.IAeccApplication

Friend comAeccDoc AsIAeccDocument

Friend comAeccDB As Autodesk.AECC.Interop.Land.IAeccDatabase

FriendFunction GetCOMobjects() AsBoolean

       

'returns true if successfull

        GetCOMobjects = False

 

       

'comAcadApp = TryCast(Application.AcadApplication, AcadApplication)

       

'comAeccApp = TryCast(comAcadApp.GetInterfaceObject(CIVIL3D_VERSION), AeccApplication)

       

'If comAeccApp Is Nothing Then

       

'    Throw New COMInstanceException("Unable to retrieve interface for Civil Application.", CIVIL3D_VERSION)

       

'End If

 

       

Try

           

If IsNothing(comAcadApp) Then 

            comAcadApp = Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication

EndIf

       

Catch ex As System.Exception

            MsgBox("Cannot load AutoCAD Application")

Return False

       

EndTry

       

IfNot comAcadApp IsNothing Then

           

Try

                comAeccApp = comAcadApp.GetInterfaceObject(CIVIL3D_VERSION)

                comAeccDoc = comAeccApp.ActiveDocument

                comAeccDB = comAeccApp.ActiveDocument.Database

Catch ex As System.Exception

                MsgBox("Cannot load Civil3D Application")

Return False

           

EndTry

       

EndIf

       

Return True

   

EndFunction

 

 

 

 

 

Everything goes pear shaped at...

 

          comAeccApp = comAcadApp.GetInterfaceObject(CIVIL3D_VERSION)

 

         where CIVIL3D_VERSION = "AeccXUiLand.AeccApplication.9.0"

 

The project references are  shown in the attached image.

 

 

This has stumped me for a couple of days now and I am sure that I will feel like a goose for missing something simple.  Please help.

 

Regards,

 

Anthony

3 REPLIES 3
Message 2 of 4
Jeff_M
in reply to: AnthonyGraham7907

Using the GetInterfaceObject() method has the potential to try to use the wrong running instance of AutoCAD if there is more than one running. This was the case in older products, not sure about 2012 because we use the following code which always works for the running instance it is called in. (Which means I'm not sure why your code fails, it looks like it should be fine, just this method takes the place of the GetInterfaceObject())

 

comAeccApp = New IAeccApplicationClass()
comAeccApp.Init(comAcadApp)

 From there you can set the document and database objects.

Jeff_M, also a frequent Swamper
EESignature
Message 3 of 4
AnthonyGraham7907
in reply to: Jeff_M

Thanks Jeff,

 

I inserted the following code as a replacement for the GetInterfaceObject...

 

               Dim comAeccApp As New Autodesk.AECC.Interop.UiLand.AeccApplication

                comAeccApp = New AeccApplication

                comAeccApp.Init(comAcadApp)

 

 

and got an error message saying that FDO.dll could not be found.  I found FDO.dll and updated the device path in C3D to look in the correct location (had to swap "...\FDO\BIN\" for "...\BIN\FDO") and the code ran through as it was meant.

 

Thanks again Jeff, you are a lifesaver.

 

Anthony

Message 4 of 4

Anthony,

 

Unless you're using something that isn't exposed to .NET I would switch to VB.NET instead. The .NET API is 5-10 times faster than the COM API, and all new API work is being done on the .NET side.

 

Cheers,

 

Peter Funk

Autodesk, Inc.



Peter Funk
Autodesk, Inc.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


Autodesk Design & Make Report