I hope somebody can help me. I want to have a IntProperty in Blender where I can set only even numbers (0,2,4,6..)
I know that the Syntax for the Float Property is the following:
bpy.types.Scene.MyFloat = FloatProperty(
name='FLoat',
default=1,
min=0,
step=200,
)
But with this code in the GUI I can still choose e.g. "4.2" as a value so that isn't a appropriate solution to my problem.
The Syntax for the IntProperty in this way would be like this:
bpy.types.Scene.MyInt = IntProperty(
name='Int',
default=1,
min=0,
step=2,
)
doesn't work.
Does anyone knows if there is a code for choosing only even numbers and how it is?
In the meantime I have found a solution for my problem.
Just use the Floatproperty with a stepsize of 200 and define a update function which then checks if the adjusted value is even - if not you force the conversion to the next near even number. The code then looks like that:
bpy.types.Scene.even_number= FloatProperty(
name='Even Numbers',
description='Just even numbers are possible',
default = 10,
min = 0,
max = 90,
step = 200,
update = update_even_numbers
)
def update_even_numbers(scene, context):
if bpy.context.scene.framestep % 2 == 0:
print('Even number')
else:
x = bpy.context.scene.even_number
bpy.context.scene.even_number= round(x/2)*2
Maybe if somebody else is looking for a solution this one will help him
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With