I added a custom property to an object with an integer value and a max of 3. Is there any way to loop the value? I want it to return to the value of 0 after 3. Is it possible?enter image description here

enter image description here

  • $\begingroup$ With a custom property ob["switch"] not so easy... with a bpy.types.Object.switch = bpy.props.IntProperty imagine its doable. Is this how you have defined the prop? $\endgroup$
    – batFINGER
    Feb 24 at 11:02
  • $\begingroup$ Could you drive it from another custom property, using a scripted expression such that switch = input%3? $\endgroup$
    – Nathan
    Feb 24 at 18:28

Setter / Getter and modulus.

enter image description here Zoomed in test. Can see 4 pop up when holding mouse down and sliding, but the setter turns 4 to 0

Internal "get/set" function of property?

How can I change IntProperty default value stored within PropertyGroup?

Is There a Way to Change a Prop with an Update Def without Calling the Update Def?

If we set up an int property with a getter and setter can assure it remains in a certain range. For this case have set the min to 0 and max to 4, but if the property is set to 4 it reverts to zero, using the modulus operator

value = value % 4  

ie the integer remainder when divided by four. This is stored in the file as a custom property emulating how properties work.

Set the default value in the getter, I've used 0

Test Code.

import bpy

from bpy.props import IntProperty

def get_int(self):
    return self.get("test", 0)

def set_int(self, value):
    self["test"] = value % 4

bpy.types.Object.test = IntProperty(
def draw(self, context):
    layout = self.layout
    ob = context.object
    layout.prop(ob, "test")

# tacked onto object props transform panel to test.    
  • $\begingroup$ Thanks for the answers. I'm still a beginner at scripting, I guess I'll need to learn more :) $\endgroup$ Feb 24 at 12:26

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.