assigning properties to randomize keyframes script

Hello
I’m writing a script that randomizes selected keyframes depends on their min and max values (if keyframes are equal then they would not change) and a threshold bar.
this is useful especially for repeating animations like cycled animations.
you can check it on
https://github.com/snotnose/blender_rigging_scripts/blob/master/randomize_keys.py

first I would be happy if people check it and tell me what they think, but just a warning it can crash sometimes :slight_smile:
not sure why since its relative a simple script but it seems to be related to the threshold property

now to some questions
I’m currently using property ID for the threshold that is assigned to the scene properties. I applied it outside of the classes and functions, in the beginning main part of the script, so that it won’t reset it every time i call the operator, but not sure if its a good idea. I was also wondering how can i setup the max and min values for this kind of property ID using python.
last time the script crashed blender was actually after i manually changed the min and max values in the property

I tried before that using properties inside the script operator for the UI panel instead of property IDs in the scene
something like
threshold = bpy.props.FloatProperty(name=“threshold”, description=“Threshold of keyframes”, default=0.1, min=0.0, max = 1.0) for the Randomize_Keys operator class

and then calling it from the panel using
props = layout.operator(“fcurves.random”)
layout.prop(props, “threshold”, slider = True)

but the slider on the ui was completly static and it wasn’t possible to change its value.
any ideas how to solve this, or would it be better to stay with property IDs assigned to the scene?
I noticed there are different kind of properties in blender as well as property groups, still trying to figure out their uses.

appreciate any tips

Tal

In your draw() method, the code should look like this:

layout.prop(self, "threshold", slider=True)

self refers to the operator instance. The property “threshold” needs to be declared in the operator class itself and should remember the last used value unless you specify the option {‘SKIP_SAVE’}.

Danke für den Antwort :wink:
I eventually applied the property using bpy.types.Scene.threshold = bpy.props.FloatProperty(name=“threshold”, description=“Threshold of keyframes”, default=0.1, min=0.0, max = 1.0)

it seems to work better since i could set the max and min values. and hopefully it`s also more stable now.

regarding your answer
my draw call is on a separated class used only for the panel, so i guess “self” wouldnt work in this case. or maybe i could define everything in one class instead of using one class for operator and one class for the panel?

If you put a property in a panel, that property must be either an ID property or bpy.props on e.g. bpy.types.WindowManager, bpy.types.Scene, bpy.types.Object or similar.

Operator properties can’t be placed in panels, you need to duplicate every property (one prop in the operator itself, one on bpy.types.* and then forward the property from the panel to the operator).