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?
- 1
- 1
1 Answers
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)
- 84,216
- 10
- 108
- 233
-
Thanks for the answers. I'm still a beginner at scripting, I guess I'll need to learn more :) – Geovanie Orcullo Feb 24 '21 at 12:26

ob["switch"]not so easy... with abpy.types.Object.switch = bpy.props.IntPropertyimagine its doable. Is this how you have defined the prop? – batFINGER Feb 24 '21 at 11:02