How do I add a link to a pop-up?

Reading through this: Calling ctypes to create a custom system message - #2 by Gui_Talarico

But can’t work out how to :
1 : add a link from my server (not URL) to the CommandLinks
2: add an e-mail link or to the footer text
3: add hyperlink (a URL) to the command links.

In a Python window in Dynamo

Anyone know?

Hello @Alien

here an example

import clr
import sys
import System
clr.AddReference("System.Windows.Forms")
from System.Windows.Forms import Clipboard
# import Revit API
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *

clr.AddReference("RevitAPIUI")
from Autodesk.Revit.UI import (TaskDialog, TaskDialogCommonButtons,
                               TaskDialogCommandLinkId, TaskDialogResult)
myForum = 'https://forum.dynamobim.com/'
myMail = 'MyNameIsNobody@nowhere.com'
title = 'Task Dialog Title'
dialog = TaskDialog(title)

# Properties
dialog.MainInstruction = 'Text Header'
dialog.MainContent = 'Text Content'
dialog.FooterText = 'Footer Text'
dialog.VerificationText = 'Verification Text'
# dialog.ExpandedContent = expanded_content

# Settings
dialog.TitleAutoPrefix = False
dialog.AllowCancellation = True
# Add Button
dialog.CommonButtons = TaskDialogCommonButtons.Ok | TaskDialogCommonButtons.Yes
# Set Default Button
dialog.DefaultButton = TaskDialogResult.None
# Add Command Link
dialog.AddCommandLink(TaskDialogCommandLinkId.CommandLink1,
                      'Go to my favorite forum',
                      myForum)
dialog.AddCommandLink(TaskDialogCommandLinkId.CommandLink2,
                      'Copy my email in the Clipboard',
                      myMail)

result = dialog.Show()

if result == TaskDialogResult.Ok:
	OUT ='Dialog was OK'
if result == TaskDialogResult.Yes:
	OUT = 'Dialog was Yes'
if result == TaskDialogResult.Cancel:
	OUT = 'Dialog was Cancelled'
if result == TaskDialogResult.CommandLink1:
	System.Diagnostics.Process.Start(myForum)
	OUT = myForum
if result == TaskDialogResult.CommandLink2:
	Clipboard.SetText(myMail)
	OUT = myMail
if dialog.WasVerificationChecked():
	OUT = 'Verification was Checked'
5 Likes

You could also check out the Data-Shapes package.

I love datashapes but unless I’ve missed that node I’m not sure you can just have a pop-up with a URL?

Thank you for that :slight_smile:

Do you know how to make it link to non-URL… for example to

“C:\Users\Default\Pictures” ?

try this
System.Diagnostics.Process.Start(r'C:\Users\Default\Pictures')

5 Likes

hey this is fantastic! Just what I needed. Do you know where I could find a list of available commandlink functions?

Another way to start a URL :

import os
os.system("start \"\" https://example.com")
3 Likes

you can use up to 4 CommandLink see the API doc

1 Like

Sorry to drag up an old thread…
But … I just cut and pasted that into R23 and it doesn’t seem to work.

Has the syntax changed?

Hi @Alien

there are several issues

  1. in CPython3 the special None keyword can be used as attribute (or enum)
    you can replace
    dialog.DefaultButton = TaskDialogResult.None
    by
    dialog.DefaultButton = getattr(TaskDialogResult, "None")

  2. then will come an overload problem, you can look at this topic for more information

2 Likes