Bold and coloured text in pop-ups

Is it possible via Dynamo and Python to get bold + coloured text in a pop-up window?

For the built-in Revit dialogs, I don’t believe so.

However, you could explore creating your dialog with Windows Forms or WPF. (Similar to data-shapes)

1 Like

I thought that was probably going to be the answer.

I’m going to go sulk until my C# gets better. :frowning:

This post has some guidance on how to do it in python:

2 Likes

Also, if you are simply wanting to draw more attention to your dialog, the Revit dialogs offer a few icons.

Basically I’ve written a new script that’s a little different from our usual format so I wanted to include a couple of very simple examples in one of the warning pop-ups.

I thought it’d be fun/ useful to make the text, Examples: bold.

1 Like

So you can install visual studio community and start making windows that are pretty much a copy paste into python.

Would result in this:

Admittedly, this is one of the first times I have interacted with WPF in python, but it is pretty neat!

3 Likes

Ooooo! Took me ages to get the basic pop-ups to work in Dyno so I’ve avoided anything scarier. Now I’m going to have to look at this! :grinning:

They seem way easier in C# from what little I’ve done.

Don’t suppose you know if it’s easier in R23?

I don’t believe Revit2023 has any extra ease to it. If anything it is more difficult because you have to reference the IronPython package to load those libraries.

But surely the functionality of Py3 is better and gives you access to more stuff?

To my understanding CPython3 eliminates the ability to use WPF and windows forms in their current state.

(I might be and hope I am wrong, cc @jacob.small )

1 Like

For completeness, here is what I mocked up real quick in visual studio: :slight_smile:

I encourage you to get VS Community installed and start having a play!

Python Code:

import clr	
import sys
import System
sys.path.append(r'C:\Program Files (x86)\IronPython 2.7\Lib')
sys.path.append(r'C:\Program Files (x86)\IronPython 2.7\DLLs')

try:
	clr.AddReference("IronPython.Wpf")
	clr.AddReference('System.Core')
	clr.AddReference('System.Xml')
	clr.AddReference('PresentationCore')
	clr.AddReference('PresentationFramework')
	clr.AddReferenceByPartialName("WindowsBase")
except IOError:
	raise
	
from System.IO import StringReader
from System.Windows.Markup import XamlReader, XamlWriter
from System.Windows import Window, Application

try:
	import wpf
	import time
except ImportError:
	raise
class CreateWindow(Window):
	LAYOUT = '''
	<Window 
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             Height="140" Width="400"
             WindowStartupLocation="CenterScreen">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="36"/>
        </Grid.RowDefinitions>

<TextBox Name="MessageBox" Grid.Row="0" Margin="8" Text="A" TextWrapping="Wrap" Foreground="Red" BorderBrush="{x:Null}" IsHitTestVisible="False"/>

<!--the buttons section-->
        <Grid Grid.Row="1" Background="LightGray">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Button Grid.Column="2" Content="Close" Margin="8 4" IsCancel="True"/>
        </Grid>
        
    </Grid>
</Window>
	'''
	
	def __init__(self):
		self.ui = wpf.LoadComponent(self, StringReader(CreateWindow.LAYOUT))
		self.Title = IN[0]
		self.MessageBox.Text = IN[1]
				
pb = CreateWindow()
pb.ShowDialog()

OUT = pb.MessageBox.Text
2 Likes

Had VS for a while… but Dynamo screen is so much more relaxing :smiley:

BUT now you’ve offered me colours I cannot say no! :star_struck:

1 Like

That works in R23 but not R21.

So maybe new python is nicer after all :smiley:

1 Like

Hmm, that is interesting. I did use the code supplied in that thread for the imports and everything though and didn’t test in older versions

Looks like you are correct. I’m watching the IronPython3 development pretty closely as that will solve a lot of the issues if it gets ported in.

Edit: Handy info for running WPF from IronPython where threading isn’t locked by Revit/Civil/whatnot: Python Dispatcher Threads - #2 by Mark.Ackerley

1 Like