LearnRevitAPI

Automate Key Parameters in Revit API

Dec 5, 2024

Key Parameters in Revit API

After last couple of emails about shared parameters I got an interesting question:
'What about Key-Parameters in Revit API?'

And it's a tricky one, so let me explain.

Key Parameters

As you know we can create Key Parameters in Revit to control multiple values. It's very common to use them with Rooms to control multiple parameters.


And if you explore it with Revit API, you will realize that you can't set key values using String names, instead it has StorageType.ElementId, so it can be tricky to find the right values.

So let me break it down.

Get Key-Parameter Values

To get all key parameter values, I use a trick with FilteredElementColletor and ViewSchedule.

If you going to open ViewSchedule for your Key-Parameter you can get 2 important values:

  • KeyScheduleParameterName Property to match schedule to your parameter name

  • Possible Key Values to get the right ElementId

I think this code snippet will explain it far better:


  • With this code we define the name of Key-Parameter we are interested in ('Room Style')

  • Get All Schedules

  • Find Schedule with matching KeyScheduleParameterName

  • Get Values with FilteredElementCollector(doc, view.Id)

  • Sort in a Dictionary

This is the easiest way I found to get these values.

Set Key-Parameter Values

Once you have a list of possible values, it becomes simple.

You can select the value you want, and use Set with ElementId value.

Here is sample:

This will help you automate your Key-Parameters with Revit API.

Have Other Revit API Questions?

Let me know if you have other Revit API Questions, especially about parameters while I'm on this topic.

This helps me find interesting ideas to make content about.

Hit 'Reply'

Enjoyed Newsletter?

Leave a Testimonial Here.

⌨️ Happy Coding!
Erik Frits

Join Newsletter

📩 You will be added to Revit API Newsletter

Join Us!

which is already read by 7500+ people!