daveBisMe
daveBisMe

Reputation: 11

Revit, Using Python, Can you change a "Formula" value in a family?

We have a Parameter in our families called "Family Version", within this parameter we set a formula to "2019.01" to represent the Revit version and the latest update to the family. Even though this is a text field, we set it as a formula so the end user cannot change it.

My question is this: Is there a way to set the formula via Python? If it's not set to a Formula, I can use this code to change the value:

#Set Family Version
t = Transaction(doc, "Set Family Version")
t.Start()
parameter = [a for a in doc.FamilyManager.Parameters if a.Definition.Name=="Family Version" ][0]
doc.FamilyManager.Set(parameter, "2020.01")
t.Commit()

Is there a way to change a formula?

Upvotes: 0

Views: 267

Answers (1)

daveBisMe
daveBisMe

Reputation: 11

For anyone EVER wanting to do this. Found the solution.

Use "SetFormula" NOT "Set". Also needed to set the text to "\"2020.01\"" and not "2020.01"

Here's the update...

#Set Family Version
t = Transaction(doc, "Set Family Version")
t.Start()
parameter = [a for a in doc.FamilyManager.Parameters if a.Definition.Name=="Family Version" ][0]
doc.FamilyManager.SetFormula(parameter, "\"2020.01\"")
t.Commit()

Upvotes: 1

Related Questions