I have a popup that can allow the user the set a value. I can see that the value is getting set correctly as it reports it to the console. However after the function that calls the Operator completes how is it possible to access values that we set inside the Operator class?

class OpenBrowser(bpy.types.Operator):
    bl_idname = "open.browser"
    bl_label = "Select Path"
    bl_options = {"REGISTER", "UNDO"}

    directory = StringProperty(subtype="DIR_PATH") 
    cancel_search = BoolProperty(
        name="Cancel Search",
        description="If no further images are to be found",

    def execute(self, context):
        display = "dirpath=" + self.directory  
        return {'FINISHED'}

    def invoke(self, context, event): 
        wm = context.window_manager
        return {'RUNNING_MODAL'}  


How do I access the value that was set for directory following the the completion of the last function call?


2 Answers 2


Window Manager keeps track of registered operators

Lets say we add a property to the simple operator template, and make it register - undo

class SimpleOperator(bpy.types.Operator):
    bl_idname = "object.simple_operator"
    bl_label = "Simple Object Operator"
    bl_options = {'REGISTER', 'UNDO'}
    xxx : bpy.props.StringProperty(default="foo")

Invoke it from the UI

bl_options = {'REGISTER', 'UNDO'}

Then in python console use WindowManager.operator_properties_last

>>> op = C.window_manager.operator_properties_last("object.simple_operator")
>>> op.xxx

There is a also a collection of operators used in WindowManager.operators If the operator has register undo we can find the value used, for example having invoked bpy.ops.object.duplicate_move() in the UI

>>> C.window_manager.operators['
>>> op = C.window_manager.operators['OBJECT_OT_duplicate_move']
>>> # how much did it move
>>> op.macros['
>>> op.macros['TRANSFORM_OT_translate'].properties['value'].to_list()
[0.7582358121871948, 1.8491952419281006, 0.10750504583120346]

The collection is keyed using the idname

>>> bpy.ops.object.duplicate_move.idname()

Note that the value of properties here will be the as used only if the operator has 'UNDO' option, otherwise it will return the default value of the property.

Note the template class name is SimpleOperator but really should be OBJECT_OT_simple_operator to match its id name "object.simple_operator" as per the naming convention

From https://blender.stackexchange.com/a/159444/15543


Best I can think of is:

Register new property:

bpy.types.Scene.directory = bpy.props.StringProperty()

and copy contents of Your self.directory to this property while executing (in execute method):

context.scene.directory = self.directory

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .