Skip to content

Instantly share code, notes, and snippets.

@ousttrue
Created July 4, 2016 00:15
Show Gist options
  • Save ousttrue/384b769b5ced23048efa4197dbed42cf to your computer and use it in GitHub Desktop.
Save ousttrue/384b769b5ced23048efa4197dbed42cf to your computer and use it in GitHub Desktop.
blender panel plugin sample
import bpy
def createVertexGroupWithEachBone(mesh, armature):
print(mesh, armature)
for b in armature.bones.keys():
bpy.ops.object.vertex_group_add()
bpy.context.active_object.vertex_groups.active.name=b
class MirrorVertexGroup(bpy.types.Operator):
bl_idname = "mesh.mirror_vertexgroup"
bl_label = "MirrorVertexGroup"
bl_description = "add vertex group for mirroring Armature"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
o=context.object
#print(dir(o))
for m in o.modifiers:
print(m)
if m.name=="Armature":
createVertexGroupWithEachBone(o.data, m.object.data)
return {'FINISHED'}
class MirrorVertexGroupPanel(bpy.types.Panel):
"""Creates a Panel in the Object properties window"""
bl_label = "VertexGroup"
bl_space_type = 'VIEW_3D'
bl_region_type = 'TOOLS'
def draw(self, context):
layout = self.layout
obj = context.object
row = layout.row()
row.operator(MirrorVertexGroup.bl_idname)
bl_info = {
"name": "MirrorVertexGroup",
"author": "ousttrue",
"version": (1, 0),
"blender": (2, 77, 0),
"location": "",
"description": "Create VertexGroup for Mirror Armature",
"warning": "",
"support": "TESTING",
"wiki_url": "",
"tracker_url": "",
"category": "Object"
}
def register():
bpy.utils.register_class(MirrorVertexGroup)
bpy.utils.register_class(MirrorVertexGroupPanel)
#print("アドオンが有効化されました。")
def unregister():
bpy.utils.unregister_class(MirrorVertexGroupPanel)
bpy.utils.unregister_class(MirrorVertexGroup)
#print("アドオンが無効化されました。")
if __name__ == "__main__":
register()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment