[Ra...] Posted May 26, 2021 Share Posted May 26, 2021 I want to display a result to operator in a message box, starting from a simple example: -- A distance is calculated from some elements -- A variable (e.g. total_dis) is created to capture the actual value (e.g. 25) -- How can I display this value in a simple message dialog as "Total distance: 25" ? Obviously the 25 will change when scan different parts. There're only a few options as output widget when I build a message box and I tried "continuous text" but it won't allow me to access any element related info. in the project. Is there any special Python script to handle this? Ray Xpert3D Metrology Link to comment Share on other sites More sharing options...
[Th...] Posted May 27, 2021 Share Posted May 27, 2021 You have several possibilities to do such a thing. Here some suggestions: # -*- coding: utf-8 -*- import gom my_value = 25.0 # brak dialog using number widget DIALOG=gom.script.sys.create_user_defined_dialog (content='<dialog>' \ ' <title>My message 1</title>' \ ' <style></style>' \ ' <control id="OkCancel"/>' \ ' <position></position>' \ ' <embedding></embedding>' \ ' <sizemode></sizemode>' \ ' <size width="198" height="112"/>' \ ' <content rows="1" columns="2">' \ ' <widget type="label" column="0" rowspan="1" row="0" columnspan="1">' \ ' <name>label</name>' \ ' <tooltip></tooltip>' \ ' <text>My value</text>' \ ' <word_wrap>false</word_wrap>' \ ' </widget>' \ ' <widget type="input::number" column="1" rowspan="1" row="0" columnspan="1">' \ ' <name>value_widget</name>' \ ' <tooltip></tooltip>' \ ' <value>0</value>' \ ' <minimum>0</minimum>' \ ' <maximum>1000</maximum>' \ ' <precision>2</precision>' \ ' <background_style></background_style>' \ ' </widget>' \ ' </content>' \ '</dialog>') DIALOG.value_widget.value = my_value DIALOG.label.enabled = False DIALOG.value_widget.enabled = False gom.script.sys.show_user_defined_dialog (dialog=DIALOG) # break message using text RESULT=gom.script.sys.execute_user_defined_dialog (content='<dialog>' \ ' <title>Message</title>' \ ' <style></style>' \ ' <control id="OkCancel"/>' \ ' <position>automatic</position>' \ ' <embedding>always_toplevel</embedding>' \ ' <sizemode>automatic</sizemode>' \ ' <size width="198" height="118"/>' \ ' <content rows="1" columns="1">' \ ' <widget type="display::text" column="0" rowspan="1" row="0" columnspan="1">' \ ' <name>text</name>' \ ' <tooltip></tooltip>' \ ' <text>' \ '<html><head></head><body>' \ '<p>My value is: {my_placeholder:1.2f}</p></body></html></text>' \ ' <wordwrap>false</wordwrap>' \ ' </widget>' \ ' </content>' \ '</dialog>'.format (my_placeholder = my_value)) # updating message using text my_text = '<html><head></head><body><p>My value is: {my_placeholder:1.2f}</p></body></html>' DIALOG=gom.script.sys.create_user_defined_dialog (content='<dialog>' \ ' <title>Message</title>' \ ' <style></style>' \ ' <control id="OkCancel"/>' \ ' <position>automatic</position>' \ ' <embedding>always_toplevel</embedding>' \ ' <sizemode>automatic</sizemode>' \ ' <size width="198" height="155"/>' \ ' <content rows="1" columns="1">' \ ' <widget type="display::text" column="0" rowspan="1" row="0" columnspan="1">' \ ' <name>text</name>' \ ' <tooltip></tooltip>' \ ' <text></text>' \ ' <wordwrap>false</wordwrap>' \ ' </widget>' \ ' </content>' \ '</dialog>') gom.script.sys.open_user_defined_dialog (dialog=DIALOG) for i in range (5): DIALOG.text.text = my_text.format (my_placeholder = my_value + i) gom.script.sys.delay_script (time=1) gom.script.sys.close_user_defined_dialog (dialog=DIALOG) For more information about user defined script dialogs and their data and event handling please have a look at: https://connect.gom.com/x/DZ-VAg Link to comment Share on other sites More sharing options...
[Ra...] Posted May 27, 2021 Author Share Posted May 27, 2021 Both work very well, thanks a lot. I do prefer 2nd method and I realize that the key is using ".format (my_placeholder = my_value)" to apply the derived value but looks like this needs to be added manually after the dialog created, correct? Because I tried to edit command on it but it gave me an error on that line. Can you explain a little bit more on how to generate this method? Link to comment Share on other sites More sharing options...
[Th...] Posted June 2, 2021 Share Posted June 2, 2021 You are right. Usually you can create these dialogs with the dialog wizard. But there you can only enter static content. The dialog creation wizard creates a command with a "content" parameter. This "content" parameter gets a python string, containing the dialog definition in XML format. So I just manipulated this XML-description string by standard python string formatting (see https://docs.python.org/3/tutorial/inputoutput.html#the-string-format-method for more information). But this "breaks" the default XML-string and the dialog creation wizard can not analyze/evaluate this string anymore. So to get a more stable approach by manipulating not the initial dialog definition XML-string but the created DIALOG python object, I recommend to use a combination of the 1st and 3rd approach like this: # -*- coding: utf-8 -*- import gom my_value = 25.0 # break message using text DIALOG=gom.script.sys.create_user_defined_dialog (content='<dialog>' \ ' <title>Message</title>' \ ' <style></style>' \ ' <control id="OkCancel"/>' \ ' <position>automatic</position>' \ ' <embedding>always_toplevel</embedding>' \ ' <sizemode>automatic</sizemode>' \ ' <size width="198" height="155"/>' \ ' <content rows="1" columns="1">' \ ' <widget type="display::text" column="0" rowspan="1" row="0" columnspan="1">' \ ' <name>text</name>' \ ' <tooltip></tooltip>' \ ' <text></text>' \ ' <wordwrap>false</wordwrap>' \ ' </widget>' \ ' </content>' \ '</dialog>') my_text = '<html><head></head><body><p>My value is: {my_placeholder:1.2f}</p></body></html>' DIALOG.text.text = my_text.format (my_placeholder = my_value) gom.script.sys.show_user_defined_dialog (dialog=DIALOG) Link to comment Share on other sites More sharing options...
[Ma...] Posted December 19, 2023 Share Posted December 19, 2023 Hello, Please note that the documentation has been moved to User-defined Dialogs — Add-On Documentation (zeissiqs.github.io). Best regards, Matthias Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in