EaBIM一直以来积极响应国家“十二五”推进建筑业信息化的号召,对建筑领域的信息技术开展深入技术交流和探讨!致力于打造“BIM-建筑师-生态技术”三位一体综合资源交流共享平台,希望为BIM与可持续设计理念及技术的普及做出微小的贡献!!!

EaBIM

 找回密码
 注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

搜索
查看: 573|回复: 3
打印 上一主题 下一主题

[在线求助] revit二次开发

[复制链接]

4

主题

9

帖子

39

积分

BIM书童

Rank: 1

积分
39

社区QQ达人

跳转到指定楼层
楼主
发表于 2015-7-4 15:16:14 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 Aaronyee 于 2015-11-2 19:13 编辑

求助,我在revit用外部工具运行出现问题,这是我的代码
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using WinForms = System.Windows.Forms;
  5. using Autodesk.Revit;
  6. using Autodesk.Revit.DB;
  7. using Autodesk.Revit.UI;
  8. using Autodesk.Revit.ApplicationServices;
  9. using Autodesk.Revit.Attributes;
  10. namespace chengtai
  11. {
  12. [Transaction(TransactionMode.Manual)]
  13. [Regeneration(RegenerationOption.Manual)]
  14. class chengtai:IExternalCommand
  15. {
  16. UIApplication rvtApp;
  17. Document rvtDoc;
  18. public Result Execute(ExternalCommandData commandData, ref string message, ElementSet element)
  19. {
  20. rvtApp = commandData.Application ;
  21. rvtDoc = commandData.Application.ActiveUIDocument.Document;
  22. //核实
  23. if (!isRightTemplate(BuiltInCategory.OST_StructuralFoundation))
  24. {
  25. TaskDialog .Show ("Family API","Please open foundation.rft");
  26. return Result.Failed ;
  27. }
  28. //(1.1)新建参考面
  29. addReferencePlanes();
  30. //(1.2)创建拉伸体
  31. Extrusion psolid = createSolid();
  32. return Result.Succeeded ;
  33. }
  34. bool isRightTemplate(BuiltInCategory targetCategory)
  35. {
  36. if (!rvtDoc .IsFamilyDocument )
  37. {
  38. TaskDialog .Show ("Family API","This command works only in the family editor.");
  39. return false ;
  40. }
  41. Family ownerFamily = rvtDoc .OwnerFamily ;
  42. if (ownerFamily == null )
  43. {
  44. TaskDialog .Show ("Family API","This document does not have Owner Family.");
  45. return false ;
  46. }
  47. Category cat = rvtDoc .Settings .Categories .get_Item (BuiltInCategory.OST_StructuralFoundation);
  48. if (!cat .Id .Equals (ownerFamily .FamilyCategory .Id ))
  49. {
  50. TaskDialog .Show ("Family API","The category of this document does not match the context of this command. Please open foundation.rft");
  51. return false ;
  52. }
  53. return true ;
  54. }
  55. void addReferencePlanes()
  56. {
  57. //add horizonal ref plane
  58. ReferencePlane refFront = findElement(typeof(ReferencePlane), "Front") as ReferencePlane;
  59. XYZ p1 = refFront.BubbleEnd;
  60. XYZ p2 = refFront.FreeEnd;
  61. XYZ pBubbleEnd = new XYZ(p1.X, p1.Y + mmToFeet(1900.0), p1.Z);
  62. XYZ pFreeEnd = new XYZ(p1.X, p1.Y + mmToFeet(1900.0), p1.Z);
  63. XYZ vec = XYZ.BasisZ;
  64. View pViewPlan = findElement(typeof(ViewPlan), "Lower Ref. Level") as View;
  65. ReferencePlane refPlane = rvtDoc.FamilyCreate.NewReferencePlane(pBubbleEnd, pFreeEnd, vec, pViewPlan);
  66. refPlane.Name = "OffsetBack";
  67. pBubbleEnd = new XYZ(p1.X, p1.Y - mmToFeet(1900.0), p1.Z);
  68. pFreeEnd = new XYZ(p1.X, p1.Y - mmToFeet(1900.0), p1.Z);
  69. refPlane = rvtDoc.FamilyCreate.NewReferencePlane(pBubbleEnd, pFreeEnd, vec, pViewPlan);
  70. refPlane.Name = "OffsetFront";
  71. //add vertical ref plane
  72. ReferencePlane refLeft = findElement(typeof(ReferencePlane), "Left") as ReferencePlane;
  73. p1 = refLeft.BubbleEnd;
  74. p2 = refLeft.FreeEnd;
  75. pBubbleEnd = new XYZ(p1.X + mmToFeet (1900.0), p1.Y, p1.Z);
  76. pFreeEnd = new XYZ(p1.X + mmToFeet(1900.0), p1.Y, p1.Z);
  77. refPlane = rvtDoc.FamilyCreate.NewReferencePlane(pBubbleEnd, pFreeEnd, vec, pViewPlan);
  78. refPlane.Name = "OffsetRight";
  79. pBubbleEnd = new XYZ(p1.X - mmToFeet(1900.0), p1.Y, p1.Z);
  80. pFreeEnd = new XYZ(p1.X - mmToFeet(1900.0), p1.Y, p1.Z);
  81. refPlane = rvtDoc.FamilyCreate.NewReferencePlane(pBubbleEnd, pFreeEnd, vec, pViewPlan);
  82. refPlane.Name = "OffsetLeft";
  83. }
  84. Extrusion createSolid()
  85. {
  86. //1. define a profile
  87. CurveArrArray pProfile = createProfile();
  88. //2. create a sketch plane
  89. ReferencePlane pRefPlane = findElement(typeof(ReferencePlane), "ReferencePlane") as ReferencePlane;
  90. SketchPlane pSketchPlane = rvtDoc.FamilyCreate.NewSketchPlane(pRefPlane.Plane);
  91. //3. height of the extrution
  92. double dHeight = mmToFeet(900.0);
  93. //4. create an extrusion here.at this point,just an box,nothing else.
  94. bool bIsSolid = true;
  95. return rvtDoc.FamilyCreate.NewExtrusion(bIsSolid, pProfile, pSketchPlane, dHeight);
  96. }
  97. CurveArrArray createProfile()
  98. {
  99. double w = mmToFeet(3800.0);
  100. double d = mmToFeet(3800.0);
  101. const int nVerts = 4;
  102. XYZ[] pts = new XYZ[] {
  103. new XYZ (-w /2.0, -d /2.0, 0.0),
  104. new XYZ (w /2.0, -d /2.0, 0.0),
  105. new XYZ (w /2.0, d /2.0, 0.0),
  106. new XYZ (-w /2.0, d /2.0, 0.0),
  107. new XYZ (-w /2.0, -d /2.0, 0.0)};
  108. //define a loop
  109. CurveArray pLoop = rvtApp.Application.Create.NewCurveArray();
  110. for (int i = 0; i < nVerts; ++i)
  111. {
  112. Line line = rvtApp.Application.Create.NewLineBound(pts[i], pts[i + 1]);
  113. pLoop.Append(line);
  114. }
  115. //put the loop in the curveArrArray as a profile
  116. CurveArrArray pProfile = rvtApp.Application.Create.NewCurveArrArray();
  117. pProfile.Append(pLoop);
  118. return pProfile;
  119. }
  120. //helper function: find an element of the given type and the name.
  121. Element findElement(Type targetType, string targetName)
  122. {
  123. FilteredElementCollector collector = new FilteredElementCollector(rvtDoc);
  124. collector.WherePasses(new ElementClassFilter(targetType));
  125. var targetElems = from element in collector where element.Name.Equals(targetName) select element;
  126. List<Element> elems = targetElems.ToList<Element>();
  127. if (elems.Count > 0)
  128. {
  129. return elems[0];
  130. }
  131. return null;
  132. }
  133. //helper function: convert millimeter to feet
  134. double mmToFeet(double mmVal)
  135. {
  136. return mmVal / 304.8;
  137. }
  138. }
  139. }
