Home Website Youtube GitHub

Synoptic Mirror and Flip Pose vs Custom script

When using mirror pose or flip pose it happens to do it in a way that is not suitable for the current rig I am using to animate. On the other hand if I use the synoptic it works correctly Flip pose and also mirror pose, any suggestion of how it could be solved?

The code that I am using for Mirror pose Flip Pose I found it in this forum and it works perfect in other rigs, but in this character that I have to do the animation does not work correctly.
“Mirror pose”

import pymel.core as pm
import maya.cmds as cmds
from mgear.core.anim_utils import mirrorPose
if not INIT:
current_selection = cmds.ls(selection=True)
controls = [pm.PyNode(x) for x in current_selection]
for ctl in controls:
mirrorPose(flip=False, nodes=[ctl])

“Flip pose”

import pymel.core as pm
import maya.cmds as cmds
from mgear.core.anim_utils import mirrorPose
if not INIT:
current_selection = cmds.ls(selection=True)
controls = [pm.PyNode(x) for x in current_selection]
for ctl in controls:
mirrorPose(flip=True, nodes=[ctl])

First of all, your code looks like it has some formatting problems. (Even the code you pasted, before the forum auto-formats it.)

So are you sure your code is pasted correctly in your rig? It needs to have indentation, and __INIT__ not **INIT**.

Are you getting errors in the script editor output when you run the code?

This is what you pasted into the forum:

import pymel.core as pm
import maya.cmds as cmds
from mgear.core.anim_utils import mirrorPose
if not **INIT**:
current_selection = cmds.ls(selection=True)
controls = [pm.PyNode(x) for x in current_selection]
for ctl in controls:
mirrorPose(flip=False, nodes=[ctl])

“Flip pose”

import pymel.core as pm
import maya.cmds as cmds
from mgear.core.anim_utils import mirrorPose
if not **INIT**:
current_selection = cmds.ls(selection=True)
controls = [pm.PyNode(x) for x in current_selection]
for ctl in controls:
mirrorPose(flip=True, nodes=[ctl])

And here is the corrected code. First, there is no reason to do one control at a time:

for ctl in controls:
    mirrorPose(flip=True, nodes=[ctl])

mirrorPose takes a list. You can simply do this:

mirrorPose(flip=True, nodes=controls)

There is also no reason to make a cmds selection and then transform it into PyNodes with list comprehension. Instead of this:

current_selection = cmds.ls(selection=True)
controls = [pm.PyNode(x) for x in current_selection]

You can simply do this:

controls = pm.selected(type='transform')

Final code: (This might not solve your weird control problem, if the problem is in the rig, since you said your code was working on other characters!)

# "Mirror pose"

import pymel.core as pm
from mgear.core.anim_utils import mirrorPose
if not __INIT__:
    controls = pm.selected(type='transform')
    mirrorPose(flip=False, nodes=controls)

# “Flip pose”

import pymel.core as pm
from mgear.core.anim_utils import mirrorPose
if not __INIT__:
    controls = pm.selected(type='transform')
    mirrorPose(flip=True, nodes=controls)
3 Likes

Thank you very much for the explanation is very useful for people who are starting in mgear, I notified those responsible for generating the rig that there is a problem, thank you very much for your time for all the explanation.

1 Like