There are two buttons to register and deregister a panel with further operator
Each with own icon:
row.operator(“ui.register_operator”, text=“Button 1”, icon =“DISCLOSURE_TRI_RIGHT”)
row.operator(“ui.deregister_operator”, text=“Button 2”, icon =“DISCLOSURE_TRI_DOWN”)
Now i have two Buttons. But i want only 1 Button visible when it needed > if/else
Like the Snap Button in the header line > on/off
Thanks you!
I don´t how to use hastr(object, “Name”) !!!
I never was so deep in blender phyton!
It was my intention to clean up the space for my panels and pie menus.
because there are to many buttons for a simple on and off.
I had not thought that this can be so complicated.
…seems to be a next level!!!
This one is an example that i know for on/off. It use an BoolProperty.
But this changed only the color behind the icon and not the icon by itself.
import bpy
bpy.types.Scene.osc_circle = bpy.props.BoolProperty(default=False)
class SubLoc_CIRCLE():
"""De-/Register for Circle Panel"""
bl_region_type = 'UI'
bl_space_type = 'VIEW_3D'
@classmethod
def poll(cls, context):
return context.scene.osc_circle
class VIEW3D_Circle_Panel(SubLoc_CIRCLE, bpy.types.Panel):
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_label = "Circle"
def draw(self, context):
layout = self.layout
row = layout.row()
row.operator("mesh.primitive_circle_add")
class VIEW3D_Register_Panel(bpy.types.Panel):
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_label = "Register"
def draw(self, context):
layout = self.layout
row = layout.row()
#changed the color behind the icons
row.prop(bpy.context.scene, "osc_circle", text="Circle Panel", icon="MESH_CIRCLE")
def register():
bpy.utils.register_class(VIEW3D_Circle_Panel)
bpy.utils.register_class(VIEW3D_Register_Panel)
def unregister():
bpy.utils.unregister_class(VIEW3D_Circle_Panel)
bpy.utils.unregister_class(VIEW3D_Register_Panel)
if __name__ == "__main__":
register()
Well, you got a special case there. It’s usually a bit simpler:
import bpy
class RENDER_PT_custom_panel(bpy.types.Panel):
bl_label = "Custom Panel"
bl_idname = "RENDER_PT_custom_panel"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "object"
def draw(self, context):
layout = self.layout
ob = context.object
if ob.type == "EMPTY":
# an Empty object has no .data attribute we could get an icon for
layout.prop(ob, "name", icon="EMPTY_DATA")
else:
# use data type specific icon, or preview if available
layout.prop(ob, "name", icon_value=layout.icon(ob.data))
def register():
bpy.utils.register_module(__name__)
def unregister():
bpy.utils.unregister_module(__name__)
if __name__ == "__main__":
register()