Python in Blender 4.0

Hi All,

The Python code was not working for me on Blender 4.0 as there are no layers on this version anymore, it was replaced by Bone Collections. I know this is not a Python focused course, but its still fun to mess with it and useful in animation I think. So after fighting with it a bit I got it to work, replacing the following part of the code: 

        #Layers

        row = col.row()
        row.prop(context.active_object.data, "layers", index=0, toggle=True, text="Head")
        row = col.row()
        row.prop(context.active_object.data, "layers", index=1, toggle=True, text="Claw")
        row = col.row()
        row.prop(context.active_object.data, "layers", index=16, toggle=True, text="Root")

With:

        #Layers

        row = col.row()
        row.prop(context.active_object.data.collections["Root"], "is_visible",toggle=True, text="Root")
        row = col.row()
        row.prop(context.active_object.data.collections["Clamp"], "is_visible",toggle=True, text="Clamp")
        row = col.row()
        row.prop(context.active_object.data.collections["Base"], "is_visible",toggle=True, text="Base")
        row = col.row()
        row.prop(context.active_object.data.collections["MCH"], "is_visible",toggle=True, text="MCH")

For this to work, instead of having the bones in layers, the collection names need to match context.active_object.data.collections["Root"]. So the bone collection name needs to be Root in this case (or match in code whatever you are using).

Control_rig.png


  • 🤘🏼
  • 👍🍪
1 love
Reply
  • Adrian Bellworthy replied

    Nice mmauroornelas
    Thanks for sharing!

    2 loves
  • Wayne Dixon replied

    Oh thanks for reminding me about this Mauro.

    It's been on my to do list for a while now and this week is when I am doing all those little update things

    1 love
  • Wayne Dixon replied

    Updated complete,  thanks again for the reminder Mauro.