【问题标题】:Getting name of element type doesn't work in Iron python for Revit获取元素类型的名称在 Iron python for Revit 中不起作用
【发布时间】:2021-03-18 12:34:06
【问题描述】:

我在pyRevit环境中使用Iron python,我的代码如下:

element_types = \
        DB.FilteredElementCollector(doc)\
          .OfCategory(DB.BuiltInCategory.OST_Walls)\
          .WhereElementIsElementType()\ # getting family types not elements
          .ToElements()

for ele in element_types:
    print(ele.Name)

根据 Revit API 文档,这应该可以工作并且可能在 C# 中工作。 ele.Name 既可以用作 setter,也可以用作 getter。 但是在 Ironpython 上面的代码失败,返回一个AttributeError: Name。但是当我尝试ele.Name = "new_family_type_name" 时,它工作正常。

所以我的问题是如何使ele.Name 工作以获取家庭类型名称。

【问题讨论】:

  • 是的,有一个错误。试试DB.Element.Name.GetValue(ele)
  • 它返回AttributeError: 'getset_descriptor' object has no attribute 'GetValue'。 :(

标签: python ironpython revit-api revitpythonshell pyrevit


【解决方案1】:

这通常是您在使用 RPS 时遇到的最早的怪癖之一 - 但不用担心,它很容易解决。试试:

for ele in element_Types:
     print Element.Name.__get__(ele)

【讨论】:

  • 我一直在寻找这个。谢谢
【解决方案2】:

请试试这个代码

from rpw import db

collector = db.Collector(of_class='WallType')
element_types = collector.get_elements()    

for ele in element_types:
    print(ele.name)  

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-06-18
    • 1970-01-01
    • 1970-01-01
    • 2018-12-06
    • 2012-01-05
    • 1970-01-01
    • 1970-01-01
    • 2021-09-20
    相关资源
    最近更新 更多