Message 1 of 10
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Good morning all,
I have a library I need to go through fixing some issues with:
- A missing shared parameter inside nested families;
- The same missing shared parameter in the host families;
- The same shared parameter inside nested families not associated to their host's counterpart.
I managed to create all the checks to identify each case but for some reason when I attempt to edit one of the nested families to add the shared parameter I get the exception below.
Autodesk.Revit.Exceptions.ArgumentException: The shared parameter 'Condition' is already in use.
I managed to add the parameter to the host family but I get that error when I edit one of the nested families and try to add the parameter. I've been stuck on that for a while and any help would be very much appreciated. Below is some of the code (in Python) I'm using.
# Get shared parameter definition
requiredDefinition = []
spFile = app.OpenSharedParameterFile()
dGroups = spFile.Groups
for dg in dGroups:
if dg.Name == '00_Families_Constraints':
for d in dg.Definitions: # There's only one in the group
requiredDefinition.Add(d)
# Check if the host has the Condition parameter
familyManager = doc.FamilyManager
famPar = familyManager.Parameters
hostCondPar = [par for par in famPar if par.Definition.Name == 'Condition']
t1 = Transaction(doc, 'Add Condition parameter')
t1.Start()
if hostCondPar == []:
for d in requiredDefinition:
newCondPar = familyManager.AddParameter(d,BuiltInParameterGroup.PG_CONSTRAINTS,True)
print('Condition added to host.')
else:
print('Host already has Condition.')
pass
t1.Commit()
# Collect all placed instances of nested families
famInstanceCollector = FilteredElementCollector(doc).OfClass(FamilyInstance).ToElements()
famList = list(famInstanceCollector)
# Go through all placed instances of nested families
for famInst in famList:
fam = famInst.Symbol.Family
# edit family to collect its Shared status
if fam.IsEditable == True and famInst.ArePhasesModifiable() == True:
famdoc = doc.EditFamily(fam)
thisFamily = famdoc.OwnerFamily
nestFamManager = famdoc.FamilyManager
sharedPar = thisFamily.get_Parameter(BuiltInParameter.FAMILY_SHARED)
sharedValue = sharedPar.AsInteger()
# if shared, check the Condition parameter is present
if sharedValue == 1 and famInst.Symbol.FamilyName != None:
nestCondPar = famInst.LookupParameter('Condition')
# if present and linked, pass
if nestCondPar != None and nestCondPar.IsReadOnly == True:
pass
# if not present, add it
elif nestCondPar == None:
t2 = Transaction(famdoc, 'Add Condition parameter')
t2.Start()
for d in requiredDefinition:
# THIS IS WHERE THE ERROR HAPPENS
newCondPar = nestFamManager.AddParameter(d,BuiltInParameterGroup.PG_CONSTRAINTS,True)
t2.Commit()
# if present but not linked, link it
elif nestCondPar != None and nestCondPar.IsReadOnly != True:
# Add linking code here
Solved! Go to Solution.