X
X
X
Are you Ready?
Task Dialog in Revit API
Revit API already has a simple form that we can use with TaskDialog Class.
It can be used to display different messages to the user and get a very simple user input, by using Common Buttons, Command Buttons or even Verification Checkbox.
Let's have a look at how to create TaskDialog and override its properties.
Task Dialog Constructor
First of all we need to create TaskDialog instance using the constructor. It takes a single argument - title.
Once you've created an instance of a TaskDialog, make sure you use Show() method to actually display it to a user.
There are 4 different Show Variations, and we will start using the regular one without any arguments, because we will override different properties manually on the TaskDialog instance.
💡 Other Show methods give you an option to provide different arguments in the Show method, so you can save some space in the code. I will show you an example in the end, but first let's break down the most commonly used properties.
Heading and Message
First of all let's add some text. We can use MainInstruction and MainContent for displaying the Heading message and the content itself.
💡 Make sure you use Show method after you've overridden all the properties.
Common Buttons
Now Let's add a few buttons to the form. We need to use CommonButtons property and use TaskDialogCommonButtons Enumeration for defining the buttons.
You will also notice that we don't create a list, but use a | ('pipe') symbol between them. This symbol represents OR/Union actions. To make it you have to click on SHIFT + \ (see image below of keyboard key)
We can also define which of these buttons should be highlighted by using DefaultButton property and providing TaskDialogResult Enumeration.
💡 Also notice that we've created a result variable to store the result of a task dialog after we call .Show method.
What Button was selected?
We can make conditional statement to find out what button user has selected in the TaskDialog. For that we need to use result variable that we defined, and compare it to TaskDialogResult Enumertaion like this:
Command Buttons
TaskDialog also has an option to create up to 4 Command Buttons.
We need to use AddCommandLink method and provide TaskDialogCommandLinkId Enumeration and the displayed text.
To read what button was selected, we can use the same logic as for CommonButtons. Just make sure you look at TaskDialogResult.CommandLink1, 2,3,4
Footer
TaskDialog also has an option to create a footer.
We can also provide an HTML <a> tag, so it's actually a link.
CheckBoxes
In case you would like to add a checkbox in your TaskDialog you have 2 options:
💡 Make sure you don't use both at the same time, as it will trigger an error!
To read the result of a checkbox we need to use appropriate method such as:
Final Code
Lastly, let's put all of it together into a single code snippet:
What about other constructors?
Well, let's look at them.
Overall allow you to provide different arguments instead of overriding properties.
There are 3 more constructors, and the difference is that, they all take 1 more parameter than the previous one. So we will only look at the last one with the most parameters, but you can obviously provide less arguments if you want to.
Let's break it down. We can provide the following 4 arguments:
title
maininstruction
buttons
defaultButton
⌨️ And here is a code example:
That would be similar to overriding the properties, but instead you set these values by using Show method.
Homework Here…
⌨️ Happy Coding!