Author Topic: Xref dialog not updating when attaching an xref  (Read 2769 times)

0 Members and 1 Guest are viewing this topic.

Chumplybum

  • Newt
  • Posts: 94
Xref dialog not updating when attaching an xref
« on: April 02, 2007, 08:41:25 PM »
hey,

I have created a routine that attaches a dwg to the current working database or a database which has not been opened.
The problem i'm having is, when i attach a dwg to the current working database, the file attaches fine (and shows up in the ClasssicXref command) but the xref palette does not update.  This is not the case when i attach a drawing to an un opened drawing and open it manually. The xref displays fine in the palette.

I'm guessing there is some type of event or flag that fires when you open a drawing to populate the xrefgraph.
Does anyone know what this is or how to make the newly attached xref show up in the xref palette???

Thanks in advance

cheers

Ben

Glenn R

  • Water Moccasin
  • Posts: 1932
  • What idiot child of married cousins wrote this?!
Re: Xref dialog not updating when attaching an xref
« Reply #1 on: April 02, 2007, 08:47:25 PM »
Database.ResolveXrefs(false, true); perhaps...?
Me

Chumplybum

  • Newt
  • Posts: 94
Re: Xref dialog not updating when attaching an xref
« Reply #2 on: April 03, 2007, 06:46:42 PM »
thanks glen, already tried that but it doesn't seem to work... i think i need to raise an event (i think its the XrefAttachEnded event), but from what i can tell, i can't raise events that are declared in another class, i'm pretty new to events (and delegates) so i don't fully understand how to get them to work.

and after looking a bit deeper into the acadmgd.dll i found a few subs and functions that should do the trick,
Autodesk.autocad.databaseservices.CmgdDatabaseEventImpl.FireXrefAttachEnded...
Or
DatabaseServices.Database.XrefAttachEnded (Event)

but they're all friend classes and hence, i can't get access to them either.


thanks again, looks like i'll be doing plenty of reading on events :-/

mohnston

  • Bull Frog
  • Posts: 305
  • CAD Programmer
Re: Xref dialog not updating when attaching an xref
« Reply #3 on: May 01, 2007, 11:27:16 PM »
thanks glen, already tried that but it doesn't seem to work... i think i need to raise an event (i think its the XrefAttachEnded event), but from what i can tell, i can't raise events that are declared in another class, i'm pretty new to events (and delegates) so i don't fully understand how to get them to work.

and after looking a bit deeper into the acadmgd.dll i found a few subs and functions that should do the trick,
Autodesk.autocad.databaseservices.CmgdDatabaseEventImpl.FireXrefAttachEnded...
Or
DatabaseServices.Database.XrefAttachEnded (Event)

but they're all friend classes and hence, i can't get access to them either.


thanks again, looks like i'll be doing plenty of reading on events :-/


I have the exact same problem. Have you made any progress?
I found this in the arx docs.
Quote
External references (xrefs) can be created and manipulated through several global functions. These global functions mimic the AutoCAD XREF command capabilities. The functions provided are

acedXrefAttach()
acedXrefOverlay()
acedXrefUnload()
acedXrefDetach()
acedXrefResolve()
acedXrefBind()
acedXrefXBind()
acedXrefCreateBlockname()
acedXrefReload()
For information on the AutoCAD XREF command, see the AutoCAD User's Guide.

The main programming consideration concerning xrefs is that, for every xref that is attached to a drawing, a separate database is created to represent the drawing containing the xref. A block table record in the main drawing contains the name of the external drawing and points to the entities of the model space of the externally referenced drawing. The xref database also contains other block table records and symbol table entries required to resolve all references from the main block table record (layers, linetypes, and so on).

The global functions in c++ may work (I have no way of knowing) but the closest thing in managed code I could find is the XrefOperation enum which is part of DatabaseServices.


It's amazing what you can do when you don't know what you can't do.
CAD Programming Solutions

mohnston

  • Bull Frog
  • Posts: 305
  • CAD Programmer
Re: Xref dialog not updating when attaching an xref
« Reply #4 on: May 02, 2007, 12:23:40 PM »
Database.ResolveXrefs(false, true); perhaps...?
Thanks for the suggestion. Tried it. Still not in xref palette.
Interesting, it works just fine. Behaves like an xref should.
When I examine xrefs using the -xref command it is listed as an attach type xref.
Could it be that it's just the palette that doesn't recognize it?

Another thing that bothers me is that AttachXref method returns an ObjectID but I don't see where any entity gets added to the blocktablerecord.
On the other hand when you insert an instance of the xref (as a blockreference) that entity is added to the blocktablerecord.
Xrefs have a definition like blockrefs do.
It is the xref definition that isn't showing up in the palette. Maybe I need to save or record the definition in some other way.

Code: [Select]
Autodesk.AutoCAD.ApplicationServices.Document doc = acadApp.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
ObjectId oid = ObjectId.Null;
ObjectId bid = ObjectId.Null;
using (Transaction trans = db.TransactionManager.StartTransaction())
{
    using (DocumentLock dlock = doc.LockDocument())
    {
        try
        {
           oid = db.AttachXref(finFile, "Finishes");
           BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForWrite);
           //BlockTableRecord xbt = (BlockTableRecord)trans.GetObject(oid, OpenMode.ForRead);
           //Database xdb = xbt.GetXrefDatabase(true);
           BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
           BlockReference bref = new BlockReference(new Autodesk.AutoCAD.Geometry.Point3d(1046, 0, 0), oid);
           bid = btr.AppendEntity(bref);
           trans.AddNewlyCreatedDBObject(bref, true);
           trans.Commit();
           db.ResolveXrefs(false, true);
        }
        catch { }
     }
}
It's amazing what you can do when you don't know what you can't do.
CAD Programming Solutions

mohnston

  • Bull Frog
  • Posts: 305
  • CAD Programmer
Re: Xref dialog not updating when attaching an xref
« Reply #5 on: May 02, 2007, 01:48:51 PM »
I have decided that this is a bug.
The Xref definition IS added to the blocktable as a blocktablerecord.
You can find it programmatically or using "-xref" at the command line.
In fact, if you save and close the drawing then reopen it the definition DOES show up in the xref palette.
That means that something internally is not hooked up right.
Even if you click the "Refresh" button on the palette the newly added xref will not show up until the next time the drawing is opened.
I declare this a bug! A bug I tells ya!
It's amazing what you can do when you don't know what you can't do.
CAD Programming Solutions

deegeecees

  • Guest
Re: Xref dialog not updating when attaching an xref
« Reply #6 on: May 02, 2007, 02:06:32 PM »
<squish>

Bennos

  • Mosquito
  • Posts: 8
Re: Xref dialog not updating when attaching an xref
« Reply #7 on: May 02, 2007, 07:08:34 PM »
I also think this is a bug, i have tried xrefing in AutoCAD 2008 and it works fine.
Meaning that the palette is updated when you attach an xref.