I need to dynamically control some properties, of which i have the data_path, in every frame of the animation using a python script. The obvious solution is to create a driver on the property, but I would like to still be able to edit the property (to set a fixed offset, basically).
Also, I want this rig to work with all (or most of) the object's properties, so I can't use an empty to store the drivers, because the empty might not have that property (also, is there a way to set the value of a property only knowing its data_path? that would solve everything...).
EDIT
As an example, I would like to control, for every frame of the animation, the obj.location
of my current object by using a python function pyFunction(self, target)
, that I declare in the script. To do that I need to create a driver with the pyFunction(self, target)
function in the expression field. So far so good.
However here I got stuck:
1) If I create the driver directly on the object's location property, I can't then move the object with the "G" hotkey or with the arrows (I could create 3 custom properties and point to them in the driver, but it's not very user friendly to change the object position using 3 separate sliders, hidden in the Custom Properties).
2) If I create the driver on a custom property, then I don't know how to change the location property: the driver controls the value of the Custom Property it is applied to, but not the value of the property I want to change. The main problem is that I don't know which properties are being targeted: in my script I have the data_path
of the properties I need to control (that I get from the object's fcurves), and I couldn't find anywhere a setValue(data_path)
function or whatever that allows me to change the value of a property in python, only knowing its data_path.
For example, if I need to control the influence value on a modifier of that object, I don't know how to make its value change with the Custom Property value, without having to add another driver on the desired property , which is the (1) problem all over again (or how to directly change its value inside the pyFunction)
In the screenshot, to control the rotation.x i need to create the driver, but then I can't manually rotate the object on the x axis with the "R" key (to create an offset that could be used to manually introduce variations in the object placement), and from the custom property obj["prop"] I don't know how to change the rotation value (using obj.rotation.x
or obj.rotation[0]
in the pyFunction is not a good solution, because I only know the data_path of the property and with most of them obj.data_path
doesn't work).
Also, don't worry about the error in the driver, pyFuntion is currently an empty function, mine works as expected, but it's very long and i didn't want to make things more complex than necessary...
Can you guys help me figure it out?