1
$\begingroup$

I'm currently creating some script to automate a cloth rig setup.

In the process I'm adding a custom float property to an empty and use it in a driver. It's a concept I wish to reuse for other purposes but had not figured out how to have that completely (and automatically) working yet. Unless I manually modify the custom property value in the UI and then update the driver dependencies, the driver will not pick the custom float property.

Here is an example that assume you have a Cube and a Sphere in the scene.

import bpy
source_obj = bpy.data.objects["Cube"]
source_prop = "influence"
source_obj[source_prop] = 1.0
target_obj = bpy.data.objects["Sphere"]
target_prop = "location"
axis_index = 2
driver = target_obj.driver_add(target_prop, axis_index).driver
v = driver.variables.new()
v.name = "var"
v.type = "SINGLE_PROP"
v.targets[0].id = source_obj
quote = "\""
v.targets[0].data_path = "[" + quote + source_prop + quote + "]"
driver.expression = "var"

If you run that you will see that the driver don't work.

If you then go modify the value of the custom property through the UI by selecting the Cube and setting the influence value to 0.5 for example.

enter image description here

Then go update the Sphere driver dependencies (and I really just mean pressing the Update Dependencies button), it then work as intended.

enter image description here

Does anybody know what I need to do to have that working programmatically without having to touch the UI? (In the case I want to add, let's say 300 custom floats).

bpy.ops.wm.properties_edit() is what is triggered when you edit the property, but if you try to add that to your script it will give you an error: Direct execution not supported.

You can apparently add properties to a whole class, but it's not what I want to do. I want to add custom property to specific empty only.

I'm using Blender 2.8 by the way

Thanks

H.

$\endgroup$

1 Answer 1

1
$\begingroup$

Ok I have figured out a solution.

If I save the file and reopen it, the drivers are working perfectly fine with what I have done with my script.

Might be an update issue with the property UI I don't know.

I could add a save/reopen at the end of the script, that would be an easy work around for now.

If anybody know how to instantly make it works please do tell so. Posting my answer anyway in the case someone else is encountering the same driver issue.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .