0
$\begingroup$

This question is similar to: Using Python to create a popup that changes an object based on the input, but I want to be able to control the flow of my script based on the execution of the popup box that is generated.

What I am trying to do is create an option of toggling the console window at the beginning of my script before the main code is run. This is because I need the console window open for parts of my script (Blender will crash otherwise). Sometimes I forget to open the console window and I don't want other developers that use my code to run into the same hassle as well.

I've tried adding bool checks in between code but this didn't produce the results that I wanted. e.g., boolCheck = 0; set boolCheck = 1 (inside execute def); if boolCheck = 1: #do rest of script (in main)

This is the basic script:

import bpy

global boolCheck


class DialogOperator(bpy.types.Operator):
    bl_idname = "object.dialog_operator"
    bl_label = "Simple Dialog Operator"

    def toggleConsole(self, context):
        if self.my_bool:
            bpy.ops.wm.console_toggle()
        return None

    my_float = bpy.props.FloatProperty(name="Some Floating Point")
    my_bool = bpy.props.BoolProperty(name="Toggle Option", update=toggleConsole)
    my_string = bpy.props.StringProperty(name="String Value")

    def execute(self, context):
        #message = "Popup Values: %f, %d, '%s'" % \
        #    (self.my_float, self.my_bool, self.my_string)
        #self.report({'INFO'}, message)
        print("stage 1 (clicked OK in popup box)")
        boolCheck = 1
        #print("popup boolCheck after pressing OK: %s" % (boolCheck)) 
        return {'FINISHED'}

    def check(self, context):
        return True

    def draw(self, context):
        layout = self.layout
        layout.prop(self, "my_bool")


    def invoke(self, context, event):
        wm = context.window_manager
        #print("stage 0.5 (opened popup window)")
        self.boolCheck = 0
        #print("popup boolCheck before pressing OK: %s" % (boolCheck)) 
        return wm.invoke_props_dialog(self)

bpy.utils.register_class(DialogOperator)


#main
boolCheck = 0
print("\n\nstage 0 (code that come BEFORE popup box code)")
#print("main boolCheck before popup script: %s" % (boolCheck))
bpy.ops.object.dialog_operator('INVOKE_DEFAULT')
#print("main boolCheck after popup script: %s" % (boolCheck))
if (boolCheck == 1):
    print("stage 2 (code the comes AFTER popup box code)")

Right now the order of operations is: "stage 0", "stage 1", and no stage 2.

Without the 'boolCheck if statement' in the main, then it just does "stage 0", then immediately "stage 2", then "stage 1" after clicking OK.

What I would like for the script to do is: "stage 0", "stage 1" when popup starts or when OK is clicked, then AFTER clicking OK in the popup box, "stage 2"

If anyone can give me some direction, I would appreciate it.

Thanks!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.