0
$\begingroup$

I want to place this panel:

![enter image description here

In this Operator

enter image description here

import bpy
from bpy.types import Operator
from bpy.props import *

class OBJECT_OT_viewport_display(Operator):
    bl_label='Viewport Display'
    bl_idname='object.viewport_display'

    tabs: EnumProperty(
        items=[
            ('TOOLS', '','', 'TOOL_SETTINGS', 0),
            ('OBJECT', '','', 'OBJECT_DATA', 1),
            ('DATA', '','', 'MESH_DATA', 2),
            ('MOD', '','', 'MODIFIER', 3),
        ],
        default='OBJECT'
    )

    def draw(self, context):
        layout = self.layout
        layout.use_property_decorate = False
        layout.label(text='Preferences')
        split = layout.split(factor=0.1, align=True)
        col = split.column(align=True)
        col.scale_x = 1.4
        col.scale_y = 1.4
        col.prop(self, 'tabs', expand=True, icon_only=True)
        col.separator()

        col = split.column()
        col.scale_x = 1.2
        col.scale_y = 1.2

        if self.tabs == 'OBJECT':
            # panel here

    def execute(self,context):
        return {'FINISHED'}
    def invoke(self,context,event):
        return context.window_manager.invoke_popup(self)
$\endgroup$
0

1 Answer 1

4
$\begingroup$

Have a look into the source

With Developer Extras enabled in the preferences, you can just right-click any property of that panel and press Edit Source. This may open up properties_object.py in the text editor and jumps to the respective line automatically, which makes it easy to copy/paste the properties you want onto your custom panel. See below.

If you open the text editor and the source is not visible, (happens in 2.93.5, sometimes), simply select it using the dropdown menu:

selecting the python file in the edit window

class OBJECT_PT_display(ObjectButtonsPanel, Panel):
    bl_label = "Viewport Display"
    bl_options = {'DEFAULT_CLOSED'}
    bl_order = 10

    def draw(self, context):
        layout = self.layout
        layout.use_property_split = True

        obj = context.object
        obj_type = obj.type
        is_geometry = (obj_type in {'MESH', 'CURVE', 'SURFACE', 'META', 'FONT', 'VOLUME', 'HAIR', 'POINTCLOUD'})
        has_bounds = (is_geometry or obj_type in {'LATTICE', 'ARMATURE'})
        is_wire = (obj_type in {'CAMERA', 'EMPTY'})
        is_empty_image = (obj_type == 'EMPTY' and obj.empty_display_type == 'IMAGE')
        is_dupli = (obj.instance_type != 'NONE')
        is_gpencil = (obj_type == 'GPENCIL')

        col = layout.column(heading="Show")
        col.prop(obj, "show_name", text="Name")
        col.prop(obj, "show_axis", text="Axis")

        # Makes no sense for cameras, armatures, etc.!
        # but these settings do apply to dupli instances
        if is_geometry or is_dupli:
            col.prop(obj, "show_wire", text="Wireframe")
        if obj_type == 'MESH' or is_dupli:
            col.prop(obj, "show_all_edges", text="All Edges")
        if is_geometry:
            col.prop(obj, "show_texture_space", text="Texture Space")
            col.prop(obj.display, "show_shadows", text="Shadow")
        col.prop(obj, "show_in_front", text="In Front")
        # if obj_type == 'MESH' or is_empty_image:
        #    col.prop(obj, "show_transparent", text="Transparency")
        sub = layout.column()
        if is_wire:
            # wire objects only use the max. display type for duplis
            sub.active = is_dupli
        sub.prop(obj, "display_type", text="Display As")

        if is_geometry or is_dupli or is_empty_image or is_gpencil:
            # Only useful with object having faces/materials...
            col.prop(obj, "color")

        if has_bounds:
            col = layout.column(align=False, heading="Bounds")
            col.use_property_decorate = False
            row = col.row(align=True)
            sub = row.row(align=True)
            sub.prop(obj, "show_bounds", text="")
            sub = sub.row(align=True)
            sub.active = obj.show_bounds or (obj.display_type == 'BOUNDS')
            sub.prop(obj, "display_bounds_type", text="")
            row.prop_decorator(obj, "display_bounds_type")

Demo based on your code

enter image description here

import bpy

from bpy.types import Operator
from bpy.props import EnumProperty

class OBJECT_OT_viewport_display(Operator):
    bl_label='Viewport Display'
    bl_idname='object.viewport_display'

    tabs: EnumProperty(
        items=[
            ('TOOLS', '','', 'TOOL_SETTINGS', 0),
            ('OBJECT', '','', 'OBJECT_DATA', 1),
            ('DATA', '','', 'MESH_DATA', 2),
            ('MOD', '','', 'MODIFIER', 3),
        ],
        default='OBJECT'
    )

    def draw(self, context):
        layout = self.layout
        layout.use_property_decorate = False
        layout.label(text='Preferences')
        split = layout.split(factor=0.1, align=True)
        col = split.column(align=True)
        col.scale_x = 1.4
        col.scale_y = 1.4
        col.prop(self, 'tabs', expand=True, icon_only=True)
        col.separator()

        col = split.column()
        col.scale_x = 1.2
        col.scale_y = 1.2

        if self.tabs == 'OBJECT':
            col.prop(context.object, "show_wire")
            col.prop(context.object, "show_all_edges")
            col.prop(context.object, "show_name")
            col.prop(context.object, "show_axis")
            # ...

    def execute(self, context):
        return {'FINISHED'}
    
    def invoke(self,context,event):
        return context.window_manager.invoke_popup(self)


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


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


if __name__ == "__main__":
    register()

    # test call
    #bpy.ops.object.viewport_display()
$\endgroup$
1
  • $\begingroup$ @brockmann: Thank you! $\endgroup$
    – Chris
    Nov 1, 2021 at 7:53

Not the answer you're looking for? Browse other questions tagged .