Code: Select all
import bpy
import sys
class UIPanel(bpy.types.Panel):
bl_label = 'Example Panel'
bl_space_type = "VIEW_3D" #Defines the location of Panel
bl_region_type = "UI"
def draw(self, context):
layout = self.layout
# To register UIPanel
bpy.utils.register_module(__name__)
Code: Select all
import bpy
import sys
class UIPanel(bpy.types.Panel):
bl_label = 'Example Panel'
bl_space_type = "VIEW_3D" #Defines the location of Panel
bl_region_type = "UI"
def draw(self, context):
layout = self.layout
row = layout.row()
row.label ('This is your first row')
row = layout.row()
row.operator('hello.hello')
class OBJECT_OT_HelloButton(bpy.types.Operator):
bl_idname = "hello.hello" #reference in code
bl_label = "Say Hello" # text appear on the button
def execute(self, context):
# Define some actions here
return {'FINISHED'}
# To register UIPanel
bpy.utils.register_module(__name__)
Code: Select all
import bpy
import sys
# store scene objects to a variable object
object = bpy.context.scene.objects
def translate_XYZ(*argv): # Translate along xyz axes
if object.active:
bpy.ops.transform.translate(value=(argv))
class UIPanel(bpy.types.Panel):
bl_label = 'Example Panel'
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
def draw(self, context):
layout = self.layout
row = layout.row() # First line in the Panel
row.label ('Move LEFT / RIGHT')
row = layout.row()
row.operator('translate.n_x')
row.operator('translate.p_x')
row = layout.row() # Second line in the Panel
row.label('Move Forward / Backward')
row = layout.row() # First line in the Panel
row.operator('translate.p_y')
row.operator('translate.n_y')
#Task
#for up and down code snippet here!
class Translate_PX(bpy.types.Operator): # move along +X Axis
bl_idname = "translate.p_x"
bl_label = "RIGHT"
name = bpy.props.StringProperty()
def execute(self, context):
translate_XYZ(1,0,0)
return{'FINISHED'}
class Translate_PY(bpy.types.Operator): # move along +Y Axis
bl_idname = "translate.p_y"
bl_label = "FORWARD"
name = bpy.props.StringProperty()
def execute(self, context):
translate_XYZ(0,1,0)
return{'FINISHED'}
class Translate_NX(bpy.types.Operator): # move along -X Axis
bl_idname = "translate.n_x"
bl_label = "LEFT"
name = bpy.props.StringProperty()
def execute(self, context):
translate_XYZ(-1,0,0)
return{'FINISHED'}
class Translate_NY(bpy.types.Operator): # move along -Y Axis
bl_idname = "translate.n_y"
bl_label = "BACKWARD"
name = bpy.props.StringProperty()
def execute(self, context):
translate_XYZ(0,-1,0)
return{'FINISHED'}
#Task
#for up and down code snippet here!
bpy.utils.register_module(__name__)