GlobalParameter SetValue in Python

Hi,

I am trying to set a global parameter value using python but it doesn’t work. While I am able to GetValue() or GetType I still cant assign new value.

import clr
# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import ReferencePointArray
# Import DocumentManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager

# Import ToDSType(bool) extension method
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)

doc= DocumentManager.Instance.CurrentDBDocument

dataEnteringNode = IN

#Assign your output to the OUT variable.
j = IN[0]
h = UnwrapElement(j)
D = h.GetValue().Value
m = h.GetType()
q= h.GetOrderedParameters()

h.SetValue(10.0)


OUT = D

1 Like

Looks like your parameters types might not match. What kind of value is it expecting? What do you get back with GetValue?

To set the parameter value you need to construct a ParameterValue as seen in the API docs for the SetValue() method

Here is the constructor for a DoubleParameterValue and you can determine what ParameterValue class you need to construct by using .GetType() after .GetValue()

Additionally, you’ll need to start and close a transaction to change the parameter value.

Something like this should work:

TransactionManager.Instance.EnsureInTransaction(doc)

hValue = Autodesk.Revit.DB.DoubleParameterValue(10.0)
h.SetValue(hValue)
newVal = h.GetValue().Value

TransactionManager.Instance.TransactionTaskDone()

OUT = newVal

Make sure to import the transaction manager as well

3 Likes