2

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)

但我总是得到一个布尔回。我也想要家人。

4

1 回答 1

5

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

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)

这确实会返回一个 tuple (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()
于 2015-07-17T13:38:43.407 回答