[Kr...] Posted January 23, 2023 Share Posted January 23, 2023 Hello, I've been playing around for a while to try and figure this out but I think I'm missing something simple. I'm trying to create a output script that runs a variety of different scripts/outputs that we generate all in one button press. The problem I'm having is I want to add a couple of check boxes to the bottom which allows the user to select what outputs they want i.e. Mesh export, Report export etc. I've tried playing around with a simple dialogue box to figure it out but I'm just not understanding it. I've posted it below. What I'm trying to generate is something like the following: If checkbox is ticked then run mesh export else skip and move on. if checkbox1 is ticked then run script abcxyz else skip. if checkbox2 is unchecked then ignore and carry on the rest of the script. # -*- coding: utf-8 -*- import gom DIALOG=gom.script.sys.create_user_defined_dialog (dialog={ "content": [ [ { "columns": 1, "name": "checkbox", "rows": 1, "title": { "id": "", "text": "Output 1 ", "translatable": True }, "tooltip": { "id": "", "text": "", "translatable": True }, "type": "input::checkbox", "value": True } ], [ { "columns": 1, "name": "checkbox_1", "rows": 1, "title": { "id": "", "text": "Mesh Output", "translatable": True }, "tooltip": { "id": "", "text": "", "translatable": True }, "type": "input::checkbox", "value": True } ], [ { "columns": 1, "name": "checkbox_2", "rows": 1, "title": { "id": "", "text": "Report Output", "translatable": True }, "tooltip": { "id": "", "text": "", "translatable": True }, "type": "input::checkbox", "value": True } ] ], "control": { "id": "OkCancel" }, "embedding": "", "position": "", "size": { "height": 174, "width": 214 }, "sizemode": "", "style": "", "title": { "id": "", "text": "Dialog Title", "translatable": True } }) # # Event handler function called if anything happens inside of the dialog # def dialog_event_handler (widget): pass DIALOG.handler = dialog_event_handler RESULT=gom.script.sys.show_user_defined_dialog (dialog=DIALOG) Any help would be greatly appreciated as I'm struggling to get my head around this for some reason. Cheers Kris Link to comment Share on other sites More sharing options...
[Mi...] Posted January 23, 2023 Share Posted January 23, 2023 (edited) Hello Chris, you could rename your three checkboxes to "checkbox_1", "checkbox_2" and "checkbox_3" or choose any other names that you prefer. Just make sure the names are unique. I have changed your script to show you how to evaluate whether checkboxes are on or off in the print_dialog_content function below. You can run the script and observe the text output in the console. Replace the print statement with invocations of the scripts that you would like to run. # -*- coding: utf-8 -*- import gom import gom DIALOG = gom.script.sys.create_user_defined_dialog(dialog={ "content": [ [ { "columns": 1, "name": "checkbox_1", "rows": 1, "title": { "id": "", "text": "Output 1 ", "translatable": True }, "tooltip": { "id": "", "text": "", "translatable": True }, "type": "input::checkbox", "value": True } ], [ { "columns": 1, "name": "checkbox_2", "rows": 1, "title": { "id": "", "text": "Mesh Output", "translatable": True }, "tooltip": { "id": "", "text": "", "translatable": True }, "type": "input::checkbox", "value": True } ], [ { "columns": 1, "name": "checkbox_3", "rows": 1, "title": { "id": "", "text": "Report Output", "translatable": True }, "tooltip": { "id": "", "text": "", "translatable": True }, "type": "input::checkbox", "value": True } ] ], "control": { "id": "OkCancel" }, "embedding": "", "position": "", "size": { "height": 174, "width": 214 }, "sizemode": "", "style": "", "title": { "id": "", "text": "Dialog Title", "translatable": True } }) # # Event handler function called if anything happens inside of the dialog # def print_dialog_content(caption): print() print(caption) print("=====================") # Evaluate first checkbox. if DIALOG.checkbox_1.value: print("1. Run output 1") # Evaluate second checkbox. if DIALOG.checkbox_2.value: print("2. Run mesh output") else: print("2. Skip mesh output") # Evaluate third checkbox. print("3. Run report output:", DIALOG.checkbox_3.value) def dialog_event_handler(widget): print_dialog_content("Dialog widget handler") DIALOG.handler = dialog_event_handler RESULT = gom.script.sys.show_user_defined_dialog(dialog=DIALOG) print_dialog_content("Dialog end result") Edited January 23, 2023 Link to comment Share on other sites More sharing options...
[Kr...] Posted January 24, 2023 Author Share Posted January 24, 2023 Hi Michael, Thank you for the feedback. I've had a look over the code and messed around with it to understand what is going on and I think I've got it. I'm just having a few problems with the "next steps" and how to change the outputs from a print to another function. Is there a way to recall the results of the checkbox/print at a later date to then run the script requirement? This is the only way I can think of setting it up. There is a order to my processes in the main script I am writing. 1. Recalculate 2. Run a statistics script 3. Export mesh and so on. If I could set it up so that when it arrives at the mesh output part of the script it asks: if checkbox_2 value = true, then run mesh export. if checkbox_2 = false, skip. or something along these lines. Hopefully that makes sense. I'm not sure If I can define the checkbox outputs as string or value that I can then reference in the mesh export. Link to comment Share on other sites More sharing options...
[Di...] Posted January 24, 2023 Share Posted January 24, 2023 (edited) I don't no if I'm understanding the question but you can try something like this import tkinter import tkinter as tk from tkinter import messagebox root = tk.Tk() canvas1 = tk.Canvas(root, width=300, height=300) # Box dimension canvas1.pack() def exit_application(): msg_box = tk.messagebox.askquestion('Run Script?', 'Are you sure you want to run the Scrip?', icon='warning') if msg_box == 'yes': SCRIPT THAT YOU CREATE else: tk.messagebox.showinfo('Exit', 'You will now return to the application screen') button1 = tk.Button(root, text='Run Script', command=exit_application, bg='brown', fg='white') canvas1.create_window(150, 150, window=button1) # Button color you can change it Edited January 24, 2023 Link to comment Share on other sites More sharing options...
[Kr...] Posted January 24, 2023 Author Share Posted January 24, 2023 Hi Diogo, Thank you for the response. I've had a little play but I can't seem to get it working or to preform any actions. Could be something on my end though. To try and simplify what I'm after I have thrown together some code as an example. This code is sort of doing what I need. It runs a recalc and another script before prompting the user with the dialogue box (I've ## the script for confidentiality reasons). The problem with the script below is, Whenever the tick box is checked in the dialogue box it exports the mesh and report there and then. I want it to wait until the OK button is clicked before it runs the script. If anyone knows how to change the button operation so it waits until the dialogue box is confirmed that would fix the problem I'm having and allow me to adapt my main code. # -*- coding: utf-8 -*- import gom import os import time DIALOG=gom.script.sys.create_user_defined_dialog (dialog={ "content": [ [ { "columns": 1, "name": "CBMesh", "rows": 1, "title": { "id": "", "text": "Mesh", "translatable": True }, "tooltip": { "id": "", "text": "", "translatable": True }, "type": "input::checkbox", "value": True }, { "columns": 1, "name": "CBReport", "rows": 1, "title": { "id": "", "text": "Report", "translatable": True }, "tooltip": { "id": "", "text": "", "translatable": True }, "type": "input::checkbox", "value": True } ] ], "control": { "id": "OkCancel" }, "embedding": "", "position": "", "size": { "height": 112, "width": 214 }, "sizemode": "", "style": "", "title": { "id": "", "text": "Dialog Title", "translatable": True } }) # # Event handler function called if anything happens inside of the dialog # ## Recalculate Project with Report Pages. gom.script.sys.recalculate_project () ## Run Other Script #2. ##gom.script.userscript.ExampleScript () def dialog_event_handler (widget): if DIALOG.CBMesh.value: gom.script.sys.export_stl ( bgr_coding=False, binary=True, color=False, elements=gom.ElementSelection ({'category': ['key', 'elements', 'part', gom.app.project.parts['Part'], 'explorer_category', 'actual_part']}), export_in_one_file=True, export_stages_mode='current', file=gom.app.project.name + '_Rep_STL_', length_unit='default', set_stl_color_bit=False) else: print("No Mesh Output") if DIALOG.CBReport.value: gom.script.report.export_pdf ( export_all_reports=True, file=gom.app.project.name + '_Rep_L2_' + '.pdf', jpeg_quality_in_percent=100) else: print("No Report Output") pass DIALOG.handler = dialog_event_handler RESULT=gom.script.sys.show_user_defined_dialog (dialog=DIALOG) Link to comment Share on other sites More sharing options...
[Mi...] Posted January 24, 2023 Share Posted January 24, 2023 Kristian, you can leave the dialog_event_handler function empty, e.g., by replacing it with "pass" statement or maybe a print function which can be useful for debugging. The block of code that was inside your dialog_event_handler function can be moved to the very end of your script, after the invocation of show_user_defined_dialog. With this setup the recalculation and mesh export will be done only once after you have clicked "ok". Hope that helps. Link to comment Share on other sites More sharing options...
[Kr...] Posted January 24, 2023 Author Share Posted January 24, 2023 Please sign in to view this quote. Michael, Simple fix. That's stopped the issue I was having. With a combination of your other post and some rearranging of the logic I reckon I can get the full code doing what I want now. Thank you very much for your assistance with this. Helped the project, and my knowledge, greatly. 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