明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1691|回复: 4

第一个c#练习的程序遍历块获取块内图元的外框

[复制链接]
发表于 2020-2-18 09:56 | 显示全部楼层 |阅读模式

  1.          [CommandMethod("PickDemo")]
  2.          public void PickDemo()
  3.          {
  4.              Database db = HostApplicationServices.WorkingDatabase;
  5.              Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
  6.              PromptEntityResult per = ed.GetEntity("选择块");
  7.              if (per.Status == PromptStatus.OK)
  8.              {
  9.                  using (Transaction trans = db.TransactionManager.StartTransaction())
  10.                  {
  11.                      ResultBuffer result = new ResultBuffer();
  12.                      BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
  13.                      BlockReference br = (BlockReference)per.ObjectId.GetObject(OpenMode.ForRead);
  14.                      string blkname = br.Name;
  15.                      ed.WriteMessage("\nBlock Name: (" + blkname + ").");
  16.                      ObjectId blockRecordId = bt[blkname];
  17.                      BlockTableRecord blockRecord = (BlockTableRecord)blockRecordId.GetObject(OpenMode.ForRead);
  18.                      Extents3d tmpExtents3D = new Extents3d();
  19.                      foreach (ObjectId entID in blockRecord)
  20.                      {
  21.                          Entity entity = (Entity)trans.GetObject(entID, OpenMode.ForRead);
  22.                          Extents3d tmp = entity.GeometricExtents;
  23.                          tmpExtents3D.AddExtents(tmp);
  24.                      
  25.                      
  26.                      }
  27.                      Point3d maxpt = tmpExtents3D.MaxPoint;
  28.                      Point3d minpt = tmpExtents3D.MinPoint;
  29.                      result.Add(new TypedValue((int)LispDataType.Point3d, minpt));
  30.                      result.Add(new TypedValue((int)LispDataType.Point3d, maxpt));
  31.                      trans.Commit();
  32.                     //return result;
  33.                  }
  34.              }
  35.          }
发表于 2020-3-9 08:50 | 显示全部楼层
最好能做一个非块的外轮廓线的生成
发表于 2021-3-16 09:02 | 显示全部楼层
很不错的做法
发表于 2022-12-5 15:14 | 显示全部楼层
感谢大神的分享~
发表于 2023-2-24 11:08 | 显示全部楼层
最大边界  要能识别 样条曲线 多线段 直线 圆弧 块 还能设置容差 就完美了!! 估计这个很难做到!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-4-20 18:00 , Processed in 0.306321 second(s), 22 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表