- 积分
- 4358
- 明经币
- 个
- 注册时间
- 2015-1-16
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
本帖最后由 qq1254582201 于 2024-11-4 16:44 编辑
- [CommandMethod("ReplaceBlock2")]
- public void ReplaceBlock2()
- {
- Document doc = Application.DocumentManager.MdiActiveDocument;
- Database db = doc.Database;
- string blockName = "TEST";
- Database blkDb = new Database(false, true);
- blkDb.ReadDwgFile(@"C:\\Temp\\TEST.dwg", System.IO.FileShare.Read, true, "");
- using (Transaction Tx = db.TransactionManager.StartTransaction())
- {
- BlockTable blockTable = Tx.GetObject(db.BlockTableId, OpenMode.ForRead, false, true);
- ObjectId btrId = db.Insert(blockName, blkDb, true);
- if (btrId != ObjectId.Null)
- {
- BlockTableRecord btr = Tx.GetObject(btrId, OpenMode.ForRead, false, true);
- ObjectIdCollection brefIds = btr.GetBlockReferenceIds(false, true);
- foreach (ObjectId id in brefIds)
- {
- BlockReference bref = Tx.GetObject(id, OpenMode.ForWrite, false, true);
- bref.RecordGraphicsModified(true);
- }
- }
- Tx.Commit();
- }
- blkDb.Dispose();
- }
插入外部CAD作为块,并更新显示
- [CommandMethod("ReplaceBlock1")]
- public void ReplaceBlock1()
- {
- Document doc = Application.DocumentManager.MdiActiveDocument;
- Database db = doc.Database;
- string blockName = "TEST";
- using (Transaction Tx = db.TransactionManager.StartTransaction())
- {
- BlockTable blockTable = Tx.GetObject(db.BlockTableId, OpenMode.ForRead, false, true);
- if ((blockTable.Has(blockName)))
- {
- BlockTableRecord btr = Tx.GetObject(blockTable[blockName], OpenMode.ForWrite, false, true);
- // Erase all entities in btr
- foreach (ObjectId id in btr)
- {
- Entity ent = id.GetObject(OpenMode.ForWrite);
- ent.Erase();
- }
- // Add new entities to btr
- Line aLine = new Line(new Point3d(50, 50, 0), new Point3d(100, 100, 0));
- btr.AppendEntity(aLine);
- Tx.AddNewlyCreatedDBObject(aLine, true);
- ObjectIdCollection brefIds = btr.GetBlockReferenceIds(false, true);
- // Update blockrefs to display new graphics
- foreach (ObjectId id in brefIds)
- {
- BlockReference bref = Tx.GetObject(id, OpenMode.ForWrite, false, true);
- bref.RecordGraphicsModified(true);
- }
- Tx.Commit();
- }
- }
- }
修改块对象后更新既有块对象内的显示
|
|