Assign values to variables in Invoke function

Hello Guys,
I’m trying to set default values for variables in invoke function(Code Below) but it seems that I can’t reach this values(that i assign in invoke) from outside of function, even if I declare them as global.

I tried to print values that I am assigning here and it works fine

Here is the Code:


import bpy
from bpy.props import *


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


    defaultOne = 0
          
    def invoke(self, context, event):
        defaultOne = 360
        global defultOne


        wm = context.window_manager
        return wm.invoke_props_dialog(self)
    
    num_one = IntProperty(
                    name = "One",
                    default = defaultOne)


    
    def execute(self, context):
        return {'FINISHED'}


bpy.utils.register_class(DialogOperator)
bpy.ops.object.dialog_operator('INVOKE_DEFAULT')

Note: Without defaultOne = 0 before invoke function Blender gives me nameError: name ‘defaultOne’ is not Defined
P.S. I am assuming that my code is right because I follow tutorial on this site: http://wiki.blender.org/index.php/User:Kilon/Python_book_of_magic/08.Function
Screen of tutorial page:

Okay i got little confused.
I searched web and find this about invoke function (from here http://www.blender.org/api/blender_python_api_2_57_release/bpy.types.Operator.html)

Operator.invoke is used to initialize the operator from the context at the moment the operator is called. invoke() is typically used to assign properties which are then used by execute(). Some operators don’t have an execute() function, removing the ability to be repeated from a script or macro.This example shows how to define an operator which gets mouse input to execute a function and that this operator can be invoked or executed from the python api.Also notice this operator defines its own properties, these are different to typical class properties because blender registers them with the operator, to use as arguments when called, saved for operator undo/redo and automatically added into the user interface.

<b>import</b> <b>bpy</b>

<b>class</b> <b>SimpleMouseOperator</b>(bpy.types.Operator):
    <i>""" This operator shows the mouse location,</i>
<i>       this string is used for the tooltip and API docs</i>
<i>   """</i>
    bl_idname = "wm.mouse_position"
    bl_label = "Invoke Mouse Operator"

    x = bpy.props.IntProperty()
    y = bpy.props.IntProperty()

    <b>def</b> execute(self, context):
        <i># rather then printing, use the report function,</i>
        <i># this way the messag appiers in the header,</i>
        self.report({'INFO'}, "Mouse coords are <i>%d</i> <i>%d</i>" % (self.x, self.y))
        <b>return</b> {'FINISHED'}

    <b>def</b> invoke(self, context, event):
        self.x = event.mouse_x
        self.y = event.mouse_y
        <b>return</b> self.execute(context)

bpy.utils.register_class(SimpleMouseOperator)

<i># Test call to the newly defined operator.</i>
<i># Here we call the operator and invoke it, meaning that the settings are taken</i>
<i># from the mouse.</i>
bpy.ops.wm.mouse_position('INVOKE_DEFAULT')

<i># Another test call, this time call execute() directly with pre-defined settings.</i> bpy.ops.wm.mouse_position('EXEC_DEFAULT', x=20, y=66)

This should explain everything for everyone who have similiar problem :slight_smile: