#!BPY
"""
Name: 'Bone Renamator'
Blender: 236
Group: 'Object'
Tooltip: 'Rename the begining or the end of a bone's name( caution
: this script works why blender 237 and older only ).'
"""
#-------
# renommer tous les bones d'une armature
# jm soler, 04/2004
# Modif par Gabio, 01/2005
#-------
import Blender
from Blender import Armature,Object
from Blender.BGL import *
from Blender.Draw import *
####Create button
old_val = Create("L.001")
new_var = Create("R")
Armature = Create("Arm")
mode = Create(2)
####Button Events
B_NULL = 0
B_START = 1
B_EXIT = 2
B_REDRAW = 3
def draw():
global old_val
global new_var
global Armature
global mode
glClear(GL_COLOR_BUFFER_BIT)
glRasterPos2d(10,160)
Text("Bone Renamator")
mode = Menu("You want to rename:%t|The begining%x1|The end%x2",B_REDRAW,10,130,100,15,mode.val,"Choose
which part you want to rename")
Button("Change it!",B_START,10,10,70,20)
Button("Exit",B_EXIT,110,10,50,20)
old_val = String("old:",B_NULL,10,100,100,15,old_val.val,50,"The
previous string")
new_var = String("new:",B_NULL,10,70,100,15,new_var.val,50,"The
new string")
Armature = String("Armature:",B_NULL,10,40,150,15,Armature.val,50,"The
Armature to use")
def event(evt,val):
if (evt == QKEY and not val):
Exit()
def bevent(evt):
if evt == B_START:
ARM = init_Armature()
BONES = init_bone(ARM)
ren_Bone(BONES)
elif evt == B_EXIT:
Exit()
elif evt == B_REDRAW:
Register(draw,event,bevent)
def init_Armature():
global Armature
try:
ARM=Object.Get(Armature.val)
return(ARM)
except:
PupMenu("Armature not found%t|Ok")
Exit()
def init_bone(ARM):
BONES=ARM.getData().getBones()
return(BONES)
def ren_Bone(BONES):
global old_val
global new_var
global mode
"""
cette fonction recursive suit tous les
embranchements de bones
"""
if mode.val == 2:
try:
for B in BONES:
if B.getName()[len(B.getName())-len(old_val.val):len(B.getName())]
== old_val.val:
Ch=B.children
B.setName(B.getName()[:len(B.getName())-len(old_val.val)]+new_var.val)
for C in Ch:
ren_Bone(C)
except:
Ch=BONES.children
if BONES.getName()[len(BONES.getName())-len(old_val.val):len(BONES.getName())]
== old_val.val:
BONES.setName(BONES.getName()[:len(BONES.getName())-len(old_val.val)]+new_var.val)
for C in Ch:
ren_Bone(C)
else:
try:
for B in BONES:
if B.getName()[:len(old_val.val)] == old_val.val:
Ch=B.children
B.setName(new_var.val + B.getName()[len(old_val.val):len(B.getName())])
for C in Ch:
ren_Bone(C)
except:
Ch=BONES.children
if BONES.getName()[:len(old_val.val)] == old_val.val:
BONES.setName(new_var.val+BONES.getName()[len(old_val.val):len(BONES.getName())])
for C in Ch:
ren_Bone(C)
Blender.Redraw()
#-------------------------------------------------
Register(draw,event,bevent) |