4
Name: 'Armature Symmetry'
7
Tooltip: 'Make an armature symetrical'
10
__author__ = "Jonas Petersen"
11
__url__ = ("blender", "elysiun", "Script's homepage, http://www.mindfloaters.de/blender/", "thread at blender.org, http://www.blender.org/modules.php?op=modload&name=phpBB2&file=viewtopic&t=4858")
12
__version__ = "0.9 2004-11-10"
15
This script creates perfectly symmetrical armatures.
17
With default configuration it will:<br>
18
- Look for bones that have the reference suffix (".L") and
19
adjust/create the according opposite bone (suffix ".R");<br>
20
- Center align all bones that _don't_ have the suffix ".X".
22
Please check the script's homepage and the thread at blender.org (last link button above) for more info.
24
For this version users need to edit the script code to change default options.
27
# --------------------------------------------------------------------------
28
# "Armature Symmetry" by Jonas Petersen
29
# Version 0.9 - 10th November 2004 - first public release
30
# --------------------------------------------------------------------------
32
# A script for creating perfectly symmetrical armatures.
34
# It is available in Object Mode via the menu item:
36
# Object -> Scripts -> Armature Symmetry
38
# With default configuration it will:
40
# - Look for bones that have the reference suffix (".L") and
41
# adjust/create the according opposite bone (suffix ".R").
43
# - Center align all bones that _don't_ have the suffix ".X"
45
# Find the latest version at: http://www.mindfloaters.de/blender/
47
# --------------------------------------------------------------------------
48
# $Id: armature_symetry.py,v 1.1 2005/05/17 07:17:52 ianwill Exp $
49
# --------------------------------------------------------------------------
50
# ***** BEGIN GPL LICENSE BLOCK *****
52
# Copyright (C) 2004: Jonas Petersen, jonas at mindfloaters dot de
54
# This program is free software; you can redistribute it and/or
55
# modify it under the terms of the GNU General Public License
56
# as published by the Free Software Foundation; either version 2
57
# of the License, or (at your option) any later version.
59
# This program is distributed in the hope that it will be useful,
60
# but WITHOUT ANY WARRANTY; without even the implied warranty of
61
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
62
# GNU General Public License for more details.
64
# You should have received a copy of the GNU General Public License
65
# along with this program; if not, write to the Free Software Foundation,
66
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
68
# ***** END GPL LICENCE BLOCK *****
70
# --------------------------------------------------------------------------
72
# --------------------------------------------------------------------------
74
# Note: Theses values will later be editable via a gui interface
77
# CENTER_SUFFIX is the suffix for bones that should (or shouldn't) get
78
# center aligned. The default is '.X'.
83
# 'include' only bones with the CENTER_SUFFIX appended
87
# all bones except those with the CENTER_SUFFIX
88
# appended get center aligned.
91
# 'off' bones will not get center aligned at all.
93
CENTER_SUFFIX_MODE = 'exclude'
95
# The suffix for the reference and opposite side of the
96
# armature. Bone positions of the opposite side will be overwritten by
97
# the mirrored values of the reference side.
98
# The default is REF_SUFFIX = '.L' and OPP_SUFFIX = '.R'.
102
# MIRROR_AXIS defines the axis in which bones are mirrored/aligned.
109
# --------------------------------------------------------------------------
110
# END OF CONFIGURATION
111
# --------------------------------------------------------------------------
116
name = bone.getName()
117
base = name[0:len(name)-ref_suffix_len]
118
rsuff = name[-ref_suffix_len:len(name)]
119
csuff = name[-center_suffix_len:len(name)]
120
return name, base, rsuff, csuff
122
ref_suffix_len = len(REF_SUFFIX);
123
center_suffix_len = len(CENTER_SUFFIX);
124
armature_selected = False
126
obj_list = Blender.Object.GetSelected()
128
if obj.getType() == "Armature":
129
armature_selected = True
131
bones = arm.getBones()
135
bonehash[bone.getName()] = bone
138
name, base, rsuff, csuff = splitName(bone)
141
if (rsuff == REF_SUFFIX):
142
oppname = base + OPP_SUFFIX
144
# create opposite bone if necessary
145
if not bonehash.has_key(oppname):
146
bonehash[oppname]=Blender.Armature.Bone.New(oppname)
147
parent = bone.getParent()
149
pname, pbase, prsuff, pcsuff = splitName(parent)
150
if prsuff == REF_SUFFIX:
151
poppname = pbase + OPP_SUFFIX
152
if bonehash.has_key(poppname):
153
bonehash[oppname].setParent(bonehash[poppname])
155
bonehash[oppname].setParent(parent)
156
arm.addBone(bonehash[oppname])
160
tail = bone.getTail()
161
tail[MIRROR_AXIS] *= -1;
162
bonehash[oppname].setTail(tail)
164
head = bone.getHead()
165
head[MIRROR_AXIS] *= -1;
166
bonehash[oppname].setHead(head)
168
roll = -bone.getRoll()
169
bonehash[oppname].setRoll(roll)
171
# Write access to ik flag not (yet?) supported in Blender (2.34)
172
#if bone.hasParent():
173
# bonehash[oppname].setIK(not bone.getIK())
176
elif (rsuff != OPP_SUFFIX) and \
177
(CENTER_SUFFIX_MODE != 'off') and \
178
((CENTER_SUFFIX_MODE == 'exclude' and csuff != CENTER_SUFFIX) or \
179
(CENTER_SUFFIX_MODE == 'include' and csuff == CENTER_SUFFIX)):
183
tail = bone.getTail()
184
tail[MIRROR_AXIS] = 0.0;
187
head = bone.getHead()
188
head[MIRROR_AXIS] = 0.0;
191
# Setting set roll in python rotates all child bones.
192
# Not so if set via the Transform Properties in Blender.
196
if not armature_selected:
197
Blender.Draw.PupMenu("Armature Symmetry%t|Please select an Armature object!")