# How to loop values on Custom properties

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?

• 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? Feb 24 at 11:02
• Could you drive it from another custom property, using a scripted expression such that switch = input%3? Feb 24 at 18:28

## 1 Answer

Setter / Getter and modulus.

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(
min=0,
max=4,
get=get_int,
set=set_int,
)

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

# tacked onto object props transform panel to test.
bpy.types.OBJECT_PT_transform.prepend(draw)

• Thanks for the answers. I'm still a beginner at scripting, I guess I'll need to learn more :) Feb 24 at 12:26