Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- https://groups.google.com/g/python_inside_maya/c/hAw5rxiHbgM/m/gwo8KoCoAQAJ
- """
- import maya.cmds as mc
- def do_constraint(obj):
- has_trans = mc.getAttr(obj + '.translate', settable=True)
- has_rot = mc.getAttr(obj + '.rotate', settable=True)
- if not has_trans and not has_rot:
- # no trans or rot?
- return
- newLoc = mc.spaceLocator()
- # check if there is rotations
- # create a loc for ech selected obj and constraint to it
- if has_rot and has_trans:
- newCon = mc.parentConstraint(obj, newLoc, mo=0)
- elif not has_rot and has_trans:
- newCon = mc.parentConstraint(obj, newLoc, mo=0, sr=['x', 'y', 'z'])
- elif has_rot and not has_trans:
- newCon = mc.parentConstraint(obj, newLoc, mo=0, st=['x', 'y', 'z'])
- start = mc.playbackOptions(q=True, min=True)
- end = mc.playbackOptions(q=True, max=True)
- mc.bakeResults(newLoc, sm=1, sr=1, t=(start, end))
- mc.delete(newCon)
- # reverse connection
- if has_rot and has_trans:
- mc.parentConstraint(newLoc, obj, mo=True, w=1)
- elif not has_rot and has_trans:
- mc.parentConstraint(newLoc, obj, mo=True, w=1, sr=['x', 'y', 'z'])
- elif has_rot and not has_trans:
- mc.parentConstraint(newLoc, obj, mo=True, w=1, st=['x', 'y', 'z'])
- def main():
- user_sel = mc.ls(sl=1)
- if not user_sel:
- mc.warning('Please make a selection')
- return
- for obj in user_sel:
- do_constraint(obj)
- main()
Advertisement
Add Comment
Please, Sign In to add comment