using Autodesk..ApplicationServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Windows;
using Autodesk.AutoCAD.ViewModel;
using Autodesk.AutoCAD.Publishing;
using Autodesk.AutoCAD.PlottingServices;
using Autodesk.AutoCAD.LivePreview;
using Autodesk.AutoCAD.LayerManager;
using Autodesk.AutoCAD.Interop;
using Autodesk.AutoCAD.Internal;
using Autodesk.AutoCAD.GraphicsSystem;
using Autodesk.AutoCAD.GraphicsInterface;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.ComponentModel;
using Autodesk.AutoCAD.BoundaryRepresentation;
using Autodesk.AutoCAD.AcInfoCenterConn;
entity和entity2 为选中的相交的2个封闭polyline
using (Transaction tr = tm.StartTransaction())
{
BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
Entity entity = tr.GetObject(entityID, OpenMode.ForWrite) as Entity;
//MgGeometry geometry = EntityToGeometryConverter.EntityToGeometry(entity);
Entity entity2 = tr.GetObject(entityID2, OpenMode.ForWrite) as Entity;
DBObjectCollection curveSegments = new DBObjectCollection();
curveSegments.Add(entity);
DBObjectCollection regions = Region.CreateFromCurves(curveSegments);
Region region = regions[0] as Region;
DBObjectCollection curveSegments2 = new DBObjectCollection();
curveSegments2.Add(entity2);
DBObjectCollection regions2 = Region.CreateFromCurves(curveSegments);
Region region2 = regions2[0] as Region;
region.BooleanOperation(BooleanOperationType.BoolSubtract, region2);
DBObjectCollection cvs =new DBObjectCollection();
//region.Explode(cvs);
ObjectId id1 = cadLayer.AddLayer("冲突图斑");
// Entity en = region as Entity;
Brep brep = new Brep(region );//出现异常
BrepEdgeCollection elp = brep.Edges;
foreach (Edge edge in elp)
{
NurbCurve3d c3d = edge.GetCurveAsNurb();
Curve cv = Curve.CreateFromGeCurve(c3d);
cv.ColorIndex = 1;
cv.Layer = "冲突图斑";
btr.AppendEntity(cv);
tr.AddNewlyCreatedDBObject(cv, true);