Last active
May 2, 2017 16:22
-
-
Save jirihnidek/64f2f269c9aa2021b33ae79989e21ebd to your computer and use it in GitHub Desktop.
This file contains hidden or 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
""" | |
This simple example of Blender Python script prints membership of verticies in vertex groups and weights. It uses deform layer. | |
""" | |
import bpy | |
import bmesh | |
obj = bpy.context.object | |
# Get the active mesh | |
me = obj.data | |
# Get a BMesh representation | |
bm = bmesh.new() # create an empty BMesh | |
bm.from_mesh(me) # fill it in from a Mesh | |
group_index = obj.vertex_groups.active_index | |
dvert_lay = bm.verts.layers.deform.active | |
if dvert_lay is not None: | |
for vert in bm.verts: | |
dvert = vert[dvert_lay] | |
print(vert.index, ' vertex groups: ', dvert.items()) | |
# Print value of active layer | |
print(dvert[group_index]) |
This file contains hidden or 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
""" | |
This simple example of Blender Python script prints memberships of verticies in vertex groups. | |
""" | |
import bpy | |
import bmesh | |
# get active mesh | |
obj = bpy.context.object | |
me = obj.data | |
# Enter edit mode | |
return_to_object_mode = False | |
if obj.mode == 'OBJECT': | |
bpy.ops.object.mode_set(mode='EDIT') | |
return_to_object_mode = True | |
# get bMesh representation | |
bm = bmesh.from_edit_mesh(me) | |
# iterate through the vertex group | |
for group in obj.vertex_groups: | |
# set current vertex group to active | |
bpy.ops.object.vertex_group_set_active(group=str(group.name)) | |
# select the active vertex group | |
bpy.ops.object.vertex_group_select() | |
# get all currently selected verts | |
vertices = [v for v in bm.verts if v.select] | |
# vertex iteration | |
for vertex in vertices: | |
print("Vertex ", vertex.index, " is in ", group.name) | |
# deselect the current vertex group | |
bpy.ops.object.vertex_group_deselect() | |
if return_to_object_mode is True: | |
bpy.ops.object.mode_set(mode='OBJECT') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment