Merge bone's weight to another bone. Please help to make a script.

Hi. Automatic Weight in blender is very helpfull, but it is not always do right things by default.
We can fix it with weight Paint tools, but often we can do the same much easier by adding some child bones to the areas where main bones do not reach, or to prevent some bones to affect this region like expanding chest bones to underarm to easy control how the hand bone affects this region. It is really gives easy and adds good control over the automatic weight distribution.

These extra bones not a big problem when we doesn’t limited in bones quantity. But when we want this model to use in realtime engine it is important to have an optimized armature.

So, it could be very helpfull to have an option to transfer and merge the weight from these addidional temporary bones to main parent bones and then get rid of these extra bones and vertex groups.

I am not programmer, but i thought it maybe an easy script to with simple math operation over bones weight? It would be very usefull, i wonder why such option doesn’t exist in blender.

NOTE! - I have found such script, but it’s for old 2.49 Blender and doesn’t works in new versions, it looks short, so maybe someone can help to make this script work with new blender or make a new one.

#!BPY
"""
Name: 'Merge to parent'
Blender: 248.1
Group: 'WeightPaint'
Tooltip: 'Merge weights to Parent bone'
"""

__author__ = "Ivo Grigull"
__url__ = ["www.ivogrigull.com"]
__version__ = "0.1"
__bpydoc__ = """\

Merge to parent
----------------------

Menu: Weightpaint->Merge to Parent

This script is supposed to be used in conjunction with the bone heating
appoach. Because the bone heating does sometimes not reach all areas i want,
(for example in the head) i usually add additional child bones and apply
bone heating again. This script can then be used to merge the weights to
the parent bone, to get rid of the extra vertex groups and remove the clutter.

This Script is to be used only in weight paint mode, and if the 
mesh has an armature modifier ( i.e. you have to make the armature
modifier "real" before using the script ).

# -------------------------------------------------------------------------- 
# ***** BEGIN GPL LICENSE BLOCK ***** 
# 
# This program is free software; you can redistribute it and/or 
# modify it under the terms of the GNU General Public License 
# as published by the Free Software Foundation; either version 2 
# of the License, or (at your option) any later version. 
# 
# This program is distributed in the hope that it will be useful, 
# but WITHOUT ANY WARRANTY; without even the implied warranty of 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
# GNU General Public License for more details. 
# 
# You should have received a copy of the GNU General Public License 
# along with this program; if not, write to the Free Software Foundation, 
# Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. 
# 
# ***** END GPL LICENCE BLOCK ***** 

"""

import Blender
from Blender import Scene, Draw, Object, Modifier, Armature
import BPyMesh

def main():

    ob = Object.GetSelected()[0]
    print ob.name

    arm = None
    Bone = None

    for m in ob.modifiers:
        if m.type== Modifier.Types.ARMATURE:
            arm = m[Modifier.Settings.OBJECT]
            if arm:
                print arm
                bones = arm.getData().bones.values()
                
                for bone in bones:
                    options = bone.options
                    
                    if Armature.BONE_SELECTED in options:
                        Bone = bone
                        
    if not Bone == None:
        
        print 'Bone: %s' % Bone.name
        print 'Mesh: %s' % ob
        
        me= ob.getData(mesh=1)
        groupNames, vWeightDict= BPyMesh.meshWeight2Dict(me)
        
        
        for n in range(0, len(vWeightDict)):
        
            if Bone.name in vWeightDict[n]:
#                print Bone.name
#                print 'parent: %s' % Bone.parent.name
                if Bone.parent.name in vWeightDict[n]:
                    value = ( vWeightDict[n][Bone.parent.name] + vWeightDict[n][Bone.name] ) * 0.5
                    vWeightDict[n][Bone.parent.name] += vWeightDict[n][Bone.name]
                    vWeightDict[n].pop(Bone.name)
                else:
                    vWeightDict[n][Bone.parent.name]  = vWeightDict[n][Bone.name]
                    vWeightDict[n].pop(Bone.name)
        
        
                    
        
        BPyMesh.dict2MeshWeight(me, groupNames, vWeightDict)
    
if __name__=='__main__':
    main()

Still need help, or at least some information about how difficult do do this thing.:frowning: