So I have two scripts, one that goes through the name of the vertex group and prints out each of that groups weight painting influence. Another script that goes into Edit Mode, and from the selected group it prints out its Vertex ID.
Both scripts print out the respected values to the console and I wipe the console each time I run the script.
Now I have gotten to a point where I am a bit stuck, I am wanting to automate this process because at the moment I need to do each step manually and this takes so much time. I currently have 109 vertex groups and manually output both of these these.
Does anyone know how I can go through each of my scripts and make it so the script will go through each of the specific bits of code, go through each group and automatically print the respected values I need, then output that file to a .txt document in a specified folder?
Thank you.
This code snippet prints out the vertex ID
import bpy
import bmesh
from os import system
cls = lambda: system('cls')
cls() #this function call will clear the console
obj=bpy.context.object
if obj.mode == 'EDIT':
bm=bmesh.from_edit_mesh(obj.data)
for v in bm.verts:
if v.select:
print(v.index)
This code snippet prints out the weight influence of that selected group.
import bpy
from os import system
cls = lambda: system('cls')
cls() #this function call will clear the console
# Which group to find all verts in?
groupName = ' '
# Use the active object
obj = bpy.context.active_object
# Ensure all values updated
bpy.ops.object.mode_set(mode='OBJECT',toggle=True)
# Store the mesh
mesh = obj.data
# Get all the verts
selVerts = [v for v in mesh.vertices]
# Get the index of the required group
indexVal = obj.vertex_groups[groupName].index
# Store the vertex and its weight together.
weights = []
for v in selVerts: #loop over all verts
for n in v.groups: #loop over all groups with each vert
if n.group == indexVal: #check if the group val is the same as the index value of the required vertex group
weights.append([v,n.weight]) #store the vertex and its weight in a nested list
print(weights[-1][1]) #print the vertex index and its weight