# Operator and properties?

in 2.82 is there a way to make a property become a min or max for another property

thanks
happy bl

hy,
With a get/set it’s posible, but I don’t know how to do it when the v value is entered from a panel entry. If anyone knows I would be curious to know how to do it.

``````class GetSet:
def __init__(self, init = 0):
self._prop = init
self._max = 20
self._mini = 10

# getter method
def get_prop(self):
return self._prop

# setter method
def set_prop(self, v):

if v >= self._max :
self._prop = self._max
elif v <= self._mini :
self._prop = self._mini
else :
self._prop = v

gt = GetSet()

# setting
gt.set_prop(5)

# retrieving property using getter
print(gt.get_prop())

print(gt._prop)
``````

source

if there is something like that in a blender operator
it would be interesting

I have some properties in operator
but would like to make one property a limit on another property

problem is that property are defined when class is created not afterward unless there is another way around !

but there might be a way around with some Hack !

Ex:

one property might be for a parabola curve = the SAG or height
but then you got another prop for the span

but there is a limit on the ratio of Sag / Span
and should be check after entering a value in the Span value or the opposite to make certain it is a valid value

thanks
happy bl

There’s an example here, but it can’t be linked to a props or a class.

Getter/Setter Example

I will test this new way and see if it can work

thanks
happy bl

It’s an interesting question, the beginning of a solution.

``````import bpy

def get_int(self):
return self["testprop"]

def set_int(self, v):
#self["testprop"] = value
if v > 100 :
self["testprop"] = 99
elif v < 20 :
self["testprop"] = 21
else :
self["testprop"] = v

bpy.types.Scene.test_int = bpy.props.IntProperty(name="bones", default=0, get=get_int, set=set_int)
#bpy.types.WindowManager.bones_nbr = bpy.props.IntProperty(name="bones", default=0)

#scene = bpy.context.scene
#scene.test_int = 100
#print('test_int:', scene.test_int)

class InterGetSetExemple (bpy.types.Panel) :

bl_label = "Get_Set_exemple..."
bl_idname = "VIEW_3D_PT_GET_SET_EXEMPLE"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = "get set exemple"
bl_description = "get set property test"

def draw(self, context) :

l = self.layout
c=l.column(align = True)

#c.prop(context.object, "name")
c.prop(bpy.context.scene, "test_int")

#obj = context
def register() :
bpy.utils.register_class(InterGetSetExemple)

def unregister() :
bpy.utils.unregister_class(InterGetSetExemple)

if __name__ == "__main__" :
register()
``````

@[megablast2

very interesting way for prop !

is it possible to add a label or string in the definition
to show the error made may be ?

thanks
happy bl

I don’t know about that, but yeah, I guess so. Actually I was way too far gone, the solution is much simpler than that.

``````import bpy

bpy.types.WindowManager.v_max = bpy.props.IntProperty(name="vmax", default=100)
bpy.types.WindowManager.v_mini = bpy.props.IntProperty(name="vmini", default=5)
bpy.types.WindowManager.test_int = bpy.props.IntProperty(name="value_test", default=0)

class InterGetSetExemple (bpy.types.Panel) :

bl_label = "Get_Set_exemple..."
bl_idname = "VIEW_3D_PT_GET_SET_EXEMPLE"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = "get set exemple"
bl_description = "get set property test"

def minimax(self) :
if bpy.context.window_manager.test_int > bpy.context.window_manager.v_max :

bpy.context.window_manager.test_int = bpy.context.window_manager.v_max

elif bpy.context.window_manager.test_int < bpy.context.window_manager.v_mini :

bpy.context.window_manager.test_int = bpy.context.window_manager.v_mini

def draw(self, context) :

l = self.layout
c=l.column(align = True)
#c=l.row(align = False)

c.prop(bpy.context.window_manager, "v_mini")
c.prop(bpy.context.window_manager, "test_int")
c.prop(bpy.context.window_manager, "v_max")

self.minimax()

def register() :
bpy.utils.register_class(InterGetSetExemple)

def unregister() :
bpy.utils.unregister_class(InterGetSetExemple)

if __name__ == "__main__" :
register()
``````

Happy bl

have not use this window manager things prop

can you explain what it is and what it does ?

have to think how to use this for my addon with operator!

be back may be tomorrow

thanks
happy bl

It’s for the use interface, then I can’t explain all the subtleties.