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)
但我总是得到一个布尔回来。我也想要家人。
答案 0 :(得分:3)
你可以像这样找到你想要的超载:
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()