//参考:https://adndevblog.typepad.com/autocad/2012/04/perimeter-of-a-hatch-using-objectarx-and-autocad-net-api.html
//计算图案填充的周长
//qq群 720924083
//2020-11-14
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Windows;
using Autodesk.AutoCAD.Geometry;
namespace AcadDemo
{public class PerimeterOfHatch{      // Perimeter calculation of a hatch using AutoCAD.Net API[CommandMethod("HatchTest")]public void HatchTestMethod(){Document activeDoc= Application.DocumentManager.MdiActiveDocument;Editor ed = activeDoc.Editor;PromptEntityOptions peo= new PromptEntityOptions("Select a hatch : ");peo.SetRejectMessage("\nPlease select a hatch");peo.AddAllowedClass(typeof(Hatch), true);PromptEntityResult per = ed.GetEntity(peo);if (per.Status != PromptStatus.OK)return;HatchPerimeter(per.ObjectId);}void HatchPerimeter(ObjectId entId){Document activeDoc = Application.DocumentManager.MdiActiveDocument;Database db = activeDoc.Database;Editor ed = activeDoc.Editor;using (Transaction tr = db.TransactionManager.StartTransaction()){Hatch hatch = tr.GetObject(entId, OpenMode.ForRead) as Hatch;int nLoops = hatch.NumberOfLoops;double totalExternalPerimeter = 0.0;double totalInternalPerimeter = 0.0;for (int i = 0; i < nLoops; i++){double loopLength = 0.0;HatchLoopTypes hlt = hatch.LoopTypeAt(i);HatchLoop hatchLoop = hatch.GetLoopAt(i);if ((hatch.LoopTypeAt(i) & HatchLoopTypes.Polyline)== HatchLoopTypes.Polyline){BulgeVertexCollection bulges= hatchLoop.Polyline;int nVertices = bulges.Count;Polyline testPoly = new Polyline(nVertices);for (int vx = 0; vx < bulges.Count; vx++){BulgeVertex bv = bulges[vx];testPoly.AddVertexAt(vx,bv.Vertex,bv.Bulge,1.0,1.0);}LineSegment3d ls = new LineSegment3d();CircularArc3d cs = new CircularArc3d();double d = 0.0, p1 = 0.0, p2 = 1.0;for (int ver = 0; ver < nVertices - 1; ver++){d = testPoly.GetBulgeAt(ver);if (d <= 1e-5){ls = testPoly.GetLineSegmentAt(ver);loopLength += ls.Length;}else{Point2d v1= new Point2d(bulges[ver].Vertex.X,bulges[ver].Vertex.Y);Point2d v2= new Point2d(bulges[ver + 1].Vertex.X,bulges[ver + 1].Vertex.Y);if (v1.IsEqualTo(v2) == false){cs = testPoly.GetArcSegmentAt(ver);p1 = cs.GetParameterOf(cs.StartPoint);p2 = cs.GetParameterOf(cs.EndPoint);loopLength +=cs.GetLength(p1,p2,Tolerance.Global.EqualPoint);}}}}else{Curve2dCollection curves = hatchLoop.Curves;if (curves != null){foreach (Curve2d curve in curves){if (hatchLoop.LoopType== HatchLoopTypes.External){totalExternalPerimeter +=curve.GetLength(0.0, 1.0);}else{totalInternalPerimeter +=curve.GetLength(0.0, 1.0);}}}}if (nLoops > 1 &&((hlt & HatchLoopTypes.External) != HatchLoopTypes.External)){totalInternalPerimeter += loopLength;}else{totalExternalPerimeter += loopLength;}}ed.WriteMessage(string.Format("\nExternal Perimeter : {0}",totalExternalPerimeter));ed.WriteMessage(string.Format("\nInternal Perimeter : {0}",totalInternalPerimeter));tr.Commit();}}}
}

autocad.net计算图案填充的周长相关推荐

  1. autoCAD 创建对象 使用面域 创建图案填充

    创建对象 在 AutoCAD 中经常有多种不同的方法可以创建相同的图形对象.虽然 .NET API 没有提供同样的创建对象的组合,但是它除为每一个对象类型都提供一个基本的对象构造函数外,也提供了对象构 ...

  2. #计算长方形的周长和面积公式_Animate如何制作动态计算长方形面积及周长

