AutoCAD Civil 3D Customization

Reply
New Member
AnthonyGraham7907
Posts: 2
Registered: ‎03-15-2009
Message 1 of 4 (284 Views)

Trouble with C3d 2012 COM

284 Views, 3 Replies
02-12-2012 05:02 PM

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

*Expert Elite*
Jeff_M
Posts: 4,194
Registered: ‎07-22-2003
Message 2 of 4 (278 Views)

Re: Trouble with C3d 2012 COM

02-12-2012 07:36 PM 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
New Member
AnthonyGraham7907
Posts: 2
Registered: ‎03-15-2009
Message 3 of 4 (275 Views)

Re: Trouble with C3d 2012 COM

02-12-2012 08:55 PM 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

Employee
peterfunkautodesk
Posts: 708
Registered: ‎08-25-2009
Message 4 of 4 (257 Views)

Re: Trouble with C3d 2012 COM

02-14-2012 08:37 PM in reply to: AnthonyGraham7907

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.

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community


Civil 3D Exchange Apps

Created by the community for the community, Autodesk Exchange Apps for AutoCAD Civil 3D helps you achieve greater speed, accuracy, and automation from concept to manufacturing.

Connect with Civil 3D

Twitter

Facebook

Blogs