gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 22:42:43 25 4
gpt4 key购买 nike

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com