037集——JoinEntities连接多段线polyline和圆弧arc(CAD—C#二次开发入门)

如图:最终效果

polyline连接:

代码如下:

cs 复制代码
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 entities
    try
    {
        IntegerCollection joinedEntities = pLine.JoinEntities(otherEntities);//调用函数的主题必须polyline
        if (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连接:

cs 复制代码
 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);//调用函数的主题必须polyline
         if (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)

cs 复制代码
 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);//调用函数的主题必须polyline
         if (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();

}

cs 复制代码
 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);//调用函数的主题必须polyline
         if (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;
 }
相关推荐
Algorithm15766 分钟前
云原生相关的 Go 语言工程师技术路线(含博客网址导航)
开发语言·云原生·golang
shinelord明16 分钟前
【再谈设计模式】享元模式~对象共享的优化妙手
开发语言·数据结构·算法·设计模式·软件工程
呆呆小雅21 分钟前
C#关键字volatile
java·redis·c#
Monly2122 分钟前
Java(若依):修改Tomcat的版本
java·开发语言·tomcat
boligongzhu23 分钟前
DALSA工业相机SDK二次开发(图像采集及保存)C#版
开发语言·c#·dalsa
Eric.Lee202123 分钟前
moviepy将图片序列制作成视频并加载字幕 - python 实现
开发语言·python·音视频·moviepy·字幕视频合成·图像制作为视频
7yewh26 分钟前
嵌入式Linux QT+OpenCV基于人脸识别的考勤系统 项目
linux·开发语言·arm开发·驱动开发·qt·opencv·嵌入式linux
waicsdn_haha37 分钟前
Java/JDK下载、安装及环境配置超详细教程【Windows10、macOS和Linux图文详解】
java·运维·服务器·开发语言·windows·后端·jdk
_WndProc39 分钟前
C++ 日志输出
开发语言·c++·算法
web1478621072341 分钟前
C# .Net Web 路由相关配置
前端·c#·.net