    前面讲了如何制作一个动态计算三角形面积的小程序,这里再讲一下如何制作一个动态计算长方形面积及周长的小程序. Animate如何制作动态计算三角形面积的程序(1)-百度经验​jingyan.baidu. ...

  3. 用计算机在记事本做图案,记事本如何自定义制作CAD图案填充

    使用记事本通过对CAD填充图案文件进行编辑,添加新的图案填充. 1.*PAT库文件标准格式: *pattern-name [, description] angle, x-origin, y-orig ...

  4. python图案填充_用matplotlib用自定义图案填充多边形

    以下内容不能解决此问题.它只是解决了问题的一部分,并显示了该方法在哪一点上失败.我目前确信matplotlib无法使用任意角度进行图案填充,因为单位单元格的大小是固定的. 为了克服设置角度的问题,可以 ...

  5. cad中填充的剖面线不能被修剪_cad 剖面线在图案填充里应该怎么设置

    可能是你剖面线的比例太大了,默认比例是1:1的,你把比例改成0.75 0.25点击[绘图]-[填充图案]对话框里有比例选项,你改成0.25 再试一下,如果还没有可能是你选的图形不是封闭的,你把连接点放 ...

  6. R语言ggpattern填充各种色彩、形状、纹理、图片到ggplot2可视化图像:图案填充列表、饼图图案填充、柱状图图案填充

    ​R语言ggpattern填充各种色彩.形状.纹理.图片到ggplot2可视化图像:图案填充列表.饼图图案填充.柱状图图案填充 目录

  7. AutoCAD LISP花型图案一

    AutoCAD LISP花型图案一,代码如下. (defun c:test()   (setq cen1 (getpoint "\n中心点:"))   (setq rr (getd ...

  8. python图案填充_向imshow Matplotlib添加图案填充

    基本上,我要做的是在this问题的答案中解释的想法.在 我用imshow绘制一幅100×100的图像,在某些情况下,我想绘制图案填充.在 下面是我的图像示例: 这表示100个标量场样本的平均值.我还有 ...

  9. python多边形图案_如何用matplotlib中的自定义图案填充多边形?

    您可以子类matplotlib.hatch.Shapes,并根据在unit square[[-0.5,0.5]x[-0.5,0.5]]内绘制的任何引用路径定义自定义图案填充.在 暂定:import n ...

最新文章

  1. Linux如何解决动态库的版本控制
  2. linux 文件目录
  3. 跟谁学、有道营销费用大于营业收入,在线教育企业烧钱大战何时休?
  4. sql server select和set赋值的区别
  5. sublime php错误提示,sublime中检查php语法错误
  6. linux内核编译步骤
  7. python最优调配问题_Python实现的基于优先等级分配糖果问题算法示例
  8. easymock教程_EasyMock教程
  9. 手写原笔迹输入_手写原笔迹
  10. 如何在Windows 10上修复缩略图问题
  11. 使用vscode开发,使用插件记录
  12. 访问hadoop集群时错误:Access denied for user Administrator. Superuser privilege is required
  13. 通过身份证号码得出性别和年龄
  14. 自媒体技巧:企鹅号与公众号同步教程
  15. ai为什么要栅格化_AI 效果-栅格化的具体用途是什么
  16. 理解Web 3:非事后的想法
  17. JTextField:单行文本框组件
  18. 新手做电商直播带货怎么和快递合作谈价格
  19. 局域网arp攻击_图解ARP协议(三)ARP防御篇-如何揪出“内鬼”并“优雅的还手”...
  20. LCD屏幕调试过程(驱动IC ST7701s)

热门文章

  1. iPhone手机加入wifi报错: 无法加入网络
  2. win10系统怎么调计算机出来,win10我的电脑怎么调出来
  3. 全面HTML5化:火狐移动操作系统B2G价值几何
  4. 手机百度打不开html网页,手机百度网页打不开怎么办 手机百度网页打不开的解决方法...
  5. 15秒正能量视频制作技巧
  6. cesium 旋转弹跳四棱锥(光带扫描)(动态泛光效果)
  7. 刘军旗书编《满江红》
  8. 2022html css高频面试题
  9. linux 脚本 退出命令,使用linux的exit命令退出shell
  10. 扫雷 黑白版 C语言练习