Well . . . . this is a test for the new implementation done by Ken on the api for constraints in the cvs
-CopyConstraints.- copy all the constraints from one armature to an other.
- MirrConstraints.- if you put the constraints of the right or left side this script will put the constraints on the opositive side if that bone do not have any constraints.
CopyConstraints
#!BPY
""" Registration info for Blender menus: <- these words are ignored
Name: 'Copy Constraints'
Blender: 242
Group: 'Object'
Tip: 'Copy constraints from active armature to selected armature'
"""
__author__ = "Ramon Carlos Ruiz (RCRuiz)"
__url__ = ("blender", "elysiun",
"e-mail: [email protected]")
__version__ = "0.0.1"
__bpydoc__ = """\
This script Copies all bone constraints from the
active armature's bones to the selected armature.
Usage:
Select target armature first and then Shift select
the active armature (the one with constraints) and
run the script.
Names in both armature's bones need to be the equal.
"""
# $Id: CopyConstraints.py,v 0.0.1 05/11/06 Ramon Carlos Ruiz
# --------------------------------------------------------------------------
# ***** BEGIN GPL LICENSE BLOCK *****
#
# Copyright (C) 2003, 2004: A Vanpoucke
#
# 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 *
listaCons=[]
def buscaCons(boneName):
cons=[]
for tmp in listaCons:
if boneName==tmp[0]:
cons.append(tmp)
return cons
objSel=Blender.Object.GetSelected()
if len(objSel)>=2:
ob1=objSel[0]
ob2=objSel[1]
pose=ob1.getPose()
for boneName in pose.bones.keys():
bone=pose.bones[boneName]
for cons in bone.constraints:
listaCons.append([boneName,cons])
pose=ob2.getPose()
for boneName in pose.bones.keys():
bone=pose.bones[boneName]
cons=buscaCons(boneName)
if len(cons)<>0:
for tmpconst in bone.constraints:
bone.constraints.remove(tmpconst)
cont=0
print "*-*-*-*-*-*"
print boneName
for c in cons:
print "Const #",cont
try:
bone.constraints.append(c[1].type)
if c[1].type<>0:
if c[1][Constraint.Settings.TARGET].getType()=='Armature':
bone.constraints[cont][100]= ob2
print 100, ob2
else:
bone.constraints[cont][100]= c[1][100]
print 100, c[1][100]
for i in range(101,150): #it only need up to 130 but just in case and new posible constraints
try:
bone.constraints[cont][i]= c[1][i]
print i, c[1][i]
except:
err=1
else:
print 0,"Nul Constraint"
cont=cont+1
except:
print "Constraint type",c[1].type," is not considere by the api"
ob2.makeDisplayList()
print "
Copy is Done!"
MirrConstraints
#!BPY
""" Registration info for Blender menus: <- these words are ignored
Name: 'Mirror Constraints'
Blender: 242
Group: 'Object'
Tip: 'Mirror constraints in selected armature '
"""
__author__ = "Ramon Carlos Ruiz (RCRuiz)"
__url__ = ("blender", "elysiun",
"e-mail: [email protected]")
__version__ = "0.0.2"
__bpydoc__ = """\
Select the armature in Object mode and apply the script .
This will put the constraints in the empty opositive bone
"""
# $Id: MirrConstraints.py,v 0.0.2 09/27/06 Ramon Carlos Ruiz
# --------------------------------------------------------------------------
# ***** BEGIN GPL LICENSE BLOCK *****
#
# Copyright (C) 2003, 2004: A Vanpoucke
#
# 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 *
listaCons=[]
def Opuesto(lado):
if lado=="r":
return "l"
if lado=="right":
return "left"
if lado=="RIGHT":
return "LEFT"
if lado=="R":
return "L"
if lado=="l":
return "r"
if lado=="left":
return "right"
if lado=="LEFT":
return "RIGHT"
if lado=="L":
return "R"
return ""
def nomOp(boneName):
nomop=""
nom=boneName.split('.')
for tmp in range(len(nom)):
opu=Opuesto(nom[tmp])
if opu=="":
opu=nom[tmp]
if tmp==0:
nomop=opu
else:
nomop=nomop+"."+opu
return nomop
def buscaEspejoCons(boneName):
cons=[]
nom=boneName.split('.')
nomop=nomOp(boneName)
for tmp in listaCons:
if boneName<>tmp[0]:
if nomop==tmp[0]:
cons.append(tmp)
return cons
objSel=Blender.Object.GetSelected()
if len(objSel)>=1:
ob1=objSel[0]
pose=ob1.getPose()
for boneName in pose.bones.keys():
bone=pose.bones[boneName]
for cons in bone.constraints:
listaCons.append([boneName,cons])
for boneName in pose.bones.keys():
bone=pose.bones[boneName]
cons=buscaEspejoCons(boneName)
if len(cons)<>0 and len(bone.constraints)==0:
for tmpconst in bone.constraints:
bone.constraints.remove(tmpconst)
cont=0
print "*-*-*-*-*-*"
print boneName
for c in cons:
print "Const #",cont
try:
bone.constraints.append(c[1].type)
if c[1].type<>0:
for i in range(100,180): #it only need up to 130 but just in case and new posible constraints
if i==103:
try:
#print "opuesto de ",nomOp(c[1][i])#," es ",nomOp(c[1][i])#nomOp(c[1][i].split('.')[0])
bone.constraints[cont][i]= nomOp(c[1][i])
except:
err=1
else:
try:
bone.constraints[cont][i]= c[1][i]
#print i, c[1][i]
except:
err=1
else:
print 0,"Nul Constraint"
cont=cont+1
except:
print "Constraint type",c[1].type," is not considere by the api"
ob1.makeDisplayList()
print "
Mirror is Done!"
Un Saludo and a BIG THANKS TO KEN
RCRuiz