Dealing with TaskDialogs

I found this great AU talk on handling Task Dialogs and thought I would share it here

But these are the codes for task dialog interactions -
image

3 Likes

Here is how I made a smartpushbutton for a taskdialog handler I created for temporarily disabling the service mismatch warning for fabrication parts.

I added the dll and addin file into my ribbon github, and the addin file is automatically copied to the appropriate folder if it is missing to automate distribution during Revit startup to about 200 different users.

We have a separate fabrication service for cans and sleeves for wall and deck pens that hosts to the pipe, and it was really annoying getting a service mismatch on every single sleeve placed.

Used an existing smartpushbutton as a template

import re
import os
import shutil
import os.path as op
from pyrevit import script
from pyrevit.coreutils.ribbon import ICON_MEDIUM
from pyrevit import HOST_APP, UI

uiapp = HOST_APP.uiapp

logger = script.get_logger()

folder_paths = [
    'C:\\ProgramData\\Autodesk\\Revit\\Addins\\2020',
    'C:\\ProgramData\\Autodesk\\Revit\\Addins\\2021',
    'C:\\ProgramData\\Autodesk\\Revit\\Addins\\2022',
    'C:\\ProgramData\\Autodesk\\Revit\\Addins\\2023',
    'C:\\ProgramData\\Autodesk\\Revit\\Addins\\2024'
]

# File name to check in each folder
target_file_name = 'DisableServiceMismatch.addin'

# Source file to copy
source_file = 'ribbon\\path\\to\\dll\\DisableServiceMismatch.addin'

for folder in folder_paths:
    if os.path.isdir(folder):
        target_file_path = os.path.join(folder, target_file_name)
        if not os.path.isfile(target_file_path):
            shutil.copy(source_file, target_file_path)

DISABLEDIALOG_ENV_VAR = 'DISABLEDIALOGACTIVE'

def __selfinit__(script_cmp, ui_button_cmp, __rvt__):
    on_icon = script_cmp.get_bundle_file('on.png')
    off_icon = script_cmp.get_bundle_file('off.png')

def toggle_state():
    new_state = not script.get_envvar(DISABLEDIALOG_ENV_VAR)
    script.set_envvar(DISABLEDIALOG_ENV_VAR, new_state)
    script.toggle_icon(new_state)
    uiapp.PostCommand(UI.RevitCommandId.LookupCommandId("38fd86a7-956c-4c9c-9765-79d5b9163527"))  

if __name__ == '__main__':
    toggle_state()

3 Likes

Brilliant! thanks for sharing mate!