MsgBox and If-statement


#1

Hi all.

I want to make an “If-Else” statement that:

-If it is true, display the messagebox.
-If False, continue with the script.

How can I implement the If node in here?

In a previous question, @john_pierson suggested me this solution, but I don’t know how can I apply this here.

Thanks in advance.


Start dynamo script from excel
#2

The null part indicates that you should do something else…
Home.dyn (3.1 KB)


#3

Here is an all python way with a true/false toggle as well.

import clr
import msvcrt

clr.AddReference("RevitAPIUI")
from  Autodesk.Revit.UI import *

button = TaskDialogCommonButtons.None
result = TaskDialogResult.Ok
if IN[0] == True:
	TaskDialog.Show('User Text',IN[1],button)
	result = IN[1]
else:
	result = "Set run to true"
		
OUT = result

and in action


#4

a bit to late… but the same conclusion :slight_smile:
The else branch can be changed for your purpose…

Home.dyn (6.0 KB)


#5

@john_pierson, @erfajo, nice solutions! Almost What I wanted. The only thing left is, when you go to the “else” part, is there a way to break the script at that point, so it doesn’t have to go further lacking the input elements?

Thanks


#6

You could add the passSomething in many ways… if you want to pass something no matter if there is a messagebox or not! Then it would look like the messagebox is “breaked”

Home.dyn (6.0 KB)


#7

Hi @john_pierson. What does the line “button = TaskDialogCommonButtons.None”?

I commented this and excluded the button call, and got the same result.


#8

http://www.revitapidocs.com/2017.1/5fa611e4-8569-e756-fc93-a4d3c4d391ec.htm

image


#9

Yes, but:

import clr
import msvcrt

clr.AddReference("RevitAPIUI")
from  Autodesk.Revit.UI import *

result = TaskDialogResult.Ok
if IN[0] == True:
	TaskDialog.Show('User Text',IN[1])
	result = IN[1]
else:
	result = "Set run to true"
		
OUT = result

this solution gets the same result. So why did you put it?


#10

Honestly. I can’t tell you. It has been a while and I am pretty sure that code came from the code samples.


#11

Ok. I’ll dig around. Thanks!


#12

My version has the boolean built into it. Search Packages for “truevis”.

image


#13

@Jorge_Villarroel (and @john_pierson)
I have been checking the Revit API… you are right the “None” option gives the same result as the “Close” option, but isnt that fairly acceptable?
http://www.revitapidocs.com/2018/5fa611e4-8569-e756-fc93-a4d3c4d391ec.htm
http://www.revitapidocs.com/2018/77990692-a24d-eb40-5872-f3ceb2f76e60.htm

The code, however, can be optimized a bit… there is no need for “TaskDialogResult.Ok” since that isnt called anywhere.

import clr
import msvcrt
clr.AddReference('RevitAPIUI')
from  Autodesk.Revit.UI import *

message = IN[1]
passSomething = IN[2]

if message:
	button = TaskDialogCommonButtons.Ok
	TaskDialog.Show('User Text',message,button)
else:
	pass

OUT = passSomething

if it should be used it must be called.

import clr
import msvcrt
clr.AddReference('RevitAPIUI')
from  Autodesk.Revit.UI import *

message = IN[1]
passSomething = IN[2]

if message:
	button = TaskDialogCommonButtons.Ok
	result = TaskDialogResult.Ok
	TaskDialog.Show('User Text',message,button,result)
else:
	pass

OUT = passSomething

in you case will that give this code (which will provide the “Close” buttom)

import clr
import msvcrt
clr.AddReference('RevitAPIUI')
from  Autodesk.Revit.UI import *

if IN[0]:
	TaskDialog.Show('User Text',IN[1])
	result = IN[1]
else:
	result = 'Set run to true'

OUT = result

Python Nodes Basics
#14

Thanks for the explanation. Much clearer now.


#15

How apply TaskDialogIcon ?
http://www.revitapidocs.com/2018/6c3246ba-2a00-386e-1ec4-39cdb7ad664e.htm


#16

dialog.MainIcon = TaskDialogIcon.TaskDialogIconWarning


#17

How use it exactly? its my incorrect try

	Icon_ = TaskDialogIcon.TaskDialogIconWarning
	TaskDialog.Show("text1",  "text2", Icon_)