Author Topic: Digging Into XREFs  (Read 3490 times)

0 Members and 1 Guest are viewing this topic.

sinc

  • Guest
Digging Into XREFs
« on: November 06, 2008, 08:48:37 PM »
I tried posting this at "the other place", but it doesn't seem to be going anywhere.  Maybe someone around here knows the "trick".

I'm trying to get to the Aecc database for Civil-3D - basically, the database for the vertical application.  Peter Funk says to do it like this:

Code: [Select]
            Dim blk As AcadExternalReference
             Set blk = obj
            Dim oapp As AcadApplication
             Set oapp = blk.Application
             Dim oCivilApp As AeccApplication
             Dim oAeccDoc As AeccDocument
            Dim oAeccDb As AeccDatabase
            Const sAppName = "AeccXUiLand.AeccApplication.6.0"
   
            Set oCivilApp = oapp.GetInterfaceObject(sAppName)
             Set oAeccDoc = oCivilApp.ActiveDocument
            Set oAeccDb = oAeccDoc.Database

Of course, I'm not doing VBA.

So I try this:

Code: [Select]
BlockReference br; // my XREF
AcadExternalReference extRef = br.AcadObject as AcadExternalReference;
AcadApplication oApp = (AcadApplication)extRef.Application;

...but that last line crashes on me, with an error HRESULT E_FAIL has been returned by COM object.

Am I mis-interpreting Peter's response?  Casting br.AcadObject to an AcadExternalReference seems to work - it returns a com object.  But then it fails on the next line, when I try to get to the Application.

Anyone have any idea what's going on here?

Glenn R

  • Guest
Re: Digging Into XREFs
« Reply #1 on: November 07, 2008, 05:19:56 AM »
Something like this maybe?

Code: [Select]
using Autodesk.AutoCAD.Interop;
using acadApp = Autodesk.AutoCAD.ApplicationServices.Application;
...
AcadApplication comAcadApp = acadApp.AcadApplication as AcadApplication;
AeccApplication comAeccApp = comAcadApp.GetInterfaceObject("AeccXUiLand.AeccApplication.6.0") as AeccApplication;

sinc

  • Guest
Re: Digging Into XREFs
« Reply #2 on: November 07, 2008, 08:16:07 AM »
No, I need to get the application for the XREF, so I can dig into the XREF database.  At least, if I understand Peter's reply correctly.

That code merely returns the application object I already have.

Glenn R

  • Guest
Re: Digging Into XREFs
« Reply #3 on: November 07, 2008, 08:18:24 AM »
There is only one 'application'...

Glenn R

  • Guest
Re: Digging Into XREFs
« Reply #4 on: November 07, 2008, 08:25:01 AM »
This?

Code: [Select]
AcadApplication comAcadApp = acadApp.AcadApplication as AcadApplication;
           
BlockReference blkRef = null;
// get block reference somehow
...
AcadExternalReference comXref = blkRef.AcadObject as AcadExternalReference;

AcadDatabase xrefDb = comXref.Database;

sinc

  • Guest
Re: Digging Into XREFs
« Reply #5 on: November 07, 2008, 09:27:50 AM »
No, that gets the AcadDatabase.  I need the AeccDatabase.

TonyT

  • Guest
Re: Digging Into XREFs
« Reply #6 on: November 07, 2008, 09:42:10 AM »
No, I need to get the application for the XREF, so I can dig into the XREF database.  At least, if I understand Peter's reply correctly.

That code merely returns the application object I already have.

I don't think Peter understood what you were trying to do.

Try creating a new AeccDatabase, call it's Init() method
and pass it the value of the XRefDatabase property of the
IAcadBlock that represents the xref.

That assumes that the API supports databases that are
not open in the editor (don't know).

sinc

  • Guest
Re: Digging Into XREFs
« Reply #7 on: November 07, 2008, 10:21:08 AM »
I can't seem to create a new AeccDatabase - no constructors available.  Unless there's a backdoor method, using the AeccDatabaseClass object?

Maybe I need to locate the DWG file that contains the XREF, then open that file in the Editor and work with it that way?

Glenn R

  • Guest
Re: Digging Into XREFs
« Reply #8 on: November 07, 2008, 11:03:49 AM »
Is the Init() method Tony mentioned, static?

Like so perhaps:
Code: [Select]
AeccDatabase.Init(blahblah);

sinc

  • Guest
Re: Digging Into XREFs
« Reply #9 on: November 07, 2008, 11:08:47 AM »
No, it is not static.

And it does not seem to have an effect on a database that is already initialized, so I can't create a new AeccApplication, get the AeccDatabase from it, and then run Init() on that new database to "redirect" it toward my XREF.  That doesn't work, either.

TonyT

  • Guest
Re: Digging Into XREFs
« Reply #10 on: November 07, 2008, 12:53:04 PM »
I can't seem to create a new AeccDatabase - no constructors available.  Unless there's a backdoor method, using the AeccDatabaseClass object?

Maybe I need to locate the DWG file that contains the XREF, then open that file in the Editor and work with it that way?

Right, I wasn't sure about it because I didn't have the type library
right in front of me, but if there's no constructor available then
we can assume the only way to get one is via the Database property
of an AeccDocument.