Hello Dynamo Friends
I want to manipulate shared parameters with python.
My goal is to create them and add them to a family while in the model, not in the family editor.
As i have never done something like this before i started by trying to edit a type parameter of a family while in the model, with success:
class FamilyOption(IFamilyLoadOptions):
def OnFamilyFound(self,familyInUse,overwriteParameterValues):
overwriteParameterValues = True
return True
def OnSharedFamilyFound(self, sharedFamily, familyInUse, FamilySource, overwriteParameterValues):
overwriteParameterValues = True
return True
doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
#Preparing input from dynamo to revit
familySymbol = UnwrapElement(IN[0])
family = familySymbol.Family
status = []
outcome=[]
#Do some action in a Transaction
TransactionManager.Instance.EnsureInTransaction(doc)
#for symbId in family.GetFamilySymbolIds():
#symbol = doc.GetElement(symbId)
if not familySymbol.IsActive:
familySymbol.Activate()
TransactionManager.Instance.TransactionTaskDone()
TransactionManager.Instance.ForceCloseTransaction()
if IN[4]:
try:
famDoc= doc.EditFamily(family)
params = famDoc.FamilyManager.Parameters
types = famDoc.FamilyManager.Types
trans = Transaction(famDoc)
trans.Start("test")
for type in types:
if type.Name == IN[1]:
famDoc.FamilyManager.CurrentType = type
for param in params:
if param.Definition.Name == IN[2]:
famDoc.FamilyManager.Set(param,IN[3])
trans.Commit()
famDoc.LoadFamily(doc,FamilyOption())
famDoc.Close(False)
status.append("Success")
except:
status.append("Failed")
OUT = status
Thanks to @SeanP for that code.
As it worked out to edit the type parameter of a family while in the model i tried my luck on adding a shared Parameter. But i get the error âFamilyManager can only be used in the Family Editor.â
class FamilyOption(IFamilyLoadOptions):
def OnFamilyFound(self,familyInUse,overwriteParameterValues):
overwriteParameterValues = True
return True
def OnSharedFamilyFound(self, sharedFamily, familyInUse, FamilySource, overwriteParameterValues):
overwriteParameterValues = True
return True
doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
#Preparing input from dynamo to revit
familySymbol = UnwrapElement(IN[0])
family = familySymbol.Family
status = []
outcome=[]
definitions = UnwrapElement(IN[6])
bipgs = UnwrapElement(IN[5])
isInstance = True
#Do some action in a Transaction
TransactionManager.Instance.EnsureInTransaction(doc)
#for symbId in family.GetFamilySymbolIds():
#symbol = doc.GetElement(symbId)
if not familySymbol.IsActive:
familySymbol.Activate()
TransactionManager.Instance.TransactionTaskDone()
TransactionManager.Instance.ForceCloseTransaction()
famDoc= doc.EditFamily(family)
params = famDoc.FamilyManager.Parameters
types = famDoc.FamilyManager.Types
trans = Transaction(famDoc)
trans.Start("test")
new = doc.FamilyManager.AddParameter(definitions,bipgs,isInstance)
outcome.append(new)
trans.Commit()
famDoc.LoadFamily(doc,FamilyOption())
famDoc.Close(False)
status.append("Success")
OUT = status
So why can i set the parameter but can´t add one? Do I have to open the family in the background before i can add a parameter? Isn´t EditFamily() already opening the family?
Creating a shared parameter will be the next task. Does the parameter have to exist in the sharedparameter.txt file before, or can i create and add it only in the model?
Kind regards