Author Topic: BlockTableRecord.IsFromExternalReference always false?  (Read 2484 times)

0 Members and 1 Guest are viewing this topic.

sinc

  • Guest
BlockTableRecord.IsFromExternalReference always false?
« on: December 26, 2008, 01:47:44 AM »
For some reason, every call to IsFromExternalReference is returning false, even when the BlockTableRecord is an XREF.

Has anyone ever seen this?  I'm sure this used to work, but it's not working for me now...

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: BlockTableRecord.IsFromExternalReference always false?
« Reply #1 on: December 26, 2008, 03:53:54 AM »
This works for me Sinc ...
Quote
Command: _XATTACH
Overlay Xref "SECT-HEAD-1R": F:\_kdub_testing\Dwgs\SECT-HEAD-1R.dwg
"SECT-HEAD-1R" loaded.

Command: _XATTACH
Overlay Xref "Alphabet Soup": F:\_kdub_testing\nest-0\Alphabet Soup.dwg
"Alphabet Soup" loaded.

Command: ListXrefs

Found XREF : SECT-HEAD-1R
Found XREF : Alphabet Soup

Code: [Select]
[CommandMethod("ListXrefs")]
public static void ListXrefs()
{
    Database db = HostApplicationServices.WorkingDatabase;
    Document doc = AcadApp.DocumentManager.MdiActiveDocument;
    Editor ed = doc.Editor;

    using (Transaction tr = db.TransactionManager.StartTransaction())
    {
        BlockTable bt = tr.GetObject(
            db.BlockTableId, OpenMode.ForRead) as BlockTable;

        BlockTableRecord btr = tr.GetObject(
            bt[BlockTableRecord.ModelSpace], OpenMode.ForRead) as BlockTableRecord;

        foreach (ObjectId objId in btr)
        {
            DBObject dbObj = tr.GetObject(
                objId, OpenMode.ForRead);

            BlockReference blkRef = dbObj as BlockReference;
            if (blkRef != null)
            {
                BlockTableRecord blkTblRecord = tr.GetObject(
                    blkRef.BlockTableRecord, OpenMode.ForRead) as BlockTableRecord;
                if (blkTblRecord.IsFromExternalReference == true)
                {
                    ed.WriteMessage("\nFound XREF : " + blkTblRecord.Name);
                }
            }
        }               
        tr.Commit();
    }
}

« Last Edit: December 26, 2008, 03:59:00 AM by Kerry Brown »
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: BlockTableRecord.IsFromExternalReference always false?
« Reply #2 on: December 26, 2008, 11:37:11 AM »
Thanks, Kerry.

I was being brain-dead.  Well, I when I was working on this last night, it was around midnight, after two days of Christmas celebrations.  Probably not the best time to be coding.  :)

I had my BlockReference (br), and I was trying to do this:

Code: [Select]
BlockTableRecord btr = tr.GetObject(br.OwnerId, OpenMode.ForRead, false) as BlockTableRecord;
instead of this:

Code: [Select]
BlockTableRecord btr = tr.GetObject(br.BlockTableRecord, OpenMode.ForRead, false) as BlockTableRecord;
After I fixed that, everything is happy again.

I knew I had been using this and everything was OK, so I couldn't figure out what was going wrong.  But I was in one of those modes where I was looking all around the problem without seeing it.  Got it now, though.  Thanks!

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: BlockTableRecord.IsFromExternalReference always false?
« Reply #3 on: December 26, 2008, 08:27:25 PM »
....................   But I was in one of those modes where I was looking all around the problem without seeing it.  .............

I can't imagine anyone who couldn't honestly say the same ..
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.