4
$\begingroup$

this is the show_bones property I am talking about

This is show_bones

I want Show_bones to be in my panel, I tried many times to get it working. here was my attempts,

row.prop(sce, "Layout.overlay.show_bones")

row.prop(sce, "View3DOverlay.show_bones")
$\endgroup$
1
  • 1
    $\begingroup$ Where your custom panel is located? $\endgroup$
    – pyCod3R
    Jan 27 at 6:57

2 Answers 2

8
$\begingroup$

The python tooltip is really misleading. The bpy.types.View3DOverlay object is actually a member of bpy.types.SpaceView3D.

Also the bpy.types.UILayout.prop method only support direct attribute access, not chained ones so you have to provide the direct holder of the property as a first argument, then the name of the property as a string.

You can access the property using this method :

https://blender.stackexchange.com/a/162466/86891

In an actual script :

import bpy


class HelloWorldPanel(bpy.types.Panel):
    """Creates a Panel in the Scene properties window"""
    bl_label = "Hello World Panel"
    bl_idname = "OBJECT_PT_hello"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "scene"

    def draw(self, context):
        area = next(a for a in context.screen.areas if a.type == "VIEW_3D", None)
        if area is None:
            return
        space = area.spaces.active
        overlay = space.overlay
        self.layout.prop(overlay, "show_bones")

def register():
    bpy.utils.register_class(HelloWorldPanel)


def unregister():
    bpy.utils.unregister_class(HelloWorldPanel)


if __name__ == "__main__":
    register()

Result :

enter image description here

$\endgroup$
3
  • $\begingroup$ That explains why I couldn't get it to work, thank you Gorgious. $\endgroup$ Jan 27 at 7:33
  • 1
    $\begingroup$ To keep things organized, consider to post your answer here: blender.stackexchange.com/questions/131465/… $\endgroup$
    – pyCod3R
    Jan 27 at 8:15
  • $\begingroup$ @pyCod3R woops didn't see that one. Thanks for bringing it up $\endgroup$
    – Gorgious
    Jan 27 at 8:21
5
$\begingroup$

If your panel is located in 3d View, you can access all overlay properties via Context.space_data. https://docs.blender.org/api/current/bpy.types.View3DOverlay.html#bpy.types.View3DOverlay

enter image description here

import bpy

class HelloWorldPanel(bpy.types.Panel):
    """Creates a Panel in the Object properties window"""
    bl_label = "Hello World Panel"
    bl_idname = "OBJECT_PT_hello"
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'UI'

    def draw(self, context):
        layout = self.layout
        space = context.space_data
        row = layout.row()
        row.prop(space.overlay, "show_bones", toggle=True, icon='BONE_DATA')
        row.prop(space.overlay, "show_cursor", toggle=True, icon='PIVOT_CURSOR')
        row.prop(space.overlay, "show_edge_crease", toggle=True, icon='EDGESEL')
        # ...
        
def register():
    bpy.utils.register_class(HelloWorldPanel)

def unregister():
    bpy.utils.unregister_class(HelloWorldPanel)

if __name__ == "__main__":
    register()
$\endgroup$
0

Not the answer you're looking for? Browse other questions tagged or ask your own question.