[Mi...] Posted October 18, 2022 Share Posted October 18, 2022 Hello all , Is it possible to create a dynamic dialog? The number of widgets (columns and rows) depends on the user (project)? Defined by "gom.script.sys.create_user_defined_dialog" only allows to enter a specific number of items, eg checkbox. Is it possible to edit the dialog window content after its definition (adding more widgets, editing the number of columns and rows) - change the dialog box format? Link to comment Share on other sites More sharing options...
[Th...] Posted October 19, 2022 Share Posted October 19, 2022 It's possible. For general information about dialog handling (dynamic and static) please have a look at: https://connect.gom.com/x/DZ-VAg You must define the dialog with parameter "Extendable break dialog" to enable dynamic behavior by the dialog-event-handler. This code just shows a simple example for reference: import gom DIALOG=gom.script.sys.create_user_defined_dialog (content='<dialog>' \ ' <title>Test Dialog</title>' \ ' <style></style>' \ ' <control id="OkCancel"/>' \ ' <position></position>' \ ' <embedding></embedding>' \ ' <sizemode></sizemode>' \ ' <size width="198" height="191"/>' \ ' <content columns="1" rows="4">' \ ' <widget columnspan="1" type="input::checkbox" rowspan="1" row="0" column="0">' \ ' <name>checkbox1</name>' \ ' <tooltip></tooltip>' \ ' <value>true</value>' \ ' <title>Checkbox 1</title>' \ ' </widget>' \ ' <widget columnspan="1" type="input::checkbox" rowspan="1" row="1" column="0">' \ ' <name>checkbox2</name>' \ ' <tooltip></tooltip>' \ ' <value>true</value>' \ ' <title>Checkbox 2</title>' \ ' </widget>' \ ' <widget columnspan="1" type="label" rowspan="1" row="2" column="0">' \ ' <name>text1</name>' \ ' <tooltip></tooltip>' \ ' <text>Text 1</text>' \ ' <word_wrap>false</word_wrap>' \ ' </widget>' \ ' <widget columnspan="1" type="input::string" rowspan="1" row="3" column="0">' \ ' <name>text2</name>' \ ' <tooltip></tooltip>' \ ' <value>Text 2</value>' \ ' <read_only>false</read_only>' \ ' <password>false</password>' \ ' </widget>' \ ' </content>' \ '</dialog>') # # Event handler function called if anything happens inside of the dialog # def dialog_event_handler (widget): DIALOG.text1.visible = DIALOG.checkbox1.value DIALOG.text2.enabled = DIALOG.checkbox2.value DIALOG.handler = dialog_event_handler RESULT=gom.script.sys.show_user_defined_dialog (dialog=DIALOG) For more information about every single dialog widget you can also use the Python-__doc__-shortcut. Link to comment Share on other sites More sharing options...
[Al...] Posted July 23 Share Posted July 23 (edited) Hi everyone, I need some help with a script I'm working on in GOM Inspect. I'm trying to let the user select an STL file via a custom dialog box, and then import that file into the project. The file path seems to be correctly selected, but the file is not imported, and I keep getting the message: "Dialog canceled or no file selected.". If anyone could point out what I'm doing wrong or missing, that would be much appreciated! Here is the code: # 2. Display the user-defined dialog DIALOG = gom.script.sys.create_user_defined_dialog(dialog={ "content": [ [ { "columns": 1, "name": "label", "rows": 1, "text": { "id": "", "text": "Add the STL file before cutting the HMU BLOCK", "translatable": True }, "tooltip": { "id": "", "text": "", "translatable": True }, "type": "label", "word_wrap": False } ], [ { "columns": 1, "default": "", "file_types": [ { "description": "All files", "name": "*.stl*" } ], "file_types_default": "*.stl*", "limited": True, "name": "file", "rows": 1, "selection_type": "file", "title": { "id": "", "text": "Choose a file", "translatable": True }, "tooltip": { "id": "", "text": "", "translatable": True }, "type": "input::file" } ] ], "control": { "id": "OkCancel" }, "embedding": "", "position": "", "size": { "height": 163, "width": 375 }, "sizemode": "", "style": "", "title": { "id": "", "text": "Dialog title", "translatable": True } }) # Event handler function (currently unused) def dialog_event_handler(widget): pass DIALOG.handler = dialog_event_handler RESULT = gom.script.sys.show_user_defined_dialog(dialog=DIALOG) print("Dialog result:", RESULT) # 4. Retrieve the 'file' field value if RESULT == 'ok': stl_nominal_path = RESULT.result['file'].value # 5. Import the selected STL file gom.script.sys.import_stl( bgr_coding=True, body_split='no_color', files=[stl_nominal_path], geometry_based_refining=False, import_mode='clipboard', length_unit='mm', stl_color_bit_set=False, target_type='cad_body' ) else: print("Dialog canceled or no file selected.") Thanks in advance for your help! Let me know if I need to share more of the code. Edited July 23 Link to comment Share on other sites More sharing options...
[Ju...] Posted July 24 Share Posted July 24 Please sign in to view this quote. try changing to check if name is blank or not selected, your print of RESULT shows it never returns OK print("Dialog result:", RESULT) # 4. Retrieve the 'file' field value if RESULT.file != '': Also change to stl_nominal_path = RESULT.file 1 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