- 积分
- 119
- 明经币
- 个
- 注册时间
- 2012-9-11
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
代码如下,CheckInference函数目的是利用3DSolid.CheckInterference()计算出List<Solid3d>中任意两个相交的部分.
但是一运行到copySolid1.BooleanOperation(BooleanOperationType.BoolIntersect, copySolid2)这句话时就出现" eWasOpenForWrite"的异常.哪位高人能解释一下应该如何处理,谢谢.
-
- private static void CheckInference(List<Solid3d> solids) {
- Database db = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database;
- using (Transaction tran = db.TransactionManager.StartTransaction()) {
- BlockTable blockTable = tran.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
- BlockTableRecord blockRecord = tran.GetObject(blockTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
- for (int i = 0; i < solids.Count - 1; i++) {
- Solid3d solid1 = solids;
- for (int j = i + 1; j < solids.Count; j++) {
- Solid3d solid2 = solids[j];
- if (solid1.Layer != solid2.Layer) {
- if (solid1.CheckInterference(solid2)) {
- Solid3d copySolid1 = solid1.Clone() as Solid3d, copySolid2 = solid2.Clone() as Solid3d;
- copySolid1.BooleanOperation(BooleanOperationType.BoolIntersect, copySolid2);
- copySolid1.ColorIndex = 1;
- blockRecord.AppendEntity(solid1);
- tran.AddNewlyCreatedDBObject(solid1, true);
- tran.Commit();
- }
- }
- }
- }
- }
- }
|
|