复制代码
本站强荐:185娱乐⺁城.足球⺁真_人.彩票齐全⺁手机可投⺁注任何游戏. 首次开户送10元.首存送58元.信誉绝对保证185.cc
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
收藏收藏 转播转播 分享分享 分享淘帖 支持支持 反对反对

9

主题

3162

帖子

5444

积分

BIM专家

Rank: 8Rank: 8Rank: 8Rank: 8Rank: 8Rank: 8Rank: 8Rank: 8

积分
5444

社区QQ达人

2F
发表于 2015-7-5 09:57:19 | 只看该作者
本帖最后由 Aaronyee 于 2015-11-2 19:13 编辑

看不懂! 本站强荐:185娱乐η城.足球η真_人.彩票齐全η手机可投η注任何游戏. 首次开户送10元.首存送58元.信誉绝对保证185.cc

0

主题

358

帖子

1147

积分

BIM项目负责人

Rank: 5Rank: 5Rank: 5Rank: 5Rank: 5

积分
1147

社区QQ达人

3F
发表于 2015-7-5 10:24:55 | 只看该作者
本帖最后由 Aaronyee 于 2015-11-2 19:13 编辑

你很厉害啊 威尼斯人:wns185.com首存赠送58元び足球び真_人び各类彩票齐全び提现即时到账

4

主题

9

帖子

39

积分

BIM书童

Rank: 1

积分
39

社区QQ达人

4F
 楼主| 发表于 2015-7-5 11:24:19 | 只看该作者
本帖最后由 Aaronyee 于 2015-11-2 19:13 编辑

你很厉害啊[/quote] 我也是在边看别人写的边学,谈不上厉害,还是初步学习阶段 皇_冠现_金网:hg88094.com首存送58元.手机可投C注任何游戏满1000送1088彩_金C体育半场结算六_合48倍C各种彩票游戏
*滑块验证:
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|EaBIM网 ( 苏ICP备2020058923号-1  苏公网安备32011502011255号

GMT+8, 2024-11-24 04:49

Powered by Discuz! X3.2 Licensed

© 2001-2013 Comsenz Inc.

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