Set a formula to a Global parameter

Hey !

I am trying to set the formulas of multiple Global parameters with Dynamo for a project and, so far, I have found no nodes or packages that helps me do this.

The only clue i have is through the API with the “GlobalParameter.SetFormula()” method but I have next to no clue on how to use it and google is not really helping.

I tried putting it in a code block but the best i can return is this error message :
“Warning: Cannot find static method or constructor Revit.Elements.GlobalParameter.GetFormula()”

Would someone help me with this or guide me towards any clue or answers ?

Thanks a lot !

bump.

Anyone ?

# by Alexander Berg | 2019-12-09 | Automated Design Solutions

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

clr.AddReference("RevitNodes")
import Revit

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

doc = DocumentManager.Instance.CurrentDBDocument

def toList(e):
	if not isinstance(e, list):
		return [e]
	else:
		return e
def un(e):
	return UnwrapElement(e)

gloPar = un(toList(IN[0]))
expres = toList(IN[1])

TransactionManager.Instance.EnsureInTransaction(doc)

for i,k in zip(gloPar,expres):
	if i.IsValidFormula(k):
		i.SetFormula(k)
		OUT = "It's over, it's done"
	else:
		OUT = "Invalid expression"
		
TransactionManager.Instance.TransactionTaskDone()
4 Likes

This work perfectly !

I have tried with different architecture of list but i can’t make the lacing to work.

Could you make it that it can handle multiple parameter with same or different formula ?

Thank you so much already !

This script takes per each parameter single expression. So to make it work on multiple parameters or expressions, you just have to feed lists that have them paired. So manage your input outside the python script. I’ve made a small error in the script so copy it again (just fixed it). For example like this.

Again : Thank you !

It works perfectly !