-
Notifications
You must be signed in to change notification settings - Fork 0
/
mr_swapObjectsInWorldspace.py
81 lines (67 loc) · 2.85 KB
/
mr_swapObjectsInWorldspace.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
"""
# ------------------------------------------------------------------------------ #
# SCRIPT: mr_swapObjectsInWorldspace.py
# VERSION: 0001
#
# CREATORS: Maria Robertson
# ---------------------------------------
# Last tested for Autodesk Maya 2023.3
# ---------------------------------------
# DESCRIPTION:
# ---------------------------------------
# Swap the position and rotation of two objects in worldspace.
#
# ---------------------------------------
# RUN COMMAND:
# ---------------------------------------
import importlib
import mr_swapObjectsInWorldspace
importlib.reload(mr_swapObjectsInWorldspace)
mr_swapObjectsInWorldspace.main(translate=True, rotate=True)
# ------------------------------------------------------------------------------ #
"""
import maya.cmds as cmds
def main(translate=True, rotate=True):
selection = cmds.ls(selection=True)
if len(selection) != 2:
cmds.warning("Please select exactly two objects.")
return None
a, b = selection
has_keyframes_a = cmds.keyframe(a, query=True, keyframeCount=True)
has_keyframes_b = cmds.keyframe(b, query=True, keyframeCount=True)
# Swap positions.
if translate:
pos_a = cmds.xform(a, query=True, worldSpace=True, translation=True)
pos_b = cmds.xform(b, query=True, worldSpace=True, translation=True)
cmds.xform(a, translation=pos_b, worldSpace=True)
cmds.xform(b, translation=pos_a, worldSpace=True)
translate_attributes = ['.translateX', '.translateY', '.translateZ']
if has_keyframes_a:
for attr in translate_attributes:
cmds.setKeyframe(a, attribute=attr)
if has_keyframes_b:
for attr in translate_attributes:
cmds.setKeyframe(b, attribute=attr)
# Swap rotations.
if rotate:
rot_a = cmds.xform(a, query=True, worldSpace=True, rotation=True)
rot_b = cmds.xform(b, query=True, worldSpace=True, rotation=True)
cmds.xform(a, rotation=rot_b, worldSpace=True)
cmds.xform(b, rotation=rot_a, worldSpace=True)
rotate_attributes = ['.rotateX', '.rotateY', '.rotateZ']
if has_keyframes_a:
for attr in rotate_attributes:
cmds.setKeyframe(a, attribute=attr)
if has_keyframes_b:
for attr in rotate_attributes:
cmds.setKeyframe(b, attribute=attr)
"""
##################################################################################################################################################
# ---------------------------------------
# CHANGELOG:
# ---------------------------------------
# 2024-01-20- 0001:
# - First pass.
# ---------------------------------------
##################################################################################################################################################
"""