Resources
Downloads
Summary
Set Parameter Values
In the previous video, you learned how to access parameters using the Revit API and read their values based on their storage type. But now let's look at how to set new values for these parameters?
There are 4 different options, depending on the StorageType of our Parameters:
So you should either know what type of parameter you are dealing with, or make a conditional statement to check its StorageType.
Prepare a button
Create a button for this lesson.
We will use code from the previous lesson, where we already got different parameters when we select a Wall.
Set Parmeter Values
Setting parameters is very simple, we just use .Set method and then we provide a value as an argument with the correct data type.
💡Make sure you provide value to match parameter's StorageType!
If you provide wrong data type of a value, then it won't make any changes, but it also won't show you any errors. So pay attention to that!
💡 Be sure that your parameters are not .ReadOnly!
Transaction
Also notice that I use Transaction class.
💡Transaction are used to make any changes in Revit projects. This protects our project from unintentional changes.
💡 It's also great for beginners to know, we can't mess up anything unless we use them, so get comfortable using Revit API!
In a nutshell: We need to
1) Define a Transaction
2) .Start() transaction
3) .Commit() transaction.
and all the changes have to be between Start and Commit statements.
Here are 2 syntax examples of how to use them:
Results Overview
If you going to inspect parameters where you changed values you might notice different values.
Remember that Revit API uses feet as internal units. So when your parameters have units associated with them, you need to provide your values in feet!
That's why you will see different values in AsDouble() and AsValueString() for s_area parameter. AsValueString shows values converted to your project units!
However, if parameter doesn't have any units associated like s_nubmer, then AsDouble and AsValueString() will hold the same value. That's because Revit doesn't know what units is this value supposed to hold.
Bonus: Write ElementId in Mark parameter for Walls
Here is a bonus example of how to write ElementId in Mark parameter for all walls.
I get all walls in the project with FilteredElementCollector. Don't worry too much about it yet, you will learn everything about getting your elements in Module 06.
💡 Try this snippet!
HomeWork
Use the code snippet provided in the Bonus section to write ElementIds for all your Walls.
Then try to make similar snippet, but for Rooms. Choose a property that you can get out of rooms, and write them in one of Room's parameters.
👇 Here is a snippet to help you get all Rooms.
⌨️ Happy Coding!