python - 如何在 revitpythonshell 中选择正确的 LoadFamily 函数

标签 python overloading revit revit-api revitpythonshell

revitpythonshell 提供了两种非常相似的加载族的方法。

LoadFamily(self: Document, filename:str) -> (bool, Family)
LoadFamily(self: Document, filename:str) -> bool

所以好像只有返回值不同。我尝试过以几种不同的方式调用它:

(success, newFamily) = doc.LoadFamily(path)
success, newFamily = doc.LoadFamily(path)
o = doc.LoadFamily(path)

但我总是得到一个 bool 值。我也想要家庭。

最佳答案

你可以像这样找到你正在寻找的过载:

import clr
family = clr.Reference[Family]()
# family is now an Object reference (not set to an instance of an object!)
success = doc.LoadFamily(path, family)  # explicitly choose the overload
# family is now a Revit Family object and can be used as you wish

这通过创建一个对象引用来传递给函数和方法重载结果来实现,现在知道要查找哪个。

假设 RPS 帮助中显示的重载列表与它们出现的顺序相同 - 我认为这是一个非常安全的假设,您也可以这样做:

success, family = doc.LoadFamily.Overloads.Functions[0](path)

这确实会返回一个元组 (bool, Autodesk.Revit.DB.Family)

请注意,这必须在交易中发生,所以一个完整的例子可能是:

t = Transaction(doc, 'loadfamily')
t.Start()
try:
    success, family = doc.LoadFamily.Overloads.Functions[0](path)
    # do stuff with the family
    t.Commit()
except:
    t.Rollback()

关于python - 如何在 revitpythonshell 中选择正确的 LoadFamily 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31471089/

相关文章:

如果将大小大于 1995 的数组传递给数组 a,Python 程序将停止工作

模板参数上的 C++ 函数模板重载

java - 这个方法在java中重载了吗?

c# - 获取 Schedule 和 Material Takeoff 的所有参数

python - Revit Python 拾取对象/选择对象

c# - 令人困惑的 API 限制

python - Python 中的二维数值积分

python - 在 Python 中搜索值时出错

python - 从漂亮的汤创建 html 文件的问题

c++ - 编译错误 : ambiguous overload for 'operator='