Does anyone has the experience to use LoadFamily(Document, IFamilyLoadOptions) in a python node to load a family back in to the project.
everytime i try to do this its telling me: “The document must not be modifiable before calling LoadFamily. Any open transactions must be closed.prior to the call.”
# Enable Python support and load DesignScript library
import clr
clr.AddReference('ProtoGeometry')
clr.AddReference('RevitAPI')
clr.AddReference("RevitServices")
from Autodesk.DesignScript.Geometry import *
from Autodesk.Revit.DB import *
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
#// method for unwrapping dynamo elements to revitones // UnwrapElement()
# The inputs to this node will be stored as a list in the IN variables.
fams = UnwrapElement(IN[0])
# classes
class famloadopt(IFamilyLoadOptions):
def OnFamilyLoad(familyInUse, overwriteParameterValues):
overwriteParameterValues = True
return True
def OnSharedFamilyFound(sharedFamily, familyInUse, source, overwriteParameterValues):
overwriteParameterValues = True
return True
# Place your code below this line
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
if doc.IsModifiable == True:
output = "document is modifiable"
else:
output = "document is not modifiable"
famdoc = doc.EditFamily(fams[0])
TransactionManager.Instance.EnsureInTransaction(famdoc)
famman = famdoc.FamilyManager
famman.AddParameter("TESTPARAMETER2", BuiltInParameterGroup.PG_IDENTITY_DATA, ParameterType.Text, False)
TransactionManager.Instance.ForceCloseTransaction()
if famdoc.IsModifiable == True:
output = "familydocument is modifiable"
elif doc.IsModifiable == True:
output = "document is modifiable while loading"
elif doc.IsReadOnly == True:
output = "document is readonly while loading"
else:
TransactionManager.Instance.EnsureInTransaction(doc)
try:
famdoc.LoadFamily(doc, famloadopt())
except Exception, e:
output = e
TransactionManager.Instance.TransactionTaskDone()
# Assign your output to the OUT variable.
OUT = output
I have seen solutions that foreclose transactions before loading families. You actually do foreclose transactions but you open new transactions just before laoding the family. I think removing those lines near the end that have EnsureInTransaction and TransactionTaskDone should fix this.
# Enable Python support and load DesignScript library
import clr
clr.AddReference('ProtoGeometry')
clr.AddReference('RevitAPI')
clr.AddReference("RevitServices")
from Autodesk.DesignScript.Geometry import *
from Autodesk.Revit.DB import *
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
#// method for unwrapping dynamo elements to revitones // UnwrapElement()
# The inputs to this node will be stored as a list in the IN variables.
fams = UnwrapElement(IN[0])
# classes
class famloadopt(IFamilyLoadOptions):
def OnFamilyLoad(familyInUse, overwriteParameterValues):
overwriteParameterValues = True
return True
def OnSharedFamilyFound(sharedFamily, familyInUse, source, overwriteParameterValues):
overwriteParameterValues = True
return True
# Place your code below this line
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
if doc.IsModifiable == True:
output = "document is modifiable"
else:
output = "document is not modifiable"
famdoc = doc.EditFamily(fams[0])
TransactionManager.Instance.EnsureInTransaction(famdoc)
famman = famdoc.FamilyManager
famman.AddParameter("TESTPARAMETER2", BuiltInParameterGroup.PG_IDENTITY_DATA, ParameterType.Text, False)
TransactionManager.Instance.ForceCloseTransaction()
if famdoc.IsModifiable == True:
output = "familydocument is modifiable"
elif doc.IsModifiable == True:
output = "document is modifiable while loading"
elif doc.IsReadOnly == True:
output = "document is readonly while loading"
else:
try:
famdoc.LoadFamily(doc, famloadopt())
except Exception, e:
output = e
# Assign your output to the OUT variable.
OUT = output
import clr
clr.AddReference('ProtoGeometry')
clr.AddReference('RevitAPI')
clr.AddReference("RevitServices")
from Autodesk.DesignScript.Geometry import *
from Autodesk.Revit.DB import *
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
# Place your code below this line
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
#// method for unwrapping dynamo elements to revitones // UnwrapElement()
# The inputs to this node will be stored as a list in the IN variables.
fams = UnwrapElement(IN[0])
class FamilyOption(IFamilyLoadOptions):
def OnFamilyFound(self, familyInUse, overwriteParameterValues):
overwriteParameterValues = True
return True
def OnSharedFamilyFound(self, sharedFamily, familyInUse, source, overwriteParameterValues):
return True
try:
result=[]
for i in fams:
family = UnwrapElement(i)
TransactionManager.Instance.ForceCloseTransaction()
famDoc = doc.EditFamily(family)
if famDoc != None:
famman = famDoc.FamilyManager
TransactionManager.Instance.EnsureInTransaction(famDoc)
famman.AddParameter("TESTPARAMETER2", BuiltInParameterGroup.PG_IDENTITY_DATA, ParameterType.Text, False)
TransactionManager.Instance.TransactionTaskDone()
result.append(famDoc.LoadFamily(doc, FamilyOption()))
except Exception, ex:
result.append(ex.message)
# Assign your output to the OUT variable.
OUT = result
now i just got to figure out what you did differently from what i did. i guess it has to do with whenever you forceclose/ensure/taskdone transactions right?
You where having unnecessary items like doc.Ismodifiable, By default all families are modifiable. And also i am closing transaction before editing family, this will ensure that no Transaction is open. Minimize as much as possible. Does that makes sense?