- [CommandMethod("testregion")]
- public void RegionSubstr()
- {
- var doc = Application.DocumentManager.MdiActiveDocument;
- var db = doc.Database;
- var ed = doc.Editor;
- var ent1 = ed.GetEntity("\nSelect Curve");
- var ent2 = ed.GetEntity("\nSelect Curve");
- using (var tr = db.TransactionManager.StartTransaction())
- {
- var btr = (BlockTableRecord) tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
- var id1 = ent1.ObjectId;
- var id2 = ent2.ObjectId;
- var entity = tr.GetObject(id1, OpenMode.ForWrite) as Entity;
- var entity2 = tr.GetObject(id2, OpenMode.ForWrite) as Entity;
- var curveSegments = new DBObjectCollection {entity,entity2};
- var regions = Region.CreateFromCurves(curveSegments);
- var region = regions[0] as Region;
- var region1 = regions[1] as Region ;
- if (region != null)
- {
- region.BooleanOperation(BooleanOperationType.BoolSubtract, region1);
-
- var brep = new Brep(region);
- var elp = brep.Edges;
- foreach (var cv in elp.Select(edge => edge.GetCurveAsNurb()).Select(c3d => Curve.CreateFromGeCurve(c3d)))
- {
- cv.ColorIndex = 1;
- //cv.Layer = "冲突图斑";
- btr.AppendEntity(cv);
- tr.AddNewlyCreatedDBObject(cv, true);
- }
- }
- tr.Commit();
- }
- }
|