Dynamic constraints for properties

Hello everyone,

I am currently modelling an item which has the properties Length as well as Range. My requirement is that Range can only be two thirds of Width. I know how to set hardcoded constraints (just write sth. like “0.0-10.0” into the textfield) but this solution is not what I need.

I created the properties as follows:

prop_length = comp.getProperty("Length")
prop_range = comp.getProperty("Range")

if not prop_length:
  prop_length = comp.createProperty(VC_REAL, "Length", VC_PROPERTY_LIMIT)
  prop_length.MinValue = 0
  prop_length.MaxValue = sys.maxint
  prop_length.Value = 45
if not prop_range:
  prop_range = comp.createProperty(VC_REAL, "Range", VC_PROPERTY_LIMIT)
  prop_range.MinValue = 0
  prop_range.MaxValue = 2/3 * prop_length.Value
  prop_range.Value = 20

Does anyone know how to fix this issue?

Thanks in advance

Hi JakobHerk,

This is classical type issue. Dividing integer with integer results to… integer. Meaning that 2/3 = 0, because int(0.67) = 0 or 3/4 = 1, because int(1.33) = 1.

Dividing by a float will result to float. So change the code to:

2/3.0 * prop_length.Value

I would add parenthesis around division since I don’t mean to divide with the product of 3.0 and prop_lenght.Value, just to make it easier to read:

(2/3.0) * prop_length.Value

Otherwise it should be good to go!

P.S To make it “perfect” add OnChanged event for the prop_length and adjust the MaxValue of prop_range in the event handler.