bpy.ops.object.vertex_weight_copy() fails in multi edit mode #99969

Open
opened 2022-07-25 17:12:41 +02:00 by Mark Edwards · 8 comments

System Information
Operating system: windows 10 amd ryzen 9 5950x 2 x 3090 (not in nvlink)
Graphics card:

Blender Version
Broken: 3.12
Worked: don't think it ever has

in multi edit copy vertex to selected fails and does not create new groups or copy the weights, you have to join the mesh first then do copy to selected then separate the mesh again which is problematic in more complex rigging scenarios with shape keys etc.

Exact steps for others to reproduce the error
included example blend file with both meshes selected tab into edit mode highlight 1 vertex on the cylinder and then select all the verts on the ico sphere and select copy, the copy fails. If you join the ico sphere to the cylinder mesh and do the same it works as expected.

going to write a script as a workaround but I think it's really a bug ? (all be it a small one :-) )
image.png

copyfail.blend

**System Information** Operating system: windows 10 amd ryzen 9 5950x 2 x 3090 (not in nvlink) Graphics card: **Blender Version** Broken: 3.12 Worked: don't think it ever has in multi edit copy vertex to selected fails and does not create new groups or copy the weights, you have to join the mesh first then do copy to selected then separate the mesh again which is problematic in more complex rigging scenarios with shape keys etc. **Exact steps for others to reproduce the error** included example blend file with both meshes selected tab into edit mode highlight 1 vertex on the cylinder and then select all the verts on the ico sphere and select copy, the copy fails. If you join the ico sphere to the cylinder mesh and do the same it works as expected. going to write a script as a workaround but I think it's really a bug ? (all be it a small one :-) ) ![image.png](https://archive.blender.org/developer/F13315238/image.png) [copyfail.blend](https://archive.blender.org/developer/F13315240/copyfail.blend)
Author

Added subscriber: @MarkEdwards

Added subscriber: @MarkEdwards
Author

Workaround if anyone else runs into this, use case is mainly for things like adding buttons to shirts / bits of hard armour etc. but keeping mesh object separate that you want to move with deformed mesh but not deform much themselves in a way that will export to game engine without additional parenting / vertex parenting. (obviously add armature to target mesh pointing to rig as well, might add that as convenience later)

import bpy

#make sure we only have 2 objects selected
if len(bpy.context.selected_objects) == 2:
    
    #get target and source objects
    first_object = bpy.context.selected_objects[0]
    second_object = bpy.context.selected_objects[1]
    
    #get target and source mesh objects
    
    has_active_target = False
    
    if first_object ==  bpy.context.view_layer.objects.active:
        target_object = first_object
        target_mesh = first_object.data
        
        source_object = second_object
        source_mesh = second_object.data
        
        has_active_target = True
    
    elif second_object == bpy.context.view_layer.objects.active:
        target_object = second_object
        target_mesh = second_object.data
        
        source_object = first_object
        source_mesh = first_object.data

        has_active_target = True
        
    else:
        print ("One object needs to be active")
        has_active_target = False
    

    if has_active_target == True:

        print ("Source : " + source_mesh.name)
        print ("Target : " + target_mesh.name)
    
        #create new list with only the selected verts from each object in it
        source_selected_verts = list(filter(lambda v: v.select, source_mesh.vertices))
        target_selected_verts = list(filter(lambda v: v.select, target_mesh.vertices))
        
        #create int list of target verts selected
        target_selected_verts_index = [i.index for i in target_selected_verts]
        
        #make sure we only have one source vert selected
        if len(source_selected_verts) == 1:
            
            #get selected single vert
            source_selected_vert = source_selected_verts[0]
            
            #get vertex index
            source_selected_verts_index = source_selected_vert.index
            
            #get all the group names in the source object
            vgroup_names = {vgroup.index: vgroup.name for vgroup in source_object.vertex_groups}
            
            #iterate through all the vertex associated with the object and create a look up list
            vgroups = {v.index: [vgroup_names[g.group] for g in v.groups] for v in source_mesh.vertices}
            

            #get count of source groups
            for i in range (len(vgroups[source_selected_verts_index])):
                
                #get group name string
                group_name = vgroups[source_selected_verts_index][i]
                
                #get weight for that group
                group_weight = source_selected_vert.groups[i].weight
                
                #remove any groups from the destination mesh
                for vgroup in target_object.vertex_groups:
                    if vgroup.name ==  group_name:   
                        target_object.vertex_groups.remove(vgroup)
                
                #create new group
                new_group = target_object.vertex_groups.new(name=group_name)
                
                #use selected target index range to add weight
                new_group.add(target_selected_verts_index,group_weight,'ADD')
        
        print ("Vertex weights copied")
    else:
        print ("Only select one source vertex to copy from")
else:
    print ("Only select 2 objects")


Workaround if anyone else runs into this, use case is mainly for things like adding buttons to shirts / bits of hard armour etc. but keeping mesh object separate that you want to move with deformed mesh but not deform much themselves in a way that will export to game engine without additional parenting / vertex parenting. (obviously add armature to target mesh pointing to rig as well, might add that as convenience later) ``` import bpy #make sure we only have 2 objects selected if len(bpy.context.selected_objects) == 2: #get target and source objects first_object = bpy.context.selected_objects[0] second_object = bpy.context.selected_objects[1] #get target and source mesh objects has_active_target = False if first_object == bpy.context.view_layer.objects.active: target_object = first_object target_mesh = first_object.data source_object = second_object source_mesh = second_object.data has_active_target = True elif second_object == bpy.context.view_layer.objects.active: target_object = second_object target_mesh = second_object.data source_object = first_object source_mesh = first_object.data has_active_target = True else: print ("One object needs to be active") has_active_target = False if has_active_target == True: print ("Source : " + source_mesh.name) print ("Target : " + target_mesh.name) #create new list with only the selected verts from each object in it source_selected_verts = list(filter(lambda v: v.select, source_mesh.vertices)) target_selected_verts = list(filter(lambda v: v.select, target_mesh.vertices)) #create int list of target verts selected target_selected_verts_index = [i.index for i in target_selected_verts] #make sure we only have one source vert selected if len(source_selected_verts) == 1: #get selected single vert source_selected_vert = source_selected_verts[0] #get vertex index source_selected_verts_index = source_selected_vert.index #get all the group names in the source object vgroup_names = {vgroup.index: vgroup.name for vgroup in source_object.vertex_groups} #iterate through all the vertex associated with the object and create a look up list vgroups = {v.index: [vgroup_names[g.group] for g in v.groups] for v in source_mesh.vertices} #get count of source groups for i in range (len(vgroups[source_selected_verts_index])): #get group name string group_name = vgroups[source_selected_verts_index][i] #get weight for that group group_weight = source_selected_vert.groups[i].weight #remove any groups from the destination mesh for vgroup in target_object.vertex_groups: if vgroup.name == group_name: target_object.vertex_groups.remove(vgroup) #create new group new_group = target_object.vertex_groups.new(name=group_name) #use selected target index range to add weight new_group.add(target_selected_verts_index,group_weight,'ADD') print ("Vertex weights copied") else: print ("Only select one source vertex to copy from") else: print ("Only select 2 objects") ```

Added subscriber: @mano-wii

Added subscriber: @mano-wii

Changed status from 'Needs Triage' to: 'Needs Developer To Reproduce'

Changed status from 'Needs Triage' to: 'Needs Developer To Reproduce'

Thank you for the report.
While this is not really a bug, it appears to be something that was missed in #54641 (Multi-object mode support (parent task)).
So it seems to be something for the developers to consider.

Thank you for the report. While this is not really a bug, it appears to be something that was missed in #54641 (Multi-object mode support (parent task)). So it seems to be something for the developers to consider.
Member

Added subscriber: @lichtwerk

Added subscriber: @lichtwerk
Member

Seems like all of bpy.ops.vertex_group_XXX was not covered by multi-object-editing

Seems like all of `bpy.ops.vertex_group_XXX` was not covered by multi-object-editing
Philipp Oeser removed the
Interest
Animation & Rigging
label 2023-02-09 14:34:47 +01:00
Bart van der Braak added
Type
Bug
and removed
Type
Report
labels 2024-08-14 13:18:33 +02:00
Christoph Lendenfeld self-assigned this 2024-10-16 20:45:48 +02:00
Christoph Lendenfeld added
Status
Confirmed
and removed
Status
Needs Info from Developers
labels 2024-10-16 20:45:57 +02:00

going to confirm and look into it.
Not strictly speaking a bug as mentioned, but would be good to fix anyway

going to confirm and look into it. Not strictly speaking a bug as mentioned, but would be good to fix anyway
Christoph Lendenfeld removed their assignment 2024-10-17 14:18:31 +02:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Code Documentation
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Viewport & EEVEE
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Asset Browser Project
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Asset System
Module
Asset System
Module
Core
Module
Development Management
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Module
Viewport & EEVEE
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Severity
High
Severity
Low
Severity
Normal
Severity
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#99969
No description provided.