如图:最终效果
polyline连接:
代码如下:
public void joinentities()
{Curve pLine = Z.db.SelectEntities<Curve>().First().Clone() as Curve;pLine.ChangeEntityColor(1);Curve pLine1 = Z.db.SelectEntities<Curve>().First().Clone() as Curve;Curve pLine2 = Z.db.SelectEntities<Curve>().First().Clone() as Curve;Entity[] otherEntities = new Entity[2];otherEntities[0] = pLine1;otherEntities[1] = pLine2;// join the other entitiestry{IntegerCollection joinedEntities = pLine.JoinEntities(otherEntities);//调用函数的主题必须polylineif (joinedEntities.Count > 0) Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("nSome or all entities joined!");Z.db.AddEntityToModeSpace(pLine);Z.Zoom();}catch (System.Exception){Z.ed.WriteMessage("连接失败!\n");}
}
polyline3d连接:
public void joinentitiesPolyline3d(){Point3d[] p3d = new Point3d[2] { new Point3d(10, 10, 0), new Point3d(0, 0, 0) };Polyline3d p3 = new Polyline3d(Poly3dType.SimplePoly,new Point3dCollection(p3d),false);Curve firstPl = p3;//polyline3d可连接范围广,包括圆弧,椭圆弧,样条曲线,直线,多段线// Curve firstPl = Z.db.SelectEntities<Curve>().First().Clone() as Curve;//连接的线不能是数据库中已有的线if (firstPl is null) return; firstPl.ChangeEntityColor(1);List<Curve> curveslist = Z.db.SelectEntities<Curve>();Curve[] curvesarray = new Curve[curveslist.Count];for (int i = 0; i < curveslist.Count; i++){curvesarray[i] = curveslist[i].Clone()as Curve;}try{IntegerCollection resultPl = firstPl.JoinEntities(curvesarray);//调用函数的主题必须polylineif (resultPl.Count > 0) Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("nSome or all entities joined!");Z.db.AddEntityToModeSpace(firstPl);Z.Zoom();}catch (System.Exception){Z.ed.WriteMessage("连接失败!\n");} }
Polyline连接(可连接弧,不可连spline和ellipse)
public void joinentitiesPolyline3d(){Point3d[] p3d = new Point3d[2] { new Point3d(10, 10, 0), new Point3d(0, 0, 0) };Polyline3d p3 = new Polyline3d(Poly3dType.SimplePoly,new Point3dCollection(p3d),false);Curve firstPl = p3;//polyline3d可连接范围广,包括圆弧,椭圆弧,样条曲线,直线,多段线// Curve firstPl = Z.db.SelectEntities<Curve>().First().Clone() as Curve;//连接的线不能是数据库中已有的线if (firstPl is null) return; firstPl.ChangeEntityColor(1);List<Curve> curveslist = Z.db.SelectEntities<Curve>();Curve[] curvesarray = new Curve[curveslist.Count];for (int i = 0; i < curveslist.Count; i++){curvesarray[i] = curveslist[i].Clone()as Curve;}try{IntegerCollection resultPl = firstPl.JoinEntities(curvesarray);//调用函数的主题必须polylineif (resultPl.Count > 0) Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("nSome or all entities joined!");Z.db.AddEntityToModeSpace(firstPl);Z.Zoom();}catch (System.Exception){Z.ed.WriteMessage("连接失败!\n");} }
封装后结果:
public void xx()
{
Polyline polyline = Z.PolyJoin();
}
public static Polyline PolyJoin(){//Point3d[] p3d = new Point3d[2] { new Point3d(10, 10, 0), new Point3d(0, 0, 0) };//Polyline3d p3 = new Polyline3d(Poly3dType.SimplePoly,new Point3dCollection(p3d),false);//Curve firstPl = p3;//polyline3d可连接范围广,包括圆弧,椭圆弧,样条曲线,直线,多段线//Curve firstPl = Z.db.SelectEntities<Curve>().First().Clone() as Curve;//连接的线不能是数据库中已有的线//if (firstPl is null) return; Polyline firstPl = new Polyline();List<Curve> curveslist = Z.db.SelectEntities<Curve>();Curve[] curvesarray = new Curve[curveslist.Count];for (int i = 0; i < curveslist.Count; i++){curvesarray[i] = curveslist[i].Clone() as Curve;}try{firstPl = curvesarray.Where(x => x is Polyline).First() as Polyline;IntegerCollection resultPl = firstPl.JoinEntities(curvesarray);//调用函数的主题必须polylineif (resultPl.Count > 0) Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("nSome or all entities joined!");firstPl.ChangeEntityColor(1); Z.db.AddEntityToModeSpace(firstPl);//Z.Zoom();}catch (System.Exception){Z.ed.WriteMessage("连接失败!\n");}return firstPl;}