Change task dialog button's text

I’d like to change the button to read something other than, ‘close’.
How do I do this?

image

The API docs say

// Set common buttons and default button. If no CommonButton or CommandLink is added,
// task dialog will show a Close button by default
mainDialog.CommonButtons = TaskDialogCommonButtons.Close;
mainDialog.DefaultButton = TaskDialogResult.Close;

https://www.revitapidocs.com/2017/5fa611e4-8569-e756-fc93-a4d3c4d391ec.htm

seems to suggest I have limited choices?
I tried this, but the button still says, “Close”

image

I think it has something to do with taskdialog vs maindialog… but I’m struggling to work it out.

If you want custom buttons you will need to create a Winform yourself or use the Data-Shaoes package.

Otherwise you are limited to the below for TaskDialogs.

1 Like

Do I need to learn C# or is it easy enough in Python do you think?

Data shapes is written in Python and all open for viewing in the nodes. Given the main input form node goes over 1k lines of code I’d say it’s a teensy bit complicated.

1 Like

I like a challenge…
Watch this space… (in about 3 years). :laughing:

1 Like

Might be worth looking into pyRevit if you’re going down the Python route. Ehsan provides some great forms to use by default which have customizable button names and outputs:

https://pyrevit.readthedocs.io/en/latest/pyrevit/forms.html

1 Like

I do sometimes wonder what i’m doing with my life…

It’s 9.30am on a Sunday and I’m reading stuff to try and change a word on a button on a windows pop-up…

:thinking:

5 Likes

Sums up the life of a developer! :joy:

2 Likes

Here is simple example of a CPython3 Winform with outputs within the Dynamo Core environment to get you going. I have commented the code so you are able to follow what each part is doing, and so can figure out in what direction you might be looking to investigate your UI choices further. :slight_smile:

import clr
clr.AddReference('System.Windows.Forms')
clr.AddReference('System.Drawing')

from System.Drawing import *
from System.Windows.Forms import *
from System import Array, Object

class SimpleForm(Form):
    def __init__(self):
        
        # The text to show in the top bar
        self.Text = "A Simple Form"
        # The width of the form in pixels
        self.Width = 250
        # The height of the form in pixels
        self.Height = 240
        # Make the form a fixed size
        self.FormBorderStyle = FormBorderStyle.FixedDialog		
        # Position the form in the center of the screen
        self.StartPosition = FormStartPosition.CenterScreen 
        # Bring the form to the front of all windows
        self.TopMost = True
        # Show top bar controls	
        self.ControlBox = True
        self.MaximizeBox = False
        self.MinimiseBox = True
        
        # Add a button
        self.button1 = Button()
        # Set the button text
        self.button1.Text = 'Value 1'
        # Define what happens when you click the button
        self.button1.Click += self.save
        
        # Set the button width
        self.button1.Width = 100
        # Set the button height
        self.button1.Height = 180
        # Set the button location offset from the top left form pixel
        self.button1.Location = Point(10,10)
        # Set the background color for the button
        self.button1.BackColor = Color.Green
        # Add the button the form
        self.Controls.Add(self.button1)
        
        # Add another button
        self.button2 = Button()
        # Set the button text
        self.button2.Text = 'Value 2'
        # Define what happens when you click the button
        self.button2.Click += self.save2
        
        # Set the button width
        self.button2.Width = 100
        # Set the button height
        self.button2.Height = 180
        # Set the button location offset from the top left form pixel
        self.button2.Location = Point(120,10)
        # Set the background color for the button
        self.button2.BackColor = Color.Red
        # Add the button the form
        self.Controls.Add(self.button2)

    # Define what happens when you click the button		
    def save(self, sender, event):
        self.output = "Output chosen was Value 1";
        # Close the form
        self.Close();

    # Define what happens when you click the other button		
    def save2(self, sender, event):
        self.output = "Output chosen was Value 2";
        # Close the form
        self.Close();

runMe = IN[0]

if runMe:
    # Create the form
    form = SimpleForm()
    # Run the form
    Application.Run(form)
    # Get the output of the form
    OUT = form.output
else:
    OUT = "Set RunMe to True";
5 Likes

Whoah!!! That is awesome!! Thank you!

So less than 2 years later… :smiley:

If anyone’s interested, there are only 6 buttons for a Taskdialog.

  1. OK
  2. Yes
  3. No
  4. Cancel
  5. Retry
  6. Close

They appear in that order left to right too… Which is odd.

Winforms give you way more control which is what i’m using now. But I’ve been told they’re a bit outdated. :expressionless: