Last active
October 7, 2021 10:50
-
-
Save esnosy/e793190bb64e96c2ce9776229af1d432 to your computer and use it in GitHub Desktop.
Create new vertex group from selected vertices(idea by MooKorea #3998 on discord)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# NOTE: blender already has this functionality | |
bl_info = { | |
"name": "Vertex Group From Selected", | |
"author": "Iyad Al-Sonoussi(AKA Human/Redivider/CGOnFire)", | |
"version": (0,1), | |
"blender": (2, 80, 0), | |
"location": "VIEW3D > Vertex Context Menu > New Vertex Group", | |
"description": "Create Vertex Group From Selected Vertices", | |
"warning": "", | |
"wiki_url": "https://gumroad.com/cgonfire", | |
"tracker_url": "", | |
"category": "Mesh" | |
} | |
import bpy | |
from bpy.types import Header, Menu, Panel | |
from bpy.utils import register_class, unregister_class | |
class CreateVG(bpy.types.Operator): | |
"""Create Vertex Group From Selected Vertices""" | |
bl_idname = "object.crvg_op" | |
bl_label = "New Vertex Group" | |
bl_options = {'REGISTER', 'UNDO'} | |
@classmethod | |
def poll(cls, context): | |
return context.active_object is not None | |
def execute(self, context): | |
obj = bpy.context.active_object | |
verts = obj.data.vertices | |
group = obj.vertex_groups.new() | |
obj.vertex_groups.active = group | |
bpy.ops.object.mode_set(mode='OBJECT') | |
for v in verts: | |
if v.select: | |
group.add([v.index],1,'REPLACE') | |
bpy.ops.object.mode_set(mode='EDIT') | |
return {'FINISHED'} | |
# This class has to be exactly named like that to insert an entry in the right click menu | |
class WM_MT_button_context(Menu): | |
#bl_options = {'REGISTER'} | |
bl_label = "Add Viddyoze Tag" | |
def draw(self, context): | |
pass | |
def menu_func(self, context): | |
layout = self.layout | |
layout.separator() | |
layout.operator(CreateVG.bl_idname) | |
classes = ( | |
CreateVG, | |
WM_MT_button_context, | |
) | |
def register(): | |
for cls in classes: | |
register_class(cls) | |
bpy.types.VIEW3D_MT_edit_mesh_context_menu.append(menu_func) | |
def unregister(): | |
for cls in classes: | |
unregister_class(cls) | |
bpy.types.VIEW3D_MT_edit_mesh_context_menu.remove(menu_func) | |
if __name__ == "__main__": | |
register() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment