3
$\begingroup$

i'm working with stats show addon enter image description here enter image description here

But i really want to add checkbox for visibility here enter image description here

How to propetly get layout of this panel and add checkbox?

Upd

Solved by AFWS

Download final script

$\endgroup$
3
$\begingroup$

You would prolly have to edit the overlays file to get it in that location. Pretty easy to add settings to overlays though.



import bpy

def draw_stats_overlay(self, context):
    layout = self.layout
    win = context.window_manager

    layout.label(text="Show Stats")
    layout.prop(win, 'stats_toggle')


def register():
    bpy.types.VIEW3D_PT_overlay.append(draw_stats_overlay)

    bpy.types.WindowManager.stats_toggle = bpy.props.BoolProperty(
        name = "Toggle Stats",
        default = False
      )

def unregister():
    bpy.types.VIEW3D_PT_overlay.remove(draw_stats_overlay)
    del bpy.types.WindowManager.stats_toggle

if __name__ == "__main__":
    register()

enter image description here

Edit:

You might could do something like this.

Remove just the guides settings.

import bpy


bpy.utils.unregister_class(bpy.types.VIEW3D_PT_overlay_guides)

enter image description here

Add the settings back with the new setting.

import bpy

def guides_with_new_settings(self, context):
    layout = self.layout

    view = context.space_data
    scene = context.scene

    overlay = view.overlay
    shading = view.shading
    display_all = overlay.show_overlays

    col = layout.column()
    col.label(text="Guides")

    col = layout.column()
    col.active = display_all

    split = col.split()
    sub = split.column()

    row = sub.row()
    row_el = row.column()
    row_el.prop(overlay, "show_ortho_grid", text="Grid")
    grid_active = (
        view.region_quadviews or
        (view.region_3d.is_orthographic_side_view and not view.region_3d.is_perspective)
    )
    row_el.active = grid_active
    row.prop(overlay, "show_floor", text="Floor")

    if overlay.show_floor or overlay.show_ortho_grid:
        sub = col.row(align=True)
        sub.active = (
            (overlay.show_floor and not view.region_3d.is_orthographic_side_view) or
            (overlay.show_ortho_grid and grid_active)
        )
        sub.prop(overlay, "grid_scale", text="Scale")
        sub = sub.row(align=True)
        sub.active = scene.unit_settings.system == 'NONE'
        sub.prop(overlay, "grid_subdivisions", text="Subdivisions")

    sub = split.column()
    row = sub.row()
    row.label(text="Axes")

    subrow = row.row(align=True)
    subrow.prop(overlay, "show_axis_x", text="X", toggle=True)
    subrow.prop(overlay, "show_axis_y", text="Y", toggle=True)
    subrow.prop(overlay, "show_axis_z", text="Z", toggle=True)

    split = col.split()
    sub = split.column()
    sub.prop(overlay, "show_text", text="Text Info")
    sub = split.column()
    sub.prop(overlay, "show_cursor", text="3D Cursor")

    if shading.type == 'MATERIAL':
        col.prop(overlay, "show_look_dev")

    split = col.split()
    sub = split.column()
    sub.prop(overlay, "show_annotation", text="Annotations")

    #Add my new setting here
    sub = split.column()        
    sub.prop(context.window_manager, "stats_toggle", text="Toggle Stats")


def register():
    bpy.types.VIEW3D_PT_overlay.append(guides_with_new_settings)

    bpy.types.WindowManager.stats_toggle = bpy.props.BoolProperty(
        name = "Toggle Stats",
        default = False
      )

def unregister():
    bpy.types.VIEW3D_PT_overlay.remove(guides_with_new_settings)
    del bpy.types.WindowManager.stats_toggle


if __name__ == "__main__":
    register()

enter image description here

Addon example

bl_info = {
    "name": "Overlay Stats Test",
    "version": (0, 0, 2),
    "blender": (2, 82, 0),
    "location": "",
    "description": "",
    "warning": "",
    "wiki_url": "",
    "category": "3D View",
}

import bpy


