#!BPY """ Name: 'Tag Template bones' Blender: 248 Group: 'Object' Tooltip: 'Adds a boneID.py pyconstraint to all bones in template, with their names and template name' """ __author__ = "Bassam Kurdali" __url__ = ["freefac.org", "tube.freefac.org"] __version__ = "0.1" __bpydoc__ = """\ Tag Template bones Adds a boneID.py pyconstraint to all bones in template, with their names and template name """ # ***** BEGIN GPL LICENSE BLOCK ***** # # Script copyright (C) Bassam Kurdali # # 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 ***** # -------------------------------------------------------------------------- # copyright 2009 Bassam Kurdali import Blender PYCON = Blender.Constraint.Type["PYTHON"] PYTYP = Blender.Constraint.Settings["SCRIPT"] PROPS = Blender.Constraint.Settings["PROPERTIES"] ID = Blender.Text.get("boneID.py") def add_IDs(arm_pose,template): global PYCON, PYTYP, PROPS,ID for bone_name in arm_pose.bones.keys(): bone = arm_pose.bones[bone_name] pycons = [ const for const in bone.constraints if const.type == PYCON] if ID in [const[PYTYP] for const in pycons]: print "bone already ID'd" else: const = bone.constraints.append(PYCON) const[PYTYP] = ID const[PROPS]['user_template']=template const[PROPS]['user_uid']=bone_name const.name='UID' const.influence=0.0 arm_pose.update() return def clear_IDs(arm_pose): global PYCON, PYTYP, PROPS,ID for bone_name in arm_pose.bones.keys(): bone = arm_pose.bones[bone_name] pycons = [ const for const in bone.constraints if const.type == PYCON] for const in pycons : if const[PYTYP] == ID: bone.constraints.remove(const) arm_pose.update() return def main(): CLEAR_IDS = Blender.Draw.Create(0) #MAKE_IDS = Blender.Draw.Create(0) pup_block= [\ ('Clear', CLEAR_IDS, 'Clear IDs on current armature bones') ] if not Blender.Draw.PupBlock('Create IDs', pup_block): return CLEAR_IDS = CLEAR_IDS.val scn = Blender.Scene.GetCurrent() arm_ob = scn.objects.active if arm_ob.type == "Armature": arm_pose = arm_ob.getPose() if CLEAR_IDS: clear_IDs(arm_pose) else: add_IDs(arm_pose,arm_ob.name) if __name__ == '__main__': main()