前言

Python 调用 Revit API,发现竟有某些属性死活拿不到。比如,选中一堵墙,得到 WallType,然后去读取它的 Name,发现竟然没有。

现象

确实是 WallType,但是找不到 Name 属性,但是却可以列出来。

确实是 WallType

Dynamo For Revit: Python 调用 Revit API 之某些不能直接拿到的 property

找不到属性

Dynamo For Revit: Python 调用 Revit API 之某些不能直接拿到的 property

所有属性

列出 wall.WallType 所有属性,有 Name
Dynamo For Revit: Python 调用 Revit API 之某些不能直接拿到的 property

原因与解决方案

原因是因为 IronPython 有这样的局限性。不过可以直接调用某个具体类的方法,这里是 Element.Name.GetValue(wallType):
Dynamo For Revit: Python 调用 Revit API 之某些不能直接拿到的 property
参考C#的反射机制 PropertyInfo.GetValue Method
对于不能调用的 Revit API 方法,我猜测用 MethodInfo.Invoke(Object, Object[]) Method 应该可以。
注: 解决方案来自 Dynamo Forum:Python - WallType - can’t get the walltype Name

相关文章:

  • 2021-07-01
  • 2021-08-16
  • 2021-07-21
  • 2021-09-27
  • 2021-08-17
  • 2022-01-13
  • 2022-01-13
  • 2021-04-14
猜你喜欢
  • 2021-09-17
  • 2021-05-30
  • 2021-10-06
  • 2021-04-25
  • 2021-10-11
  • 2021-12-28
  • 2021-06-26
相关资源
相似解决方案