#Guide settings with new setting added
def guides_with_new_settings(self, context):
    layout = self.layout

    view = context.space_data
    scene = context.scene

    overlay = view.overlay
    shading = view.shading
    display_all = overlay.show_overlays

    col = layout.column()
    col.label(text="Guides")

    col = layout.column()
    col.active = display_all

    split = col.split()
    sub = split.column()

    row = sub.row()
    row_el = row.column()
    row_el.prop(overlay, "show_ortho_grid", text="Grid")
    grid_active = (
        view.region_quadviews or
        (view.region_3d.is_orthographic_side_view and not view.region_3d.is_perspective)
    )
    row_el.active = grid_active
    row.prop(overlay, "show_floor", text="Floor")

    if overlay.show_floor or overlay.show_ortho_grid:
        sub = col.row(align=True)
        sub.active = (
            (overlay.show_floor and not view.region_3d.is_orthographic_side_view) or
            (overlay.show_ortho_grid and grid_active)
        )
        sub.prop(overlay, "grid_scale", text="Scale")
        sub = sub.row(align=True)
        sub.active = scene.unit_settings.system == 'NONE'
        sub.prop(overlay, "grid_subdivisions", text="Subdivisions")

    sub = split.column()
    row = sub.row()
    row.label(text="Axes")

    subrow = row.row(align=True)
    subrow.prop(overlay, "show_axis_x", text="X", toggle=True)
    subrow.prop(overlay, "show_axis_y", text="Y", toggle=True)
    subrow.prop(overlay, "show_axis_z", text="Z", toggle=True)

    split = col.split()
    sub = split.column()
    sub.prop(overlay, "show_text", text="Text Info")
    sub = split.column()
    sub.prop(overlay, "show_cursor", text="3D Cursor")

    if shading.type == 'MATERIAL':
        col.prop(overlay, "show_look_dev")


    split = col.split()
    sub = split.column()
    sub.prop(overlay, "show_annotation", text="Annotations")

    #Add my new setting here
    sub = split.column()        
    sub.prop(context.window_manager, "stats_toggle", text="Toggle Stats")


#Guide settings without new setting
def guides_without_new_settings(self, context):
    layout = self.layout

    view = context.space_data
    scene = context.scene

    overlay = view.overlay
    shading = view.shading
    display_all = overlay.show_overlays

    col = layout.column()
    col.label(text="Guides")

    col = layout.column()
    col.active = display_all

    split = col.split()
    sub = split.column()

    row = sub.row()
    row_el = row.column()
    row_el.prop(overlay, "show_ortho_grid", text="Grid")
    grid_active = (
        view.region_quadviews or
        (view.region_3d.is_orthographic_side_view and not view.region_3d.is_perspective)
    )
    row_el.active = grid_active
    row.prop(overlay, "show_floor", text="Floor")

    if overlay.show_floor or overlay.show_ortho_grid:
        sub = col.row(align=True)
        sub.active = (
            (overlay.show_floor and not view.region_3d.is_orthographic_side_view) or
            (overlay.show_ortho_grid and grid_active)
        )
        sub.prop(overlay, "grid_scale", text="Scale")
        sub = sub.row(align=True)
        sub.active = scene.unit_settings.system == 'NONE'
        sub.prop(overlay, "grid_subdivisions", text="Subdivisions")

    sub = split.column()
    row = sub.row()
    row.label(text="Axes")

    subrow = row.row(align=True)
    subrow.prop(overlay, "show_axis_x", text="X", toggle=True)
    subrow.prop(overlay, "show_axis_y", text="Y", toggle=True)
    subrow.prop(overlay, "show_axis_z", text="Z", toggle=True)

    split = col.split()
    sub = split.column()
    sub.prop(overlay, "show_text", text="Text Info")
    sub = split.column()
    sub.prop(overlay, "show_cursor", text="3D Cursor")

    if shading.type == 'MATERIAL':
        col.prop(overlay, "show_look_dev")

    split = col.split()
    sub = split.column()
    sub.prop(overlay, "show_annotation", text="Annotations")


def register():
    #Check to make sure overlay guides panel is registered
    if hasattr(bpy.types, 'VIEW3D_PT_overlay_guides'):
        #Unregister if overlay guides is registered        
        bpy.utils.unregister_class(bpy.types.VIEW3D_PT_overlay_guides)

    #Append guide settings with new setting when addon is registered    
    bpy.types.VIEW3D_PT_overlay.append(guides_with_new_settings)

    #Remove guide settings without new setting when addon is registered    
    bpy.types.VIEW3D_PT_overlay.remove(guides_without_new_settings)

    bpy.types.WindowManager.stats_toggle = bpy.props.BoolProperty(
        name = "Toggle Stats",
        default = False
      )

def unregister():
    #Remove guide settings with new setting when unregistering addon        
    bpy.types.VIEW3D_PT_overlay.remove(guides_with_new_settings)

    #Append guide settings without new setting when unregistering addon   
    bpy.types.VIEW3D_PT_overlay.append(guides_without_new_settings)

    del bpy.types.WindowManager.stats_toggle


if __name__ == "__main__":
    register()
```
$\endgroup$
  • $\begingroup$ Thank you! Just one question, is "append" function support to ability to add this prop in some defined place in this panel? $\endgroup$ – Alex Nov 14 '19 at 8:58
  • $\begingroup$ I edited my answer. You might could do it like I mentioned in my edit ,but append alone doesn't let you place in a certain location. $\endgroup$ – AFWS Nov 14 '19 at 12:58
  • $\begingroup$ Thank you again! I didn't even know about overlay guides. Thank you! $\endgroup$ – Alex Nov 14 '19 at 13:29
1
$\begingroup$

Well, this is not the solution but i just add checking if general overlays is on enter image description here enter image description here enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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