I have an idea how to get a faster workflow when assigning weights in edit mode, and would like to know how hard this would be to make in python as an addon:
Before: I'm manually setting weights using this method:
- Select one or more vertices
- Select a vertex group
- Choose a weight, by entering 0.2 and pressing enter
- Click Assign
If I'm not happy with it, repeat 3-4 until I'm happy. This can be quite cumbersome and a lot of clicking and typing.
After: With my addon, it would be one less step, like this:
- Select one or more vertices
- Select a vertex group
- Click 20 - And 0.2 is assigned in one click
If I'm not happy with it, I just click another value. It would save a lot of time for me.
And as an extra bonus, if this is possible, there is also a Liveweight slider, that updates the vertex group as I drag the slider, and I see the result right away. Pretty much like the Vertex weights in the Properties panel, but this affects all selected vertices.
Would this be possible, and where would I start? I have never coded anything in python, but I've been coding for a long time, mostly PHP and Javascript, so I think I can figure out the basics, if I get some pointers.
Also, is it possible to put this inside the Vertex Group section, or does it need to be in a separate panel?
Here's a rough screenshot of my idea as a separate panel, sorry for a weird number of buttons
Here's the code I've made so far. I got it working when I had another similar script loaded, but when I use only this, I only get the Panel, not the buttons. Is there a class I missed or something?
Now I'd be happy for some tips on finding the active vertex group and assigning the vertex values to the selected vertices.
I tried to implement the code, but I'm not sure if I should tab in the for loop, and make it iterate through all vertices.
bl_info = {
"name": "Quickly set weights of Vertex Groups",
"author": "nicmar",
"version": (1, 0),
"blender": (2, 78, 0),
"location": "Properties Editor > Object data > Vertex Groups",
"description": "Quickly set Vertex Groups with assigned weight and live edit",
"warning": "",
"wiki_url": "",
"category": "Mesh"}
import bpy
import time
from bpy.types import Panel
class QuickWeightPanel(bpy.types.Panel):
bl_label = "Quick Vertex Weights"
bl_space_type = "PROPERTIES";
bl_region_type = "WINDOW";
bl_context = "data"
#bl_category = "Test"
def draw(self,context):
layout = self.layout
row = layout.row(align=True)
row.alignment = 'EXPAND'
row.operator("my.button", text="0").number=0
row.operator("my.button", text="10").number=0.1
row.operator("my.button", text="25").number=0.25
row.operator("my.button", text="40").number=0.4
row.operator("my.button", text="50").number=0.5
row.operator("my.button", text="60").number=0.6
row.operator("my.button", text="75").number=0.75
row.operator("my.button", text="90").number=0.9
row.operator("my.button", text="100").number=1
class MyOp(bpy.types.Operator): #The operator class derived from Operator
bl_idname="my.button" #Same as in row.operator
bl_label="my.button blabla" #Needed
number=bpy.props.FloatProperty() #The property used in row.operator
def execute(self, context): #Is trigered by buttons
# Toggle into edit mode
obj=bpy.context.active_object
# Toggle into object mode (Wrong? I need to be in edit mode to set weights?)
#prevMode = obj.mode
#bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
# Get active vertex group index
active_vertex_group_index = obj.vertex_groups.active_index
# Should I use this?
#g=obj.vertex_groups['group name']
# Loop through and get all selected vertices i v (?)
[v for v in obj.data.vertices if v.select]
# Get first?
v = obj.data.vertices[0]
# Get the data for the group accessed by the group index
vg=v.groups[active_vertex_group_index]
# Set weight of active vertices in active weight group
# vg.weight = 0.5
# Print weight of current vertex
print(vg.weight)
# Return to previous mode before operator
bpy.ops.object.mode_set(mode=prevMode, toggle=False)
return {'FINISHED'}
def register():
bpy.utils.register_module(__name__)
#bpy.types.Data.ignit_panel = bpy.props.PointerProperty(type=IgnitProperties)
def unregister():
bpy.utils.unregister_module(__name__)
#del bpy.types.Data.ignit_panel
if __name__ == "__main__":
register()