public void AddComplexRegion() { Database db = HostApplicationServices.WorkingDatabase; using (Transaction trans = db.TransactionManager.StartTransaction()) { //创建一个正六边形 Polyline polygon = new Polyline(); polygon.CreatePolygon(new Point2d(500, 200), 6, 30); //创建一个圆 Circle circle = new Circle { Center = new Point3d(500, 200, 0), Radius = 10 }; //根据正六边形和圆创建面域 List <Region> regions = RegionTools.CreateRegion(polygon, circle); if (regions.Count == 0) { return; //如果面域创建未成功,则返回 } //使用LINQ按面积对面域进行排序 List <Region> orderRegions = (from r in regions orderby r.Area select r).ToList(); //对面域进行布尔操作,获取正六边形减去圆后的部分 orderRegions[1].BooleanOperation(BooleanOperationType.BoolSubtract, orderRegions[0]); db.AddToModelSpace(regions[1]); //将上面操作好的面域添加到数据库中 trans.Commit(); //提交更改 } }
public void AddRegion() { Database db = HostApplicationServices.WorkingDatabase; using (Transaction trans = db.TransactionManager.StartTransaction()) { //创建一个三角形 Polyline triangle = new Polyline(); triangle.CreatePolygon(new Point2d(550, 200), 3, 30); //根据三角形创建面域 List <Region> regions = RegionTools.CreateRegion(triangle); if (regions.Count == 0) { return; //如果面域创建未成功,则返回 } Region region = regions[0]; db.AddToModelSpace(region);//将创建的面域添加到数据库中 //获取面域的质量特性 GetAreaProp(region); trans.Commit();//提交更改 } }