I’m currently working on a python script that will batch load families . It works as is in IronPython ; however, when I switch to CPython I get a TypeError : interface takes exactly one argument line 58 (the famDoc.LoadFamily(doc,FamilyOption()) line). It appears to be related to the FamilyOption Class, but can’t seem to figure out how to fix it. Any thoughts?
class FamilyOption(IFamilyLoadOptions):
def OnFamilyFound(self, familyInUse, overwriteParameterValues):
overwriteParameterValues = True
return True
def OnSharedFamilyFound(self, sharedFamily, familyInUse, source, overwriteParameterValues):
overwriteParameterValues = True
return True
def ChangeCategory(doc, element, bic):
# Retrieve the family from the given element
family = element.Symbol.Family
TransactionManager.Instance.ForceCloseTransaction()
famDoc = doc.EditFamily(family)
ownerFamily = famDoc.OwnerFamily
# Change the category of the owner family to a new category, in this case, Windows
ownerFamily.FamilyCategory = Category.GetCategory(famDoc, bic)
# Define new subcategories to be added to the family
newSubCats = ["Glass", "Trim", "Frame/Mullion", "Sill/Head", "Panel"]
TransactionManager.Instance.EnsureInTransaction(famDoc)
subCats = ownerFamily.FamilyCategory.SubCategories
subCatDict = {}
for s in subCats:
subCatDict[s.Name] = s
for w in newSubCats:
# Add new subcategory if it does not already exist
if w not in subCatDict:
try:
newCat = famDoc.Settings.Categories.NewSubcategory(ownerFamily.FamilyCategory, w)
except: pass
TransactionManager.Instance.TransactionTaskDone()
# Start a new transaction in the main document to load the modified family
TransactionManager.Instance.EnsureInTransaction(doc)
famDoc.LoadFamily(doc, FamilyOption())
TransactionManager.Instance.TransactionTaskDone()
return ownerFamily
dunno.
I looked at it a bit, but I am hitting other issues related to the partial implementation of Cpython.
my advice, stay away of cpython engine in pyRevit for now. It needs some love.
This is a known limitation of CP3 being unable to support interfaces in the revit API. General advice on dynamo forums is to use ironpython or pythonnet engines.
Yes generally if using dynamo you’ll be limited to the builds autodesk chooses to update, which these days is only the latest one. If you need to span python in revit 2024 or prior ironpython is the only option in my experience, security risks and all. If you jump to c# this of course fixes these issues but requires more work/learning.