Brep brep = new Brep(region );//出现异常
using Autodesk.AutoCAD.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, 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 as Region;
DBObjectCollection curveSegments2 = new DBObjectCollection();
curveSegments2.Add(entity2);
DBObjectCollection regions2 = Region.CreateFromCurves(curveSegments);
Region region2 = regions2 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);
}
tr.Commit();
}
最好先用简单的例子测试下 brep库用的人很少 这个是最简单的,选择2个entity 裁剪得到结果 解析
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 as Region;
var region1 = regions 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();
}
}
为什么用edge.curve 得到的曲线 不能用createfromgecurve 生成db曲线呢 只能用edge.GetCurveAsNurb得到dbcurve
页:
[1]