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

What am I missing?

import bpy

def string_update(self, context):
    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.types.Scene.test_vars = bpy.props.PointerProperty(type = test_vars)

def unregister():
    del bpy.types.Scene.test_vars
  • 2
    $\begingroup$ 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..... $\endgroup$ – batFINGER Aug 10 '18 at 7:26

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"] = ""
|improve this answer|||||
  • $\begingroup$ That works perfectly thank you so much, would you mind explaining why this doesn't trigger the update? $\endgroup$ – Way2Close Aug 10 '18 at 22:54
  • 2
    $\begingroup$ @Way2Close The get set example emulates ("This is what the RNA would do internally") the way blender properties use custom properties as storage. $\endgroup$ – batFINGER Aug 11 '18 at 4:18

Your Answer

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

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