// Erase the anonymous blocks referenced by an object private static void EraseReferencedAnonBlocks( Transaction tr, DBObject obj ) { var refFiler = new ReferenceFiler(); obj.DwgOut(refFiler); // Loop through the references and erase any // anonymous block definitions // foreach (ObjectId refid in refFiler.HardPointerIds) { BlockTableRecord btr = tr.GetObject(refid, OpenMode.ForRead) as BlockTableRecord; if (btr != null && btr.IsAnonymous) { btr.UpgradeOpen(); btr.Erase(); } } }
// Remove the stroke objects that have references from this // particular complex linetype or stroke object from the list // passed in private static void PurgeStrokesReferencedByObject( Transaction tr, ObjectIdCollection nodIds, ObjectId id ) { var obj = tr.GetObject(id, OpenMode.ForRead); if (obj.ExtensionDictionary != ObjectId.Null) { // Get the extension dictionary var exd = (DBDictionary)tr.GetObject( obj.ExtensionDictionary, OpenMode.ForRead ); // And the "DGN Linestyle Definition" object if (exd.Contains(dgnLsDefName)) { var lsdef = tr.GetObject( exd.GetAt(dgnLsDefName), OpenMode.ForRead ); // Use a DWG filer to extract the references var refFiler = new ReferenceFiler(); lsdef.DwgOut(refFiler); // Loop through the references and remove any from the // list passed in foreach (ObjectId refid in refFiler.HardPointerIds) { if (nodIds.Contains(refid)) { nodIds.Remove(refid); } // We need to recurse, as linetype strokes can reference // other linetype strokes PurgeStrokesReferencedByObject(tr, nodIds, refid); } } } else if ( obj.GetRXClass().Name.Equals("AcDbLSCompoundComponent") || obj.GetRXClass().Name.Equals("AcDbLSPointComponent") ) { // We also need to consider compound components, which // don't use objects in their extension dictionaries to // manage references to strokes... // Use a DWG filer to extract the references from the // object itself var refFiler = new ReferenceFiler(); obj.DwgOut(refFiler); // Loop through the references and remove any from the // list passed in foreach (ObjectId refid in refFiler.HardPointerIds) { if (nodIds.Contains(refid)) { nodIds.Remove(refid); } // We need to recurse, as linetype strokes can reference // other linetype strokes PurgeStrokesReferencedByObject(tr, nodIds, refid); } } }