private List <ObjectId> GetBlockReferences(ObjectId blockId) { List <ObjectId> result = null; using (Transaction tr = _wdb.TransactionManager.StartTransaction()) { BlockTableRecord btr = (BlockTableRecord)tr.GetObject(blockId, OpenMode.ForRead); BlockTable bt = (BlockTable)tr.GetObject(_wdb.BlockTableId, OpenMode.ForRead); ObjectId modelId = ((BlockTableRecord)tr .GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForRead)).ObjectId; result = btr.GetAllBlockReferenceIds(true) .Select(n => (BlockReference)tr.GetObject(n, OpenMode.ForRead)) .Where(n => n.OwnerId == modelId) .Select(n => n.ObjectId) .ToList(); tr.Commit(); } return(result); }
/// <summary> /// Gets all block reference ids. /// </summary> /// <param name="btr">The BTR.</param> /// <param name="directOnly">if set to <c>true</c> [direct only].</param> /// <param name="forceValidity">if set to <c>true</c> [force validity].</param> /// <returns></returns> public static ObjectIdCollection GetAllBlockReferenceIds(this BlockTableRecord btr, bool directOnly, bool forceValidity) { return(btr.GetAllBlockReferenceIds(btr.Database.TransactionManager.TopTransaction, directOnly, forceValidity)); }