# Set Parameter to Vary by Group Instance

**URL:** <https://forum.dynamobim.com/t/set-parameter-to-vary-by-group-instance/79882>\
**Category:** Revit\
**Created:** [August 15, 2022, 10:26am UTC](https://forum.dynamobim.com/t/set-parameter-to-vary-by-group-instance/79882 "2022-08-15T10:26:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mark.Ackerley](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/mark.ackerley/32/79310_2.png) [@Mark.Ackerley](https://forum.dynamobim.com/u/Mark.Ackerley)\
**Post date:** [August 15, 2022, 10:26am UTC](https://forum.dynamobim.com/t/set-parameter-to-vary-by-group-instance/79882/1 "2022-08-15T10:26:07Z")

</div>

Might be useful to people…

This is limited by the types of parameter which are allowed to vary by group instance, this does not include Yes/No or Length.

Thanks to @jeremytammik and anyone else who has done work in this area.

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/c/7/c78938f706e68ef7ff38c0316f80c95cd5e7a9e0.png)  
.  
Mark

```auto
import clr

import System
from System import *

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
from System.Collections.Generic import *

clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *

doc = DocumentManager.Instance.CurrentDBDocument

# The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN
keyWord = IN[0]

def isInstance(definition_Name):
	#for some reason, returning the name of the Key in the bindings iterator
	#fails sometimes and says item can't be managed? so then restart Revit
	
	#the list of parameters in doc.ParameterBindings is only the ones which are
	#added in the Project Parameters box, so you're not getting ones which
	#just exist in families
	
	#this is the only way to see if a parameter is 'bound' to the doc as
	#a type or an instance parameter
	
	bindings = doc.ParameterBindings
	it = doc.ParameterBindings.ForwardIterator()
	defs = []
	value = False
	while(it.MoveNext()):
		d = it.Key
		b = it.Current
		if d.Name == definition_Name and b.GetType() == InstanceBinding:
			value = True
			break
	return value	

def canBeEditableInGroup(parameter):
    parameter_Type = parameter.ParameterType
    
    variable_Parameter_Types_List = [ParameterType.Text, 
                                     ParameterType.Area, 
                                     ParameterType.Volume, 
                                     ParameterType.Currency, 
                                     ParameterType.MassDensity, 
                                     ParameterType.URL, 
                                     ParameterType.Material]
    
    if parameter_Type in variable_Parameter_Types_List:
        return True
    else:
        return False
        
# Place your code below this line
output = []
#catch anything that doesn't work and output the error
sPs = FilteredElementCollector(doc).OfClass(SharedParameterElement)

try:
    sPs = FilteredElementCollector(doc).OfClass(SharedParameterElement)
    errorReport = None 

    #begin transaction
    TransactionManager.Instance.EnsureInTransaction(doc)
    for sP in sPs:
        #we are interested in the shared parameter 'definition'
        #the 'definition' is a container of the shared parameter
        #that holds the information about whether
        #the parameter is variable by instance in a group
        
        #we only want the shared parameters with our key word
        #we only want them if they are a type which can vary
        #we only want them if they are not already true
        #we only want them if they are instance parameters
        
        definition = sP.GetDefinition()  

        varies_Query = definition.VariesAcrossGroups
        

        if keyWord in definition.Name and canBeEditableInGroup(definition) and isInstance(definition.Name) and varies_Query != True:
            try:
                definition.SetAllowVaryBetweenGroups(doc, True)
                output.append("Success: " + definition.Name + " can now vary across group instances")
            except:
                import traceback
                errorReport_SP = traceback.format_exc()
                exception = ' does not support the specified value of allowVaryBetweenGroups'              
                if exception in errorReport_SP:
                    output.append("Failure: " + definition.Name + "cannot be set to vary between groups")
                else:
                    output.append([definition.Name, errorReport_SP])
    #finish transaction
    TransactionManager.Instance.TransactionTaskDone()

#Assign your output to the OUT variable.
except:
    import traceback
    errorReport = traceback.format_exc()

if errorReport == None:
    OUT = output

else:
    OUT = errorReport

OUT = output

```

---

<div class="post-metadata">

**Author:** ![rrvivancosWTL](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/rrvivancoswtl/32/185795_2.png) [@rrvivancosWTL](https://forum.dynamobim.com/u/rrvivancosWTL)\
**Post date:** [March 27, 2025, 3:14pm UTC](https://forum.dynamobim.com/t/set-parameter-to-vary-by-group-instance/79882/2 "2025-03-27T15:14:54Z")

</div>

sorry does not work, says Empty List the result, I tried in Revit 2023 with ironpython 2.7 and cpython3 engine too, it worked like this:

```auto
import clr
import traceback

clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *

# Get current Revit document
doc = DocumentManager.Instance.CurrentDBDocument

# Get filter keyword from Dynamo input (e.g., "Planification_")
keyword = IN[0]

# Returns True if a shared parameter with this name is instance-bound
def isInstanceBound(definition_name):
    bindings = doc.ParameterBindings
    it = bindings.ForwardIterator()
    while it.MoveNext():
        if it.Key.Name == definition_name and isinstance(it.Current, InstanceBinding):
            return True
    return False

output = []

try:
    TransactionManager.Instance.EnsureInTransaction(doc)
    
    # Get all SharedParameterElement definitions in the document
    shared_params = FilteredElementCollector(doc).OfClass(SharedParameterElement)

    for sp in shared_params:
        try:
            definition = sp.GetDefinition()
            name = definition.Name
            if keyword in name:
                output.append("Processing: {}".format(name))
                if isInstanceBound(name):
                    # Attempt to force vary-by-group setting
                    definition.SetAllowVaryBetweenGroups(doc, True)
                    output.append("✅ Set 'vary by group instance' = True for '{}'".format(name))
                else:
                    output.append("⚠️ Skipped: '{}' is not instance-bound.".format(name))
        except Exception as innerEx:
            output.append("❌ Error processing '{}': {}".format(name, traceback.format_exc()))
    
    TransactionManager.Instance.TransactionTaskDone()

except Exception as outerEx:
    TransactionManager.Instance.ForceCloseTransaction()
    output.append("❌ Transaction failed: {}".format(traceback.format_exc()))

# Return log output to Dynamo
OUT = output

```
