【问题标题】:How do I obtain room seperators in revit 2017如何在 revit 2017 中获取房间分隔符
【发布时间】:2016-11-09 17:53:20
【问题描述】:

我正在开发一个应用程序,该应用程序需要知道哪个房间的边界是哪个房间的边界。在这种情况下,了解房间边界是墙壁还是房间分隔符是相关的。

 public FindsRoomSeperators(){
        SpatialElementBoundaryOptions options = new SpatialElementBoundaryOptions();
        options.SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.Finish;

        foreach (IList<Autodesk.Revit.DB.BoundarySegment> boundSegList in room.GetBoundarySegments(options))
                {
                    foreach (Autodesk.Revit.DB.BoundarySegment boundSeg in boundSegList)
                            if ((BuiltInCategory)el.Category.Id.IntegerValue == BuiltInCategory.OST_RoomSeparationLines)
                                 //proccess el
                 }
   }

但是,从 revit 2017 开始,此代码现在会抛出找不到方法:“Autodesk.Revit.DB.Element Autodesk.Revit.DB.BoundarySegment.get_Element()”。提示此方法已被删除的异常。

      var geometry = (Solid)room.get_Geometry(new Options()).First();
      var faces = geometry.Faces;

虽然这确实让我能够判断诸如地板是否以一定角度站立之类的东西,但它并不能告诉我哪些边缘来自墙壁,哪些来自房间分隔器。

理想情况下,我可以获取我们拥有的面孔并检查面孔的任何边缘是否是房间分隔符。如果有帮助,我已经列出了所有墙壁。

那么如何在 revit 2017 中做到这一点?最好不要破坏与 2015 的兼容性。

【问题讨论】:

  • GetBoundarySegments() 没有在 2017 年从 API 中删除,它仍然存在(甚至没有标记为“已弃用”)。你没有错过参考吗?
  • 该代码在 2017 年调用时会在 foreach 循环中引发异常,但在 2016 年可以正常工作。上述方法抛出异常: Method not found: 'Autodesk.Revit.DB.Element Autodesk.Revit.DB.BoundarySegment.get_Element()'。

标签: c# revit-api revit


【解决方案1】:

这在 Revit 平台 API 更改和添加文件 (see SDK) 中是预期和记录的,此方法在 2016 年被标记为已弃用,并于 2017 年被删除。

您应该使用 ElementIdLinkElementId(请参阅文档)。

foreach (Autodesk.Revit.DB.BoundarySegment boundSeg in boundSegList)
{
  Element el = doc.GetElement(boundSeg.ElementId); // or doc.GetElement(boundSeg.LinkElementId);
  if ((BuiltInCategory)el.Category.Id.IntegerValue == BuiltInCategory.OST_RoomSeparationLines)
  {

  }
}

【讨论】:

  • 会不会是 revit 2015 中不存在 boundSeg.ElementId?它给了我一个错误:边界段不包含“ElementID”的定义。
  • 是的,BoundarySegment.ElementId 属性是在 2016 年引入的(根据文档)
  • 你知道一种方法可以让我同时使用这两种方法吗?我需要与 2015 年和 2017 年竞争。
  • 您可以使用 Dynamic,请参阅我的第一个建议(和改进版本)stackoverflow.com/a/33401274/4838205
【解决方案2】:

Augusto 上面提到的 Revit Platform API Changes and Additions 文档也可以在线获取:

http://thebuildingcoder.typepad.com/blog/2016/04/whats-new-in-the-revit-2017-api.html

只需搜索 BoundarySegment。您缺少的 get_Element 方法实际上是 Element 属性的包装器,该属性已在 Revit 2017 中删除。

The Building Coder 在

提供了一个示例,该示例演示了使用 .NET Reflection 库来支持不同版本 Revit 中的不同功能

http://thebuildingcoder.typepad.com/blog/2012/07/multi-version-add-in.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-24
    • 2021-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多