I'm tryng to write a script that adds a driver to some bones automatically. But I'm facing some problems with the property "hide". I want to add the driver into the property "Hide" (Inside Viewport display of a bone). All the rest of the code seems to be working correctly.
This is my code:
import bpy
# Set the name of the armature and list of bones
armature_name = "RIG-Luana"
bone_names = [
"STR-shorts_bot_tweak1.L",
"STR-shorts_bot_tweak2.L",
"STR-shorts_bot_tweak3.L",
"STR-shorts_bot_tweak4.L",
"STR-shorts_bot_tweak1.R",
"STR-shorts_bot_tweak2.R",
"STR-shorts_bot_tweak3.R",
"STR-shorts_bot_tweak4.R"
]
# Set up the driver expression
driver_expression = 'roupa != 0'
# Loop through each bone name and apply the driver
for bone_name in bone_names:
bone = bpy.data.objects[armature_name].pose.bones[bone_name]
# Add the driver
driver = bone.driver_add("hide").driver
# Add the variable to the driver
var = driver.variables.new()
var.name = "roupa"
var.targets[0].id_type = 'OBJECT'
var.targets[0].id = bpy.data.objects[armature_name]
var.targets[0].data_path = 'pose.bones["Properties_Character_Luana"]["Roupa"]'
# Set up the driver type and expression
driver.type = 'SCRIPTED'
driver.expression = driver_expression
First I made a test adding the driver to the property of the scale of the object, and it works. But I don't know how to acess the property "hide" of the bone. Any ideia how to fix the code? Thanks in advance for any help!