This script renames the bones positioned in the Left and right
sides of the armature, and if no suffix is specified, it’s
added automatically.
It’s only needed to name the left-side bones of the armature, without specifying the “_L” suffix, because it’s automatically
added and the bone located in the opposite side of the armature,
gets the same name, with the _R suffix in it’s name.
Notes:
The script must be run in Object Mode - Only the bones in the Left side of the armature (right side from viewer)
must be renamed
there is the original script.
not tested.
no guarantees.
#!BPY
"""
Name: 'Mirror Armature Left-Right names'
Blender: 244
Group: 'Object'
Tooltip: 'Renames bones according to armature symmetry'
"""
__author__ = "Ernesto Mendez"
__url__ = ("blender", "blenderartists")
__version__ = "1.0 2007-8-14"
__doc__ = """\
This script renames the bones positioned in the Left and right
sides of the armature, and if no suffix is specified, it's
added automatically.
It's only needed to name the left-side bones of the armature,
without specifying the "_L" suffix, because it's automatically
added and the bone located in the opposite side of the armature,
gets the same name, with the _R suffix in it's name.
"""
# -----------------------------------
# email: < [email protected] >
# ===========================================================================
# ***** BEGIN GPL LICENSE BLOCK *****
#
# Copyright (C) 2007, Ernesto Mendez
#
# 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 *****
# ===========================================================================
from Blender import *
def fix(bone):
name = ""
if ".0" in bone:
if "_L." in bone:
name = bone.split("_L.")[0] + "_L"
elif " L." in bone:
name = bone.split(" L.")[0] + "_L"
elif ".L." in bone:
name = bone.split(".L.")[0] + "_L"
if "_R." in bone:
name = bone.split("_R.")[0] + "_L"
elif " R." in bone:
name = bone.split(" R.")[0] + "_L"
elif ".R." in bone:
name = bone.split(".R.")[0] + "_L"
else:
if "_L" in bone:
name = bone
elif "_R" in bone:
name = bone[:-2] + "_L"
else:
name = bone + "_L"
return name
def rename(armature):
arm = Object.Get(armature)
arm_data = arm.getData()
bones = arm_data.bones.keys()
middle = []
left = []
right = []
left_pairs = {}
#arm_data.makeEditable()
#counter = 0
#for bone in bones:
# bone = arm_data.bones[bone]
# bone.name = "bone %d" % counter
# break
#arm_data.update()
for bname in arm_data.bones.keys():
bone = arm_data.bones[bname]
xval = bone.tail['ARMATURESPACE'][0]
if xval == 0:
middle.append(bname)
elif xval > 0:
left.append(bname)
elif xval < 0:
right.append(bname)
for lname in left:
bone = arm_data.bones[lname]
tail = bone.tail['ARMATURESPACE']
x,y,z = tail
fliptail = ( round(-x,3),round(y,3),round(z,3) )
for rname in right:
bone = arm_data.bones[rname]
x,y,z = bone.tail['ARMATURESPACE']
rtail = ( round(x,3), round(y,3), round(z,3) )
if rtail == fliptail:
left_pairs[lname] = rname
new_name = {}
for lname in left_pairs.keys():
rname = left_pairs[lname]
new_name[lname] = fix(lname)
new_name[rname] = fix(lname).replace("_L","_R")
arm_data.makeEditable()
for bname in new_name.keys():
bone = arm_data.bones[bname]
bone.name = new_name[bname]
arm_data.update()
Redraw()
def main():
scn = Scene.GetCurrent()
selection = scn.objects.context
if len(selection) == 0:
Draw.PupMenu("ERROR | No Armature selected")
elif len(selection) == 1:
ob = scn.objects.active
if ob.type == "Armature":
rename(ob.name)
else:
Draw.PupMenu("ERROR | %s is not an armature" % ob.name)
if __name__ == '__main__':
main()