使用工具==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("坐标点导入成功");