Anda di halaman 1dari 2

class OBJECT_PT_test1(bpy.types.

Panel):
'''
Class to represent a testpanel in Blender.
'''
bl_space_type = "PROPERTIES" #Window type where the panel will be shown
# Valid bl_space_type: ('EMPTY', 'VIEW_3D', 'GRAPH_EDITOR', 'OUTLINER',
'PROPERTIES', 'FILE_BROWSER', 'IMAGE_EDITOR', 'INFO', 'SEQUENCE_EDITOR', 'TEXT_E
DITOR', 'AUDIO_WINDOW', 'DOPESHEET_EDITOR', 'NLA_EDITOR', 'SCRIPTS_WINDOW', 'TI
MELINE', 'NODE_EDITOR', 'LOGIC_EDITOR', 'CONSOLE', 'USER_PREFERENCES')
bl_region_type = "WINDOW"
# Valid bl_region_type: ('WINDOW', 'HEADER', 'CHANNELS', 'TEMPORARY', 'U
I', 'TOOLS', 'TOOL_PROPS', 'PREVIEW')
bl_context = "object" #Where to show panel in space_type
bl_label = "Test Panel 1" #Panel name displayed in header
def draw_header(self, context):
'''
Function used by blender to draw the header of the panel.
'''
layout = self.layout #Panel layout to draw on
layout.label(text="123", icon='RADIO') #Shows a icon and extra t
ext before the panel title (bl_label)
def draw(self, context):
'''
Function used by blender to draw the panel.
'''
obj = bpy.context.active_object #Get active object
layout = self.layout #Panel layour to draw on
row = layout.row() #Create new row
row.label(text="The currently selected object is: " + obj.name)
row = layout.row() #Create new row
if obj.type == 'MESH':
row.label(text="It is a mesh containing " + str(len(obj.
data.verts)) + " vertices.")
else:
row.label(text="it is a " + obj.type.capitalize() + ".")
row = layout.row() #Create new row
row.alignment = 'RIGHT'
if obj.selected:
row.operator("slctbtn", text="Deselect")
else:
row.operator("slctbtn", text="Select")
class OBJECT_OT_selectbtn(bpy.types.Operator):
'''
Class to represent a button that can be used to deselect an object in bl
ender.
'''
bl_label = "slctbtn" #Button label
bl_idname = "slctbtn" #Name used to refer to this operator
bl_description = "Deselect the active object" # tooltip
def invoke(self,context,event):
'''
Function used to process a click on the deselect button.
'''
if bpy.context.object.selected:
bpy.context.object.selected = False
else:
bpy.context.object.selected = True
return{'FINISHED'}
bpy.types.register(OBJECT_PT_test1) #Register OBJECT_PT_test1 in blender
bpy.types.register(OBJECT_OT_selectbtn) #Register OBJECT_OT_selectbtn in blender

Anda mungkin juga menyukai