1

Is there a way to change a prop with an update def without calling the update def?

def update_prop(self, context):
    print ("update")
    if self.variable > 10:
        self.variable  = 10 #10 is a variable that changes in my code 
    #i want to set the prop without recalling the update
    else:
        print("else")



class Props(bpy.types.PropertyGroup):


    bpy.types.Object.variable  = bpy.props.IntProperty(
        name="variable",
        default=0,
        min=0,
        update=update_prop,
Syler
  • 824
  • 7
  • 20

1 Answers1

1

In the example, simply setting a max will do this for us

import bpy

def update_prop(self, context):
    print ("update")
    print(self.variable)


bpy.types.Object.variable  = bpy.props.IntProperty(
    name="variable",
    default=0,
    min=0,
    max=10,
    update=update_prop)

In python console

>>> C.object.variable = 22
update
10

>>> C.object.variable
10

If you wish to set a value and not fire an update, set the id property. A property defined via bpy.props for example ob.prop is stored as ob["prop"] once set to non default.

May be better to use a getter / setter method(s) Internal "get/set" function of property?

def update_prop(self, context):
    print ("update")
    self["variable"] = 4
    print(self.variable)


>>> C.object.variable = 22
update
4

>>> C.object.variable
4

Note this has been answered recenlty, couldn't find that one

batFINGER
  • 84,216
  • 10
  • 108
  • 233