Passing custom arguments to a Blender Operator as if it were a function
Question: I created a python script in Blender which obtains information about an
object. Said information is then stored in a list of numpy arrays for later
use. Initially, I wanted to use that information to have the camera move in a
certain way, but running the script freezes the 3D enviornment until the end
of execution.

Multiple folks suggest using Operators, but Operators (as far as I know) only
accept arguments in a very special and inconvenient way. For instance, here we
have an example operator

    
    
    import bpy
    
    
    class DialogOperator(bpy.types.Operator):
        bl_idname = "object.dialog_operator"
        bl_label = "Simple Dialog Operator"
    
    my_float = bpy.props.FloatProperty(name="Some Floating Point")
    my_bool = bpy.props.BoolProperty(name="Toggle Option")
    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)
        return {'FINISHED'}
    
    def invoke(self, context, event):
        wm = context.window_manager
        return wm.invoke_props_dialog(self)
    
    
    bpy.utils.register_class(DialogOperator)
    
    # test call
    bpy.ops.object.dialog_operator('INVOKE_DEFAULT')
    

One can optionally write

    
    
    # test call
    bpy.ops.object.dialog_operator('INVOKE_DEFAULT',myfloat=2.3,...)
    

in order to set values for the parameters defined within the operator. My
problem is that only fields within the operator of the form
"bpy.props.****Property" can be assigned in this way.

Is there anyone who knows of a way to pass **ANY** desired set of argument to
an operator in the same way arguments can be passed to a function?

NOTE: An ugly way I though of to pass the arguments indirectly is by declaring
the set of variables you want to pass to be global variables...


Answer: To move your camera and get an updated 3DView, try using a [modal
operator](https://www.blender.org/api/blender_python_api_current/bpy.types.Operator.html#modal-
execution). When `execute()` is called and it returns `{'RUNNING_MODAL'}`, the
operators `modal()` method is called repeatedly until it returns
`{'FINISHED'}` or `{'CANCELLED'}`. Within `modal()` you can change things and
get the 3DView updated between calls.

Using
[`bpy.props`](https://www.blender.org/api/blender_python_api_current/bpy.props.html)
to add properties to an operator class is how you get properties that work
within blender. While we can add normal properties that the operator can use
within itself, we must use `bpy.props` to define the properties available to
an operator that are set during the operator's execute and effect its
operation, these properties can be adjusted by the user in the operator
properties panel and effect the undo/redo of the operator.

There are "Vector" versions of Bool, Int and Float properties so you can have
multiple values in one property. For more flexibility you might want to use a
[PropertyGroup](https://www.blender.org/api/blender_python_api_current/bpy.props.html#collection-
example) or look at defining custom [get and set
functions](https://www.blender.org/api/blender_python_api_current/bpy.props.html#get-
set-example).

Other options you have for storing values are adding properties to the scene
or object, you can also use module properties (an addon is a python module) or
use
[AddonPreferences](https://www.blender.org/api/blender_python_api_current/bpy.types.AddonPreferences.html).

