找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 3121|回复: 13

[每日一码] 选择SOLID 3D的子实体(面、边、顶点)

[复制链接]

已领礼包: 6个

财富等级: 恭喜发财

发表于 2016-9-11 00:04:31 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
下面的命令演示了提示用户选取SOLID3D的方法,允许用户选择一个单独的子实体并且检查子实体的类型是否匹配。选取完子实体后,使用BREP API检索表达这个子实体的Brep实体。进一步的使用Brep对象的方法执行分析子实体的属性。

The following command illustrates a way to prompt user for subentity selection on a solid3d. It allows to select a single subentity and checks if the selected subentity type matches the specified type.
After the subentity has been selected, it uses the Brep API and retrieve the Brep entity representing this subentity. Further methods of the Brep object can be invoked in order to analyze the properties of the subentity.
//Command SubEntSelectBrep: Prompts user to select a single
//solid sub-entity and filters type of sub-entity selected.
//Philippe Leefsma, Developer Technical Services. March 2012.

  1. [CommandMethod("SubEntSelectBrep")]
  2. public void SubEntSelectBrep()
  3. {
  4.     Document doc = Application.DocumentManager.MdiActiveDocument;
  5.     Database db = doc.Database;
  6.     Editor ed = doc.Editor;

  7.     PromptKeywordOptions pko = new PromptKeywordOptions(
  8.         "\nSpecify sub-entity selection type:");
  9.     pko.AllowNone = false;
  10.     pko.Keywords.Add("Face");
  11.     pko.Keywords.Add("Edge");
  12.     pko.Keywords.Add("Vertex");
  13.     pko.Keywords.Default = "Face";

  14.     PromptResult pkr = ed.GetKeywords(pko);

  15.     if (pkr.Status != PromptStatus.OK)
  16.         return;

  17.     SubentityType subentityType = SubentityType.Null;

  18.     switch(pkr.StringResult)
  19.     {
  20.         case "Face":
  21.             subentityType = SubentityType.Face;
  22.             break;
  23.         case "Edge":
  24.             subentityType = SubentityType.Edge;
  25.             break;
  26.         case "Vertex":
  27.             subentityType = SubentityType.Vertex;
  28.             break;
  29.         default:
  30.             return;
  31.     }

  32.     PromptSelectionOptions pso = new PromptSelectionOptions();
  33.     pso.MessageForAdding = "\nSelect solid " +
  34.         pkr.StringResult + ": ";
  35.     pso.SingleOnly = true;
  36.     pso.SinglePickInSpace = true;
  37.     pso.ForceSubSelections = true;

  38.     PromptSelectionResult psr = ed.GetSelection(pso);

  39.     if (psr.Status != PromptStatus.OK)
  40.         return;

  41.     SelectionSet ss = psr.Value;

  42.     SelectedObject so = ss[0];

  43.     if (!so.ObjectId.ObjectClass.IsDerivedFrom(
  44.         RXClass.GetClass(typeof(Solid3d))))
  45.     {
  46.         ed.WriteMessage(
  47.             "\nYou didn't select a solid, please try again...");
  48.         return;
  49.     }

  50.     using (Transaction Tx = db.TransactionManager.StartTransaction())
  51.     {
  52.         Solid3d solid = Tx.GetObject(so.ObjectId, OpenMode.ForRead)
  53.             as Solid3d;

  54.         SelectedSubObject[] sso = so.GetSubentities();

  55.         //Checks that selected type matches keyword selection
  56.         if (subentityType != sso[0].FullSubentityPath.SubentId.Type)
  57.         {
  58.             ed.WriteMessage("\nInvalid Subentity Type: " +
  59.                 sso[0].FullSubentityPath.SubentId.Type +
  60.                 ", please try again...");
  61.             return;
  62.         }

  63.         SubentityId subentityId = sso[0].FullSubentityPath.SubentId;

  64.         //Creates subentity path to use with GetSubentity
  65.         FullSubentityPath subEntityPath = new FullSubentityPath(
  66.             new ObjectId[] { solid.ObjectId },
  67.             subentityId);

  68.         //Returns a non-database resident entity
  69.         //that represents the subentity
  70.         using (Entity entity = solid.GetSubentity(subEntityPath))
  71.         {
  72.             ed.WriteMessage("\nSubentity Entity Type: "
  73.                 + entity.ToString());
  74.         }

  75.         //Creates entity path to generate Brep object from it
  76.         FullSubentityPath entityPath = new FullSubentityPath(
  77.             new ObjectId[] { solid.ObjectId },
  78.             new SubentityId(SubentityType.Null, IntPtr.Zero));

  79.         using (Brep brep = new Brep(entityPath))
  80.         {
  81.             switch (subentityType)
  82.             {
  83.                 case SubentityType.Face:

  84.                     foreach (
  85.                         Autodesk.AutoCAD.BoundaryRepresentation.Face
  86.                             face in brep.Faces)
  87.                     {
  88.                         if (subentityId ==
  89.                             face.SubentityPath.SubentId)
  90.                         {
  91.                             ed.WriteMessage("\nSurface: "
  92.                                 + face.Surface.ToString());

  93.                             break;
  94.                         }
  95.                     }
  96.                     break;

  97.                 case SubentityType.Edge:

  98.                     foreach (
  99.                         Autodesk.AutoCAD.BoundaryRepresentation.Edge
  100.                            edge
  101.                         in brep.Edges)
  102.                     {
  103.                         if (subentityId ==
  104.                             edge.SubentityPath.SubentId)
  105.                         {
  106.                             ed.WriteMessage("\nCurve: " +
  107.                                 edge.Curve.ToString());

  108.                             break;
  109.                         }
  110.                     }
  111.                     break;

  112.                 case SubentityType.Vertex:

  113.                     foreach (
  114.                        Autodesk.AutoCAD.BoundaryRepresentation.Vertex
  115.                            vertex
  116.                         in brep.Vertices)
  117.                     {
  118.                         if (subentityId ==
  119.                             vertex.SubentityPath.SubentId)
  120.                         {
  121.                             ed.WriteMessage("\nPoint: " +
  122.                                 PointToStr(vertex.Point));

  123.                             break;
  124.                         }
  125.                     }
  126.                     break;

  127.                 default:
  128.                     break;
  129.             }
  130.         }

  131.         Tx.Commit();
  132.     }
  133. }


游客,如果您要查看本帖隐藏内容请回复


论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!

已领礼包: 8727个

财富等级: 富甲天下

发表于 2016-9-11 10:38:25 | 显示全部楼层
回复查看本帖隐藏内容!!!!!
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 1个

财富等级: 恭喜发财

发表于 2017-7-1 07:02:46 | 显示全部楼层
看看,,,试了下,,出错的不知道怎么处理
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 26个

财富等级: 恭喜发财

发表于 2017-7-11 08:12:00 | 显示全部楼层
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复

使用道具 举报

发表于 2018-7-2 14:05:57 | 显示全部楼层
想看看能不能获取三角面
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2018-7-4 08:30:24 | 显示全部楼层
DDDDDDDDDDDDDDDDDDDDDD
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2019-6-8 20:34:14 | 显示全部楼层
1555544222
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2019-9-1 12:01:52 来自手机 | 显示全部楼层
感谢楼主分享!学习中!
来自: 微社区
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 58个

财富等级: 招财进宝

发表于 2019-10-22 18:39:03 来自手机 | 显示全部楼层
学习一下,感谢您分享!
来自: 微社区
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2019-11-1 09:13:30 | 显示全部楼层
楼主厉害,正好用来学习学习
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2020-2-21 11:19:34 | 显示全部楼层
学习了
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复

使用道具 举报

已领礼包: 19个

财富等级: 恭喜发财

发表于 2020-2-21 12:59:54 | 显示全部楼层
有没有VB.NET
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2020-2-21 17:46:35 | 显示全部楼层
学习!!!!!!!!!!!
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复

使用道具 举报

发表于 2021-7-14 11:09:24 | 显示全部楼层
回复查看本帖隐藏内容!!!!!
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-4-26 22:54 , Processed in 0.271253 second(s), 53 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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