bl_info = {
"name": "Juzipi Addon",
"author": "Juzipi",
"description": "Juzipi Addon",
"blender": (3, 3, 0),
"version": (1, 0, 0),
"warning": "",
"category": "Juzipi Addon",
}
import bpy
class myproperties(bpy.types.PropertyGroup):
my_string : bpy.props.StringProperty(name="name")
my_float_vector : bpy.props.FloatVectorProperty(name= "Scale", soft_min= 0, soft_max= 1000, default= (1,1,1))
my_enum : bpy.props.EnumProperty(
name= "Enumerator / Dropdown",
description= "sample text",
items= [('OP1', "Add Cube", ""),
('OP2', "Add Sphere", ""),
('OP3', "Add Suzanne", "")
])
#mypanel1_z1_s : bpy.props.StringProperty(name="Name")
mypanel2_1_s : bpy.props.StringProperty(name="name")
#----------------------------------------------------------------------------------------------
class mypanel1(bpy.types.Panel): #Juzipi_1折叠菜单
bl_label = "mypanel1"
bl_idname = "mypanel1"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "▇▇▇"
def draw(self, context):
layout = self.layout
mytool = context.scene.my_tool
layout.operator("mypanel1_1.x",text=mypanel1_1.bl_label)
layout.operator("mypanel1_2.x",text=mypanel1_2.bl_label)
layout.prop(mytool, "my_string")
layout.prop(mytool, "my_float_vector")
layout.prop(mytool, "my_enum")
layout.operator("mypanel1_3.x",text=mypanel1_3.bl_label)
#layout.operator("mypanel1_z1.x",text=mypanel1_z1.bl_label)
#obj=bpy.context.active_object
#layout.prop(bpy.data.particles["ParticleSettings"], "count")
#layout.prop(bpy.context.object.particle_systems["ParticleSystem"], "seed")
#layout.prop(bpy.data.particles["ParticleSettings"], "lifetime_random")
def execute(self, context):
return {'FINISHED'}
def invoke(self, context,event):
return {'FINISHED'}
class mypanel1_1(bpy.types.Operator): #button1
bl_label = "Cursor->Selected & Origin->Cursor"
bl_idname = "mypanel1_1.x" #这里必须用小写开头
def execute(self, context):
bpy.ops.view3d.snap_cursor_to_selected() # make sure in EDIT MODE
bpy.ops.object.editmode_toggle()
bpy.ops.object.origin_set(type='ORIGIN_CURSOR', center='MEDIAN')
bpy.ops.object.editmode_toggle()
self.report({'INFO'},'Cursor->Selected & Origin->Cursor have done')
return {'FINISHED'}
class mypanel1_2(bpy.types.Operator): #button2
bl_label = "add ico_sphere"
bl_idname = "mypanel1_2.x"
#bl_options = {'REGISTER', 'UNDO'}
loc : bpy.props.FloatVectorProperty()
n : bpy.props.IntProperty()
f : bpy.props.FloatProperty()
s : bpy.props.StringProperty()
pd : bpy.props.BoolProperty()
def execute(self, context):
bpy.ops.mesh.primitive_ico_sphere_add(radius=1,location=self.loc)
self.report({'INFO'}, 'have done')
return {'FINISHED'}
class mypanel1_3(bpy.types.Operator): #button3
bl_label = "Add Some Object" #the name of button
bl_idname = "mypanel1_3.x"
def execute(self, context):
if mytool.my_enum == 'OP1':
bpy.ops.mesh.primitive_cube_add()
if mytool.my_enum == 'OP2':
bpy.ops.mesh.primitive_uv_sphere_add()
if mytool.my_enum == 'OP3':
bpy.ops.mesh.primitive_monkey_add()
bpy.context.object.name = context.scene.my_tool.my_string
self.report({'INFO'},'have created')
return {'FINISHED'}
'''
class mypanel1_z1(bpy.types.Panel): #Juzipi_1的Panel折叠子菜单
bl_label = "mypanel1_z1"
bl_idname = "mypanel1_z1.x"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_parent_id = 'mypanel1'
bl_options = {'DEFAULT_CLOSED'}
def draw(self, context):
layout = self.layout
mytool = context.scene.my_tool
layout.row().label(text= "label")
layout.prop(mytool, "mypanel1_z1_s")
layout.operator("mypanel1_z1.x",text=mypanel1_z1.bl_label)
'''
#----------------------------------------------------------------------------------------------
class mypanel2(bpy.types.Panel): #Juzipi_2折叠菜单
bl_label = "mypanel2" #按钮名
bl_idname = "mypanel2"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = "▇▇▇" #设置成同等级菜单
def draw(self, context):
layout = self.layout
mytool = context.scene.my_tool
layout.prop(mytool, "mypanel2_1_s")
layout.operator("mypanel2_1.x",text=mypanel2_1.bl_label)
class mypanel2_1(bpy.types.Operator):
bl_label = "monkey_add"
bl_idname = "mypanel2_1.x"
def execute(self, context):
bpy.ops.mesh.primitive_monkey_add()
bpy.context.object.name = context.scene.my_tool.mypanel2_1_s
self.report({'INFO'},'have done')
return {'FINISHED'}
#---------------------------------------------------------------------------------------------
classes = [myproperties,mypanel1,mypanel1_1,mypanel1_2,mypanel1_3,mypanel2,mypanel2_1] #be sure to put the myproperties first
def register():
from bpy.utils import register_class
for cls in classes:
register_class(cls)
bpy.types.Scene.my_tool = bpy.props.PointerProperty(type=myproperties)
def unregister():
from bpy.utils import unregister_class
for cls in reversed(classes):
unregister_class(cls)
del bpy.types.Scene.my_tool
if __name__ == "__main__":
register()
#unregister()
blender插件,设置鼠标处为坐标并设置为原点
最新推荐文章于 2024-07-25 11:35:21 发布