Page Menu
Home
Search
Configure Global Search
Log In
Files
F23795
pose_mirror1,01.py
Public
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Authored By
Connor (toucan)
Nov 13 2013, 5:15 PM
Size
4 KB
Subscribers
None
pose_mirror1,01.py
View Options
# ***** BEGIN GPL LICENSE BLOCK *****
#
# 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 3 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, see <http://www.gnu.org/licenses/>.
#
# The Original Code is Copyright (C) 2013 by Connor Simpson
# All rights reserved.
#
# Information:
#
# The Original Code is: all of this file.
#
# Contributor(s): none yet.
#
# ***** END GPL LICENSE BLOCK *****
import
bpy
bl_info
=
{
"name"
:
"Mirror Bone Constraints"
,
"description"
:
"Mirrors bone constraints from pose mode."
,
"author"
:
"Connor Simpson"
,
"version"
:
(
1
,
01
),
"blender"
:
(
2
,
65
,
0
),
"location"
:
"View3D > Tool Shelf > Mirror Constraints"
,
"warning"
:
""
,
# used for warning icon and text in addons panel
"wiki_url"
:
"http://wiki.blender.org/index.php?title=Extensions:2.6/Py/Scripts/Rigging/Mirror_Bone_Constraints"
,
"tracker_url"
:
"https://projects.blender.org/tracker/index.php?func=detail&aid=36334"
,
"category"
:
"Rigging"
}
class
BoneConstraintMirror
(
bpy
.
types
.
Operator
):
"""Mirror bone constraints"""
bl_idname
=
"pose.mirror_bone_constraints"
bl_label
=
"Mirror Bone Constraints"
bl_options
=
{
'REGISTER'
,
'UNDO'
}
@classmethod
def
switchEnding
(
cls
,
boneName
):
"""Reverses side label of object (usually bone)"""
end
=
boneName
[
-
2
:]
newBoneName
=
boneName
if
(
end
[
0
]
==
"."
or
end
[
0
]
==
"_"
):
newBoneName
=
boneName
[:
-
1
]
if
(
end
[
1
]
==
"r"
):
newBoneName
=
newBoneName
+
"l"
elif
(
end
[
1
]
==
"R"
):
newBoneName
=
newBoneName
+
"L"
elif
(
end
[
1
]
==
"l"
):
newBoneName
=
newBoneName
+
"r"
elif
(
end
[
1
]
==
"L"
):
newBoneName
=
newBoneName
+
"R"
return
newBoneName
def
execute
(
self
,
context
):
"""Bones must be named with side extensions to use"""
bones
=
context
.
selected_pose_bones
armature_data
=
bpy
.
context
.
scene
.
objects
.
active
.
data
.
name
for
b
in
bones
:
if
len
(
b
.
constraints
)
>
0
:
bpy
.
ops
.
pose
.
select_all
(
action
=
'DESELECT'
)
b2
=
(
bpy
.
context
.
scene
.
objects
.
active
.
pose
.
bones
[
self
.
switchEnding
(
b
.
name
)])
b2
.
bone
.
select
=
True
bpy
.
ops
.
pose
.
constraints_clear
()
bpy
.
data
.
armatures
[
armature_data
]
.
bones
.
active
=
b
.
bone
bpy
.
ops
.
pose
.
constraints_copy
()
for
c2
in
b2
.
constraints
:
if
c2
.
target
is
not
None
:
if
c2
.
target
.
type
==
'ARMATURE'
:
posstarg
=
self
.
switchEnding
(
c2
.
subtarget
)
if
(
posstarg
in
bpy
.
data
.
armatures
[
armature_data
]
.
bones
):
c2
.
subtarget
=
posstarg
else
:
posstarget
=
self
.
switchEnding
(
c2
.
target
.
name
)
if
(
posstarget
in
context
.
scene
.
objects
):
c2
.
target
=
(
bpy
.
context
.
scene
.
objects
[
posstarget
])
return
{
'FINISHED'
}
@classmethod
def
poll
(
cls
,
context
):
return
(
context
.
mode
==
'POSE'
and
context
.
active_object
.
type
==
'ARMATURE'
)
class
VIEW3D_PT_tools_posemode_mirrorconstraints
(
bpy
.
types
.
Panel
):
bl_label
=
"Mirror Constraints"
bl_space_type
=
"VIEW_3D"
bl_region_type
=
"TOOLS"
def
draw
(
self
,
context
):
self
.
layout
.
operator
(
"pose.mirror_bone_constraints"
)
@classmethod
def
poll
(
cls
,
context
):
return
(
context
.
mode
==
'POSE'
and
context
.
active_object
.
type
==
'ARMATURE'
)
def
register
():
bpy
.
utils
.
register_module
(
__name__
)
def
unregister
():
py
.
utils
.
unregister_module
(
__name__
)
if
__name__
==
"__main__"
:
register
()
File Metadata
Details
Mime Type
text/x-python
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
5d/02/a45323cef7f3c0b8fc2c68ed3628
Event Timeline
Log In to Comment