Author Topic: GetInterfaceObject  (Read 5793 times)

0 Members and 1 Guest are viewing this topic.

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
GetInterfaceObject
« on: August 25, 2007, 01:11:16 PM »
I just posted to the Autodesk Civil3D newsgroup a problem with Civil3D and GetinterfaceObject. While reading some of today's posts here, it dawned on me that this may not be a C3D specific issue. If anyone has any other Vertical app and could convert this code for use in that, I'd like to know the results.

Here's a copy of my post, the C# project to test is attached.
Quote from: Me
C# Code to access Civil3D objects.
Start any other ACAD 2007 or 2008 application, open a drawing.
Start Civil3D 2008, open a drawing
Load the included.NET Application in C3D
Invoke the Command "Testme"

The command line will display the current Drawing name, obtained from the
AcadApplication, and the current Aecc drawing name, obtained from the
AeccApplication.

Note that the second drawing listed will be the name of the drawing opened
in the first Acad session and NOT the sessio
n from which the command was
invoked. This makes working with any of the C3D objects impossible until any
prior sessions have been closed.

Any suggestions on how to address this?
<Edited the mis-spelled Subject line - jm>
« Last Edit: August 28, 2007, 04:50:34 PM by Jeff_M »

LE

  • Guest
Re: GetnterfaceObject
« Reply #1 on: August 25, 2007, 02:04:28 PM »
Jeff;

I do not have any vertical app installed.


Have you tried or used before the CommandFlags on your commands?

[CommandMethod("MYEXPLODE", CommandFlags.yourenumhere)]


Maybe.... if not, don't tell anyone I recommend it.... :)

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: GetnterfaceObject
« Reply #2 on: August 25, 2007, 02:40:54 PM »
Maybe.... if not, don't tell anyone I recommend it.... :)
Thanks for the suggestion, Luis. No, I hadn't tried the CommandFlags, and to be honest after reading up on them I can see how I should be using some of these, but none that may help with the issue I'm having with the InterfaceObject.

Oh, and I won't tell anyone you were here :-)

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: GetInterfaceObject
« Reply #3 on: August 28, 2007, 04:52:12 PM »
OK, so this isn't a .NET issue. I tested the same scenario using VBA and got the exact same result.
Code: [Select]
Option Explicit

Sub testme()
Dim acadApp As AcadApplication
Dim aeccApp As AeccApplication

Set acadApp = ThisDrawing.Application
Set aeccApp = acadApp.GetInterfaceObject("AeccXUiLand.AeccApplication.5.0")

Debug.Print "AcadDWG = " & acadApp.ActiveDocument.Name
Debug.Print "AeccDWG = " & aeccApp.ActiveDocument.Name

End Sub

Bryco

  • Water Moccasin
  • Posts: 1883
Re: GetInterfaceObject
« Reply #4 on: August 28, 2007, 05:16:43 PM »
Does acadver hold a way to differentiate the apps?

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: GetInterfaceObject
« Reply #5 on: August 28, 2007, 06:24:51 PM »

Thanks Jeff .. that's a bit of a trap for players ..
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

sinc

  • Guest
Re: GetInterfaceObject
« Reply #6 on: August 28, 2007, 06:28:02 PM »
Judging from the huge number of issues that have revolved around the entire vertical-app structure for years now, I'm guessing that this is another of Autodesk's internal problems.  Even after all these years, I still don't think they understand what they're trying to do.  (Witness the Autodesk Sabotage - er, I mean the Autodesk Shared - directory...)

Personally, I've never liked the vertical-app structure at all, and wish they had not done things that way.  But like so many other things in Autocad, it probably seemed like a good idea at the time...   :?

I, too, am at a loss.  I've tried late-binding, normal binding, using COM objects, and everything else I can think of, and can find no way around the issue.  I'm guessing it's something we just need to wait for Autodesk to fix, if they ever do.

Other than that, the only real solution I see is to just not start up multiple Autodesk products at the same time...   :wink:

Also, the way I do things in the SincpacC3D, the reference to the application is "remembered" by the framework.  So, if you start up Civil-3D first, the SincpacC3D will continue to work even if you later open an instance of Land Desktop.  It's only if Land Desktop is already up and running when you first initialize the SincpacC3D that it can't find the correct application instance.

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: GetInterfaceObject
« Reply #7 on: August 28, 2007, 06:37:15 PM »
Does acadver hold a way to differentiate the apps?
Thanks for the idea, but I don't think so. If I have 2 C3D sessions open (not likely on this machine due to the amount RAM each would require) then they would both return the same but the first one would still be the one grabbed by the InterfaceObject.

I was finally able to install Architecture2008 today. I just tested the exact same thing in VBA and I get  the results I would expect to get...i.e. both application objects return the DWG name of the Active session. So it appears to be an issue inside the C3D ActiveX component.

Sinc, so long as the C3D session that SincPacC3D is called from is the first Acad application in the running processes it works fine. This includes calling it in the second or third in-line, finding that things don't work, and closing the sessions opened prior to the one you are in.

This also explains why all of my searches have come up empty for others having similar issues. There still aren't very many of us coding for C3D to expose these issues.

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: GetInterfaceObject
« Reply #8 on: August 28, 2007, 06:44:47 PM »
Other than that, the only real solution I see is to just not start up multiple Autodesk products at the same time...
I'm thinking, too, that a check must be run to ensure the 2 drawing names match and, if not, inform the user that the commands will not return valid results.

sinc

  • Guest
Re: GetInterfaceObject
« Reply #9 on: August 28, 2007, 06:49:18 PM »
That's a good idea.

This problem has gotten me recently - at first I thought that SP1 had broken things, then I finally realized I had an instance of Land Desktop running that I had forgotten about.  So if this issue can still throw ME for a loop, and I know all about it, I hate to think what it can do to the "average user"...   :-o

erlking

  • Guest
Re: GetInterfaceObject
« Reply #10 on: October 01, 2007, 04:30:42 AM »
'try this funciton,Jeff :
'Thanks to SincpacC3D
'
Public Shared Function RunCvl(ByRef AcadApp As AcadCOM.AcadApplication, ByRef AeccApp As AeccUiLandLib.IAeccApplication, ByRef AeccDoc As AeccUiLandLib.IAeccDocument, ByRef AeccDb As AeccLandLib.IAeccDatabase) As Boolean

        Try

            Try
                AcadApp = Application.AcadApplication
            Catch ex As Exception
                Dim AcadProg As System.Type = System.Type.GetTypeFromProgID("AutoCAD.Application")
                AcadApp = System.Activator.CreateInstance(AcadProg, True)
            End Try

            If AcadApp IsNot Nothing Then
                AcadApp.Visible = True
                AeccApp = New AECC.Interop.UiLand.AeccApplicationClass()
                AeccApp.Init(AcadApp)
            End If
        Catch
            MsgBox("Failed To Run C3d!")
            Return False
        End Try
        '================
        Try
            AeccDoc = AeccApp.ActiveDocument
            AeccDb = AeccApp.ActiveDocument.Database
        Catch
            MsgBox("Civil 3D NO Doc!")
            Return False
        End Try

        Return True
    End Function
'My English is so bad!:)

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: GetInterfaceObject
« Reply #11 on: October 01, 2007, 02:29:11 PM »
Thanks erlking! However, what I was working with (and subsequently found the answer for) WAS SincPacC3d before Sinc updated it to use the method you posted :-)