I have a string property, when it is updated it runs a function which runs an operator, the operator clears the string at the end to reset it. This makes the function (string_update) loop to infinite recursion. As I understand, order of events should be:

update string
run function once
run operator
finish

What am I missing?

import bpy


def string_update(self, context):
    bpy.ops.test.test()
    print("Ran")
    return None


class test_vars(bpy.types.PropertyGroup):
    test_update_string = bpy.props.StringProperty(
        name = "",
        default = "",
        update = string_update
        )


class Test_Op(bpy.types.Operator):
    """"""
    bl_idname = "test.test"
    bl_label = "test"

    def execute(self, context):
        bpy.context.scene.test_vars.test_update_string = ""

        return {'FINISHED'}


def register():
    bpy.utils.register_module(__name__)
    bpy.types.Scene.test_vars = bpy.props.PointerProperty(type = test_vars)


def unregister():
    bpy.utils.unregister_module(__name__)
    bpy.utils.unregister_class(test_vars)
    del bpy.types.Scene.test_vars
  • 2
    Every time you update the prop, it calls the update method. Your update method calls an operator that updates the prop ... which calls the update method which calls the operator which calls the update method which calls the operator..... – batFINGER Aug 10 at 7:26
  • Wow i'm an idiot, so obvious haha thank you – Way2Close Aug 10 at 22:48
up vote 2 down vote accepted

In the execute method of the Test_Op class, you should access the property like this to prevent the update method from being called:

bpy.context.scene.test_vars["test_update_string"] = ""
  • That works perfectly thank you so much, would you mind explaining why this doesn't trigger the update? – Way2Close Aug 10 at 22:54
  • 2
    @Way2Close The get set example emulates ("This is what the RNA would do internally") the way blender properties use custom properties as storage. – batFINGER Aug 11 at 4:18

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.