public static BlockDrawingObject Create(Database target, string blockName) { Transaction trans = target.TransactionManager.TopTransaction; BlockTable bt = (BlockTable)trans.GetObject(target.BlockTableId, OpenMode.ForRead); SymbolUtilityServices.ValidateSymbolName(blockName, false); if (bt.Has(blockName)) { throw new InvalidOperationException("Block name exists"); } BlockTableRecord btr = new BlockTableRecord(); btr.Name = blockName; bt.UpgradeOpen(); ObjectId btrId = bt.Add(btr); trans.AddNewlyCreatedDBObject(btr, true); BlockDrawingObject blockDrawingObject = new BlockDrawingObject(target); blockDrawingObject.BaseObject = btrId; return(blockDrawingObject); }
// TODO: Add test public BlockDrawingObject GetBlock() { BlockDrawingObject blockDrawingObject = new BlockDrawingObject(); blockDrawingObject.BaseObject = _database.GetBlockDefinition(BlockName).ObjectId; return(blockDrawingObject); }
public BlockDrawingObject TransferToDocument(Document targetDocument) { Transaction sourceTrans = this._database.TransactionManager.TopTransaction; Transaction destinatiopnTrans = targetDocument.Database.TransactionManager.TopTransaction; BlockTableRecord sourceBlockTableRecord = sourceTrans.GetObject(this.BaseObject, OpenMode.ForRead) as BlockTableRecord; ObjectIdCollection sourceObjects = new ObjectIdCollection(); /*foreach (ObjectId objectId in sourceBlockTableRecord) * { * sourceObjects.Add(objectId); * }*/ sourceObjects.Add(sourceBlockTableRecord.ObjectId); IdMapping mapping = new IdMapping(); // TODO: Confirm ignore is correct option _database.WblockCloneObjects(sourceObjects, targetDocument.Database.BlockTableId, mapping, DuplicateRecordCloning.Ignore, false); BlockDrawingObject blockDrawingObject = new BlockDrawingObject(targetDocument); blockDrawingObject.BaseObject = mapping.Lookup(sourceBlockTableRecord.ObjectId).Value; return(blockDrawingObject); }
public static BlockRefDrawingObject Create(Database target, Point3d insertionPoint, BlockDrawingObject sourceBlock) { ObjectId newRefId; Transaction trans = target.TransactionManager.TopTransaction; BlockReference acadReference = new BlockReference(insertionPoint, sourceBlock.BaseObject); newRefId = target.GetModelSpace(true).AppendEntity(acadReference); trans.AddNewlyCreatedDBObject(acadReference, true); // TODO: Figure out why the belwo throws an exception when the modified handler is active // Exception is thrown when the object is attempted to be opened, during the modified event handler BlockRefDrawingObject newRef = new BlockRefDrawingObject(); newRef.BaseObject = newRefId; return(newRef); }