How to assign FloatProperty, EnumProperty etc values through script I have been googling this and can't find an answer.
I defined a float property that creates a number spinner in my UI that allows me to move an object back and forth. I would like to clamp this value dynamically so I can't use the built-in FloatProperty clamp values. The code below should work, yet it seems to reset the value to the default value when it should get clamped.
def SetPos(self, context):
    self['left'] = Clamp(self['left'],0,1)

def register():
    bpy.types.Object.left = FloatProperty(name=&quot;left&quot;, default=0.34, unit=&quot;LENGTH&quot;, update=SetPos)

Another issue is that I don't see how to change an enumproperty through script. I can see in the python console it just assigns the string value to the prop like
bpy.context.object.myEnum = 'BLA'
but when I do an assignment like that myself, the UI does not update.
The update method will be invoked every time you try to modify the value of this property, like a callback function. The manual do warn about infinite loop when your update method constantly do something to props.
As your code, each time you update a new value, you set the value instead of check the value then set. So each time you invoke update method, blender will trigger another update function since you &quot;set&quot; value that is supervised by Blender system.
Not sure how to avoid this behavior but you might check the condition first then change the value:
def SetPos(self, context):
    if need_clamp(self['left']):
        self['left'] = Clamp(self['left'],0,1)
    # so next time this method will do nothing

Or just use setter and getter function:
Property Definitions (bpy.props) — Blender Python API