CAD二开(c#)小试牛刀系列9 dat点数据读入CAD

使用工具==CAD2018+VS2022

主要作用==测量外业数据导入CAD,主要是读入全站仪或者gps采集的点数据文件

具体代码如下:

Database db = HostApplicationServices.WorkingDatabase;
Editor ed = acadApp.Application.DocumentManager.MdiActiveDocument.Editor;

//打开文件
OpenFileDialog openDlg = new OpenFileDialog();
openDlg.Filter = "数据文件|*.dat";
openDlg.ShowDialog();
string pathDat =openDlg.FileName;

string[] contens = File.ReadAllLines(pathDat);//读取dat文件中的数据            

//图层设置 自定义的新建图层函数
Tools.AddLayerTab(db,"pointName",0);//点名
Tools.AddLayerTab(db, "points", 1);//点位
Tools.AddLayerTab(db, "pointHeighText", 1);//高程

foreach (var item in contens)
{
    string[] datas = item.Split(',');//拆分数据

    string ptName = datas[0];//点名
    double pointY = double.Parse(datas[2]);//y坐标
    double pointX = double.Parse(datas[3]);//x坐标
    double pointZ = double.Parse(datas[4]);//z坐标 

    //点样式                                      
    db.Pdmode = 33;
    db.Pdsize = 0.5;

    Point3d point = new Point3d(pointX, pointY, pointZ);
    DBPoint dbPoints = new DBPoint(point);//点集合                   
    dbPoints.Layer = "points";//点的图层

    //高程文字
    DBText dbHeighText = new DBText();
    dbHeighText.Layer = "pointHeighText";//高程标注文字图层
    dbHeighText.Position = point;//文字位置
    dbHeighText.Rotation = 0;//文字旋转
    dbHeighText.Height = 0.5;//文字高度
    dbHeighText.TextString = pointZ.ToString("0.00");//文字内容

    //点名文字
    DBText dbText = new DBText();
    dbText.Layer = "pointName";
    dbText.Position = point;
    dbText.Rotation = 0;
    dbText.Height = 0.5;
    dbText.TextString = ptName;


    //导入实体
    Tools.AddToModelSpace(db, dbText);//写文字 
    Tools.AddToModelSpace(db, dbHeighText);//写文字 
    Tools.AddToModelSpace(db, dbPoints);//写入点数据      
}

wind.MessageBox.Show("坐标点导入成功");

  • 4
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值