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

Hey Chrislesage, I’m getting spun up with AnimPicker and this code generally works except it seems to be calculating my arm twist incorrectly.

I’m on mGear 4.0.9 and the Mirror Pose script seems to produce undesirable behavior on Twist Controls.

image < Mirror Script Results

< Flipped Twist Y manually from - to positive

The script is copying the Twist values directly rather than mirroring. Is this a bug in the Mirror Pose definition?

Hey @Saveremreve oh maybe so. I’ll give it a try on Monday and see if I can spot where that problem is coming from.

If you use the mGear right-click menu mirror do you get the same (bad) result? If so, I guess it’s a bug. If not, maybe the code needs to be updated in the Anim Picker template. (As far as I remember the Anim Picker code is just calling the generic mirror function, so you might be right, that it is a bug.)

Hi @Saveremreve,

Can you give some more details? Which component are you using for your arms? What do you mean by “Twist controls and values”? What exact attribute or control is that referring to?