Author Topic: Tell whether blockreference is an xref  (Read 2448 times)

0 Members and 1 Guest are viewing this topic.

Bernd

  • Newt
  • Posts: 31
Tell whether blockreference is an xref
« on: June 08, 2018, 01:30:38 AM »
Is there a way to tell whether a BlockReference is an xref or a "normal" block?
Background is that I'm transforming all objects in a drawing except XRefs as they reference already transformed drawings.

Thanks, Bernd

huiz

  • Swamp Rat
  • Posts: 917
  • Certified Prof C3D
The conclusion is justified that the initialization of the development of critical subsystem optimizes the probability of success to the development of the technical behavior over a given period.

Bernd

  • Newt
  • Posts: 31
Re: Tell whether blockreference is an xref
« Reply #2 on: June 09, 2018, 07:12:14 AM »
Sounds good - I'll check it out next week.
Thanks for your help!

Bernd

  • Newt
  • Posts: 31
Re: Tell whether blockreference is an xref
« Reply #3 on: June 11, 2018, 07:52:03 AM »
Tried to get something together with the help of your links. But I'm not sure whether my code is fool proof, so I'd appreciate any comment on it...
Code - C#: [Select]
  1. using (var blockTable = (BlockTable)trans.GetObject(database.BlockTableId, OpenMode.ForRead))
  2. using (var modelSpace = (BlockTableRecord)trans.GetObject(blockTable[BlockTableRecord.ModelSpace], OpenMode.ForRead))
  3. {
  4.     /* Find all XRefs */
  5.     var objectIdsXrefs = new ObjectIdCollection();
  6.     foreach (ObjectId oid in blockTable)
  7.     {
  8.         var btr = trans.GetObject(oid, OpenMode.ForRead) as BlockTableRecord;
  9.         if (btr.IsFromExternalReference)
  10.             objectIdsXrefs.Add(oid);
  11.     }
  12.  
  13.     /* iterate over each graphical object */
  14.     foreach (ObjectId oid in modelSpace)
  15.     {
  16.         using (var dbObject = trans.GetObject(oid, OpenMode.ForRead))
  17.         {
  18.             if (dbObject is BlockReference)
  19.             {
  20.                 /* Is the assumption correct, that the blockreference's (xref's) DynamicBlockTableRecord
  21.                    is the same id as xref's BlockTableRecord id?
  22.                    In my case it is, but could that also be different? */
  23.                 if (objectIdsXrefs.Contains(((BlockReference)dbObject).DynamicBlockTableRecord))
  24.                     continue;
  25.             }
  26.             /* else transform the object ... */
  27.         }
  28.     }
  29. }
  30.  

Thank you  :|

Gasty

  • Newt
  • Posts: 90
Re: Tell whether blockreference is an xref
« Reply #4 on: June 16, 2018, 11:18:46 PM »
Hi,

From DXF reference:

Code 70

Block-type flags (bit coded values, may be combined):
1 = This is an anonymous block generated by hatching, associative dimensioning, other internal operations, or an application.
2 = This block has non-constant attribute definitions (this bit is not set if the block has any attribute definitions that are constant, or has no attribute definitions at all).
4 = This block is an external reference (xref).
8 = This block is an xref overlay.
16 = This block is externally dependent.
32 = This is a resolved external reference, or dependent of an external reference (ignored on input).
64 = This definition is a referenced external reference (ignored
on input).

Gaston Nunez