当前位置: 首页 > ops >正文

C#开源库ACadSharp读取dwg图元的示例

文章目录

  • 介绍
  • 数据示例
  • 读取图元属性

介绍

开源库ACadSharp的地址:https://github.com/DomCR/ACadSharp

可以在NuGet中搜索到该库并安装。

数据示例

数据是一个绘制了以下简单图元的dwg数据:
在这里插入图片描述

读取图元属性

创建了.net6控制台项目,通过NuGet安装了ACadSharp库。

测试了以下几种图元的读取:

  • Line
  • Arc
  • Circle
  • Ellipse
  • LwPolyline
  • MText
  • Text
using ACadSharp.IO;
using ACadSharp;
using ACadSharp.Entities;namespace TestACadSharp
{internal class Program{static void Main(string[] args){var dwgPath = "./test-data/demo.dwg";CadDocument doc = DwgReader.Read(dwgPath, onNotification);//遍历所有实体foreach (var entity in doc.Entities){PrintInfo(entity);Console.WriteLine();}Console.WriteLine("Over!");}static void PrintInfo(Entity ent){switch (ent){case Line:var e = ent as Line;Console.WriteLine($"Line: X1={e.StartPoint.X},Y1={e.StartPoint.Y}," +$"X2={e.EndPoint.X},Y2={e.EndPoint.Y},Handle={e.Handle}");break;case Arc:var a = ent as Arc;Console.WriteLine($"Arc: r={a.Radius},X={a.Center.X},Y={a.Center.Y}," +$"StartAngle={a.StartAngle},EndAngle={a.EndAngle}");break;case Circle:var c = ent as Circle;Console.WriteLine($"Circle: r={c.Radius},X={c.Center.X},Y={c.Center.Y}");break;case Ellipse:var ee = ent as Ellipse;Console.WriteLine($"Ellipse: X={ee.Center.X},Y={ee.Center.Y}," +$"MajorAxis={ee.MajorAxis},MinorAxis={ee.MinorAxis}," +$"Rotation={ee.Rotation}");break;case Polyline:var p = ent as Polyline;Console.WriteLine($"Polyline: IsClosed={p.IsClosed}");for (int i = 0; i < p.Vertices.Count; i++){var v = p.Vertices[i];Console.WriteLine($"Bulge={v.Bulge},X={v.Location.X},Y={v.Location.Y}");}break;case LwPolyline:var wp = ent as LwPolyline;Console.WriteLine($"LwPolyline: IsClosed={wp.IsClosed}");for (int i = 0; i < wp.Vertices.Count; i++){var v = wp.Vertices[i];Console.WriteLine($"Bulge={v.Bulge},X={v.Location.X},Y={v.Location.Y}");}break;case MText:var mt = ent as MText;Console.WriteLine($"MText: X={mt.InsertPoint.X},Y={mt.InsertPoint.Y},Text={mt.Value},Height={mt.Height}");break;case TextEntity:var t = ent as TextEntity;Console.WriteLine($"Text: X={t.InsertPoint.X},Y={t.InsertPoint.Y},Text={t.Value},Height={t.Height}");break;default:break;}}// Process a notification form the readerprivate static void onNotification(object sender, NotificationEventArgs e){Console.WriteLine(e.Message);}}
}

在控制台打印了图元的部分属性:

Line: X1=0,Y1=0,X2=100,Y2=100,Handle=591Circle: r=20,X=100,Y=100LwPolyline: IsClosed=False
Bulge=0,X=100,Y=0
Bulge=0,X=200,Y=100
Bulge=0,X=200,Y=200Arc: r=50,X=200,Y=0,StartAngle=1.5707963267948961,EndAngle=3.5853960407017067LwPolyline: IsClosed=True
Bulge=0,X=0,Y=200
Bulge=0,X=20,Y=200
Bulge=0,X=100,Y=300
Bulge=0,X=20,Y=300LwPolyline: IsClosed=False
Bulge=1.7160122950374628,X=144.12226845286386,Y=251.44355233800798
Bulge=0,X=203.49903695426838,Y=270.9970954309483
Bulge=0,X=168.5715230805963,Y=344.3228820294762
Bulge=0,X=91.0324529571044,Y=367.36812645092596Ellipse: X=325.5331742656035,Y=139.27755185746537,MajorAxis=167.47948810551864,MinorAxis=61.59293601510967,Rotation=-2.3304093705041717Text: X=334.465413122849,Y=340.1926829662716,Text=hello,Height=77.01746524013924MText: X=427.1373896780551,Y=226.34077414221065,Text=world\P!!!!,Height=77.01746524013924
http://www.xdnf.cn/news/18425.html

相关文章:

  • Springboot项目的各层级详细总结
  • 【GaussDB】全密态等值查询功能测试及全密态技术介绍
  • Python socket远程部署工具服务
  • 论文阅读:Do As I Can, Not As I Say: Grounding Language in Robotic Affordances
  • 基于Django的学校实验室预约管理系统/基于python的实验室管理系统的设计与实现#python#django#FLASK
  • Spring Start Here 读书笔记:第9章 Using the Spring web scopes
  • Excel表格指定数据读取写入到另一个Excel表中(指定列指定行)
  • CXR-LT 2024:一场关于基于胸部X线的长尾、多标签和零样本疾病分类的MICCAI挑战赛|文献速递-深度学习人工智能医疗图像
  • 前端AI工具——TRAE
  • ExcelUtils实现 设置内容 插入行 复制行列格式
  • Blender模型动画导入到UE5
  • 【python】python进阶——推导式
  • 基于 SkyWalking + Elasticsearch + Grafana 的可落地调用链监控方案
  • 氙灯市场报告:亚太成增长主力,汽车、医疗、科研多领域需求驱动行业发展
  • 数据结构 -- 队列
  • Redis内存碎片深度解析:成因、检测与治理实战指南
  • Day16 二叉树part4
  • JDK21之虚拟线程的深入理解
  • Halcon那些事:什么是动态阈值,如何用dyn_threshold分割图片
  • 腾讯云COS SDK签名有效期设置为10分钟到期会自动刷新
  • Java后端学习路线
  • uniapp googlepay支付 内购项目
  • mysql编程(简单了解)
  • pthon实现bilibili缓存视频音频分离
  • 数据预处理学习笔记
  • 【C++】--函数参数传递:传值与传引用的深度解析
  • 防爆自动气象监测设备:高危环境的 “安全堡垒”
  • SpringBoot中的条件注解
  • 工作后的总结和反思1
  • 如何制定股指期货投机交易策略计划?