CAD多段线两侧偏移(交叉线容易出错)

  public void 交叉多段线容易出错(){List<Curve> entse = Z.db.SelectEntities<Curve>();List<Polyline> ents =  Z.db.CurvesToPolyLines(entse);//Z.db.SelectEntities<Polyline>();double offsetDistance = 5.0;//偏移距离List<Polyline> resultPolylines = new List<Polyline>();List<Circle> resultCir = new List<Circle>();List<Region> regions = new List<Region>();DBObjectCollection tempColl = new DBObjectCollection();//DBObjectCollection allColl = new DBObjectCollection();//所有对象集合foreach (var item in ents){Polyline polyline = item ;DBObjectCollection offsetLineSegLeft = polyline.GetOffsetCurves(offsetDistance);DBObjectCollection offsetLineSegRight = polyline.GetOffsetCurves( (-1)*offsetDistance);Polyline pltemp1 = offsetLineSegLeft[0] as Polyline;Polyline pltemp2 = offsetLineSegRight[0] as Polyline;Polyline pltempxx = new Polyline();Polyline pltempyy = new Polyline();pltempxx.AddVertexAt(0,new Point2d(pltemp1.StartPoint.X, pltemp1.StartPoint.Y),  0, 0, 0);pltempxx.AddVertexAt(1, new Point2d(pltemp2.StartPoint.X, pltemp2.StartPoint.Y), 0, 0, 0);pltempyy.AddVertexAt(0, new Point2d(pltemp2.EndPoint.X, pltemp2.EndPoint.Y), 0, 0, 0);pltempyy.AddVertexAt(1, new Point2d(pltemp1.EndPoint.X, pltemp1.EndPoint.Y), 0, 0, 0);Z.db.AddEntityToModeSpace(pltempxx, pltempyy);Z.db.AddEntityToModeSpace(offsetLineSegLeft[0] as Polyline);Z.db.AddEntityToModeSpace(offsetLineSegRight[0] as Polyline);}}
 public static List<T> SelectEntities<T>(this Database db ) where T : Entity{List<T> result = new List<T>();Editor editor = Application.DocumentManager.MdiActiveDocument.Editor;var pso = new PromptSelectionOptions();pso.MessageForAdding = "\n请选择:";PromptSelectionResult psr = editor.GetSelection(pso);if (psr.Status == PromptStatus.OK){ObjectId[] objectids = psr.Value.GetObjectIds();Database database = HostApplicationServices.WorkingDatabase;using (Transaction tran = database.TransactionManager.StartTransaction()){foreach (var item in objectids){Entity entity = item.GetObject(OpenMode.ForRead) as Entity;if (entity is T){result.Add(entity as T);}}}}return result;}
  public static List<Autodesk.AutoCAD.DatabaseServices.Polyline> CurvesToPolyLines(this Database db, List<Curve> ents){List<Autodesk.AutoCAD.DatabaseServices.Polyline> curves = new List<Autodesk.AutoCAD.DatabaseServices.Polyline>();Spline sp;foreach (var item in ents){if (item is Polyline oldpl){curves.Add(oldpl);}if (item is Line line){Polyline polyline = new Polyline();polyline.AddVertexAt(0,new Point2d (line .StartPoint.X,line.StartPoint.Y),0,0,0);polyline.AddVertexAt(1, new Point2d(line.EndPoint.X, line.EndPoint.Y), 0, 0, 0);polyline.ColorIndex = line.ColorIndex;curves.Add(polyline);}if (item is Circle){Circle temp = (Circle)item;Point3d pt = temp.Center;double leftx = pt.X - temp.Radius;double rightx = pt.X + temp.Radius;double topx = pt.X;double bottomx = pt.X;double lefty = pt.Y;double righty = pt.Y;double topy = pt.Y + temp.Radius;double bottomy = pt.Y - temp.Radius;Point2d left = new Point2d(leftx, lefty);Point2d right = new Point2d(rightx, righty);Point2d top = new Point2d(topx, topy);Point2d bottom = new Point2d(bottomx, bottomy);Autodesk.AutoCAD.DatabaseServices.Polyline pl = new Autodesk.AutoCAD.DatabaseServices.Polyline();pl.AddVertexAt(0, bottom, 1, 0, 0);pl.AddVertexAt(1, top, 1, 0, 0);pl.AddVertexAt(2, bottom, 0, 0, 0);pl.ColorIndex = temp.ColorIndex;curves.Add(pl);//pl.Highlight();}if (item is Arc arc){double ang = 0;if (arc.StartAngle > arc.EndAngle){double endangle;endangle = arc.EndAngle + 2 * Math.PI;ang = endangle - arc.StartAngle;}else{ang = arc.EndAngle - arc.StartAngle;}//Debugger.Break();ang = ang / 4;double td = Math.Tan(ang);// arc.Spline;Autodesk.AutoCAD.DatabaseServices.Polyline pl = new Autodesk.AutoCAD.DatabaseServices.Polyline();// if arc.StartAnglepl.AddVertexAt(0, new Point2d(item.StartPoint.X, item.StartPoint.Y), td, 0, 0);pl.AddVertexAt(1, new Point2d(item.EndPoint.X, item.EndPoint.Y), 0, 0, 0);pl.ColorIndex = arc.ColorIndex;curves.Add(pl);//Z.db.AddEntityToModeSpace(pl);}if (item is Ellipse ellipse){sp = item.Spline;var curve = sp.ToPolyline();curve.ColorIndex = ellipse.ColorIndex;curves.Add(curve as Polyline);}if (item is Spline spline){Spline sp2 = (Spline)item;var curve2 = sp2.ToPolyline();curve2.ColorIndex = spline.ColorIndex;curves.Add(curve2 as Polyline);}}List<Curve> eracurves = new List<Curve>();foreach (var item in ents){if (item is Circle || item is Arc || item is Ellipse || item is Spline|| item is Line){eracurves.Add(item );}}Z.db.Erase(eracurves);Z.db.AddEntityToModeSpace(curves.ToArray());//转换完加入模型空间return curves;}

curve版

 

 public void 交叉多段线容易出错可拟合闭合圆和椭圆(){List<Curve> entse = Z.db.SelectEntities<Curve>();List<Polyline> ents = Z.db.CurvesToPolyLines(entse);//Z.db.SelectEntities<Polyline>();//List<Curve> ents = Z.db.SelectEntities<Curve>();double offsetDistance = 5.0;//偏移距离List<Polyline> resultPolylines = new List<Polyline>();List<Circle> resultCir = new List<Circle>();List<Region> regions = new List<Region>();DBObjectCollection tempColl = new DBObjectCollection();//DBObjectCollection allColl = new DBObjectCollection();//所有对象集合foreach (var item in ents){      Curve polyline = item ;DBObjectCollection offsetLineSegLeft = polyline.GetOffsetCurves(offsetDistance);DBObjectCollection offsetLineSegRight = polyline.GetOffsetCurves( (-1)*offsetDistance);Curve pltemp1 = offsetLineSegLeft[0] as Curve; //as Polyline;Curve pltemp2 = offsetLineSegRight[0] as Curve;//as Polyline;if (!item.Closed)//如果不闭合{ Polyline pltempxx = new Polyline();Polyline pltempyy = new Polyline();pltempxx.AddVertexAt(0,new Point2d(pltemp1.StartPoint.X, pltemp1.StartPoint.Y),  0, 0, 0);pltempxx.AddVertexAt(1, new Point2d(pltemp2.StartPoint.X, pltemp2.StartPoint.Y), 0, 0, 0);pltempyy.AddVertexAt(0, new Point2d(pltemp2.EndPoint.X, pltemp2.EndPoint.Y), 0, 0, 0);pltempyy.AddVertexAt(1, new Point2d(pltemp1.EndPoint.X, pltemp1.EndPoint.Y), 0, 0, 0);Curve[] arraypl = new Curve[3];arraypl[0]= pltempxx as Curve;arraypl[1]= pltemp2 ;arraypl[2]= pltempyy as Curve;pltemp1.ReverseCurve();//arraypl[3]= pltemp1;Curve closedpl = pltemp1;closedpl.JoinEntities(arraypl);Z.db.AddEntityToModeSpace(closedpl);//Z.db.AddEntityToModeSpace(pltempxx, pltempyy);}else{Z.db.AddEntityToModeSpace(offsetLineSegLeft[0] as Polyline);Z.db.AddEntityToModeSpace(offsetLineSegRight[0] as Polyline);}}}
 public static List<Autodesk.AutoCAD.DatabaseServices.Polyline> CurvesToPolyLines(this Database db, List<Curve> ents){List<Autodesk.AutoCAD.DatabaseServices.Polyline> curves = new List<Autodesk.AutoCAD.DatabaseServices.Polyline>();Spline sp;foreach (var item in ents){if (item is Polyline oldpl){curves.Add(oldpl);}if (item is Line line){Polyline polyline = new Polyline();polyline.AddVertexAt(0,new Point2d (line .StartPoint.X,line.StartPoint.Y),0,0,0);polyline.AddVertexAt(1, new Point2d(line.EndPoint.X, line.EndPoint.Y), 0, 0, 0);polyline.ColorIndex = line.ColorIndex;curves.Add(polyline);}if (item is Circle){Circle temp = (Circle)item;Point3d pt = temp.Center;double leftx = pt.X - temp.Radius;double rightx = pt.X + temp.Radius;double topx = pt.X;double bottomx = pt.X;double lefty = pt.Y;double righty = pt.Y;double topy = pt.Y + temp.Radius;double bottomy = pt.Y - temp.Radius;Point2d left = new Point2d(leftx, lefty);Point2d right = new Point2d(rightx, righty);Point2d top = new Point2d(topx, topy);Point2d bottom = new Point2d(bottomx, bottomy);Autodesk.AutoCAD.DatabaseServices.Polyline pl = new Autodesk.AutoCAD.DatabaseServices.Polyline();pl.AddVertexAt(0, bottom, 1, 0, 0);pl.AddVertexAt(1, top, 1, 0, 0);pl.AddVertexAt(2, bottom, 0, 0, 0);pl.ColorIndex = temp.ColorIndex;pl.Closed = true;curves.Add(pl);//pl.Highlight();}if (item is Arc arc){double ang = 0;if (arc.StartAngle > arc.EndAngle){double endangle;endangle = arc.EndAngle + 2 * Math.PI;ang = endangle - arc.StartAngle;}else{ang = arc.EndAngle - arc.StartAngle;}//Debugger.Break();ang = ang / 4;double td = Math.Tan(ang);// arc.Spline;Autodesk.AutoCAD.DatabaseServices.Polyline pl = new Autodesk.AutoCAD.DatabaseServices.Polyline();// if arc.StartAnglepl.AddVertexAt(0, new Point2d(item.StartPoint.X, item.StartPoint.Y), td, 0, 0);pl.AddVertexAt(1, new Point2d(item.EndPoint.X, item.EndPoint.Y), 0, 0, 0);pl.ColorIndex = arc.ColorIndex;curves.Add(pl);//Z.db.AddEntityToModeSpace(pl);}if (item is Ellipse ellipse){sp = item.Spline;var curve = sp.ToPolyline();curve.ColorIndex = ellipse.ColorIndex;curves.Add(curve as Polyline);}if (item is Spline spline){Spline sp2 = (Spline)item;var curve2 = sp2.ToPolyline();curve2.ColorIndex = spline.ColorIndex;curves.Add(curve2 as Polyline);}}List<Curve> eracurves = new List<Curve>();foreach (var item in ents){if (item is Circle || item is Arc || item is Ellipse || item is Spline|| item is Line){eracurves.Add(item );}}Z.db.Erase(eracurves);Z.db.AddEntityToModeSpace(curves.ToArray());//转换完加入模型空间return curves;}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.xdnf.cn/news/17711.html

如若内容造成侵权/违法违规/事实不符,请联系一条长河网进行投诉反馈,一经查实,立即删除!

相关文章

数据库EVA模式与传统数据库模式 | 分析对比及应用场景

目录 1. 实战场景2. 基本知识3. 应用场景 1. 实战场景 从实战进行探讨以及深入&#xff1a; 事因是同事给我创建表结构的时候&#xff0c;以如下这种方式进行创建&#xff1a; 看到这张表的结构可能会思考&#xff1a; 为啥设备的部件值&#xff08;日期、数值、字符串&…

算法【Java】—— 动态规划之简单多状态 dp 问题

按摩师 https://leetcode.cn/problems/the-masseuse-lcci 状态表示&#xff1a;根据经验和题目要求&#xff0c;达到 i 位置的时候&#xff0c;预约时间最长 接着我们细分状态表示&#xff1a;在遍历数组的时候&#xff0c;到达 i 位置的时候&#xff0c;又两种情况&#xff…

小鸡模拟器 1.8.11 | 街机怀旧重温经典游戏,支持手柄

小鸡模拟器是一款支持多种经典游戏机模拟的游戏应用&#xff0c;包括街机、索尼(SONY)、世嘉、任天堂等主流掌机游戏以及PSP、GBA、NDS、SFC(超级任天堂SNES)、FC(红白机NES)、MD(世嘉MEGA DRIVE)、PS1、PS2等。应用支持手柄完美操作&#xff0c;兼容安卓手柄&#xff0c;让玩家…

Pygame坦克大战游戏开发实验报告

✅作者简介&#xff1a;2022年博客新星 第八。热爱国学的Java后端开发者&#xff0c;修心和技术同步精进。 &#x1f34e;个人主页&#xff1a;Java Fans的博客 &#x1f34a;个人信条&#xff1a;不迁怒&#xff0c;不贰过。小知识&#xff0c;大智慧。 &#x1f49e;当前专栏…

Springboot3.3.5 启动流程之 tomcat启动流程介绍

在文章 Springboot3.3.5 启动流程&#xff08;源码分析&#xff09; 中讲到 应用上下文&#xff08;applicationContext&#xff09;刷新(refresh)时使用模板方法 onRefresh 创建了 Web Server. 本文将详细介绍 ServletWebServer — Embedded tomcat 的启动流程。 首先&…

电子应用设计方案-12:智能窗帘系统方案设计

一、系统概述 本设计方案旨在打造便捷、高效的全自动智能窗帘系统。 二、硬件选择 1. 电机&#xff1a;选用低噪音、扭矩合适的智能电机&#xff0c;根据窗帘尺寸和重量确定电机功率&#xff0c;确保能平稳拉动窗帘。 2. 轨道&#xff1a;选择坚固、顺滑的铝合金轨道&…

Javaweb-day12(登录认证)

登录功能 登录校验&#xff08;重点&#xff09; 登录校验指的是在服务器接收到浏览器发送过来的请求之后&#xff0c;首先要对这个请求进行校验&#xff0c;先要校验一下用户登录了没有 怎么来实现登录校验的操作呢&#xff1f;具体的实现思路可以分为两部分&#xff1a; 在…

记录大学Linux运维上机考试题目和流程

备注&#xff1a;今年的Linux操作系统考试已经全部结束&#xff0c;仅作为一个记录和留念 前提&#xff1a;配置环回网卡和环境和nat网卡 1、搭建dns服务器 2、Apache和http服务 3、搭建postfix邮件服务器实现邮件发送 4、搭建vsftpdFTP服务器实现文件上传 题目如下&…

Linux驱动开发第2步_“物理内存”和“虚拟内存”的映射

“新字符设备的GPIO驱动”和“设备树下的GPIO驱动”都要用到寄存器地址&#xff0c;使用“物理内存”和“虚拟内存”映射时&#xff0c;非常不方便&#xff0c;而pinctrl和gpio子系统的GPIO驱动&#xff0c;非常简化。因此&#xff0c;要重点学习pinctrl和gpio子系统下的GPIO驱…

关于强化学习的一份介绍

在这篇文章中&#xff0c;我将介绍与强化学习有关的一些东西&#xff0c;具体包括相关概念、k-摇臂机、强化学习的种类等。 一、基本概念 所谓强化学习就是去学习&#xff1a;做什么才能使得数值化的收益信号最大化。学习者不会被告知应该采取什么动作&#xff0c;而是必须通…

vue内置指令和自定义指令

常见的指令&#xff1a; v-bind : 单向绑定解析表达式, 可简写为 :xxx v-model : 双向数据绑定 v-for : 遍历数组/对象/字符串 v-on : 绑定事件监听, 可简…

《Java核心技术 卷I》用户界面AWT事件继承层次

AWT事件继承层次 EventObject类有一个子类AWTEvent&#xff0c;它是所有AWT事件类的父类。 Swing组件会生成更多其他事件对象&#xff0c;都直接拓展自EventObject而不是AWTEvent。 AWT将事件分为底层(low-level)事件和语义事件。 语义事件&#xff1a;表示用户的动作事件&…

AntFlow:一款高效灵活的开源工作流引擎

AntFlow 是一款功能强大、设计优雅的开源工作流引擎&#xff0c;其灵感来源于钉钉的工作流设计理念&#xff0c;旨在为企业和开发者提供灵活、高效的工作流解决方案。AntFlow 支持复杂的业务流程管理&#xff0c;具有高度可定制性&#xff0c;且拥有现代化的前端设计&#xff0…

2024年江西省职业院校技能大赛网络建设与运维技能竞赛方案赛项规程(中职组)

2024 年江西省职业院校技能大赛网络建设与运维赛项竞赛&#xff0c;为 确保竞赛工作顺利开展&#xff0c;特制定本竞赛方案。 一、赛项介绍 1.赛项简介&#xff1a;本赛项设置网络理论测试、网络建设与调试、 服务搭建与运维三个模块&#xff0c;竞赛内容包括&#xff1a;职…

EWM 打印

目录 1 简介 2 后台配置 3 主数据 4 业务操作 1 简介 打印即输出管理&#xff08;output management&#xff09;利用“条件表”那一套理论实现。而当打印跟 EWM 集成到一起时&#xff0c;也需要利用 PPF&#xff08;Post Processing Framework&#xff09;那一套理论。而…

WLAN概述

前言 无线局域网WLAN是一种利用无线技术实现主机等总端设备灵活接入以太网的技术,它使得网路哦的国家你和终端的移动更加方便和灵活.不仅可以作为有线局域网的补充和延申,而且还要看与有线网络互为备份. WLAN应用 智能移动设备的使用热潮为BYOD(bring Your Own Device).BYOD解…

stm32——通用定时器时钟知识点

&#xff08;该图来自小破站 铁头山羊老师的stm32标准库教学&#xff09;

免费下载 | 2024年金融数字化转型白皮书

导读&#xff1a;数字经济的蓬勃发展给银行创造了全新的机遇和挑战&#xff0c;数字化转型升级已成为必然要求。在金融服务需求方面客户对银行的要求全面升级:一是个人生活线上化比重提升&#xff0c;对金融服务的需求频度和便捷度要求提高;二是企业业务场景化&#xff0c;对金…

RabbitMQ 高级特性——延迟队列

文章目录 前言延迟队列延迟队列的概念TTL 死信队列模拟延迟队列设置队列的 TTL设置消息的 TTL 延迟队列插件安装并且启动插件服务使用插件实现延迟功能 前言 前面我们学习了 TTL 和死信队列&#xff0c;当队列中的消息达到了过期时间之后&#xff0c;那么这个消息就会被死信交…

腾讯IM uniapp微信小程序版本实现迅飞语音听写(流式版)

在之前文章《腾讯IM web版本实现迅飞语音听写&#xff08;流式版&#xff09;》实现了腾讯IM web版本实现迅飞语音听写&#xff0c;本文将基于uniapp vue2/vue3&#xff08;cli 脚手架&#xff09;的Demo项目集成迅飞语音听写&#xff08;流式版&#xff09;&#xff1a; 主要代…