# define the prop of a driver with a script?

I'm trying to make a driver that gets the restrict viewport (hide property) and restrict rendering (hide_render property) properties from another object, as explained here.

The above picture only shows a driver on the hide_render property, even if I did try with the hide property too.

• hide_render : seems to work (objets are hidden when rendered);
• hide : the outliner icons are not updated nor the objects are hidden in the viewport. Probably related to this bug ?

This is a known limitation of the current dependency graph (depsgraph).

Currently, the depsgraph can only represent and schedule up relationships on datablock level. Drivers are actually evaluated on the object level, and all in one go before any other data on the object gets evaluated. As a result, for drivers which operate on bones within the same armature that they read values from, the drivers are only able to see the result of the previous time that the pose was evaluated. In other words, you'll find a bit of lag in the updates.

2. Script to fetch a parent ?

While I have coding skills, I don't know anything about Python, and it's the first time I'm thinking about using a script in Blender.

Rather than setting manually an object for the "prop" value of the driver, is it possible to add a script that would fetch the object's parent ?

That script should get the closest parent having keyframes for the desired property.

Firstly, quite possibly, the issue re viewport via render is you need to drive the hide property as well. Simply right click copy on view_render driver, and right-click paste driver into the hide field to emulate hide_render behaviour.

A driver can only return a float (decimal) or integer (or bool (True, False)) type, therefore you can't return object references or name strings. What you can do though, is pass the name of an object to a driver expression.

To get a property from a parent using a driver.

def get_parent_property(name, property, default):
object = bpy.data.objects.get(name)
parent = object.parent
return getattr(parent, property, default)


The driver expression get_parent_property("Cube", "hide_render", True) will return the hide_render property of "Cube"'s parent object, or the default value True in the case there is no parent.