Home Website Youtube GitHub

Bets way to Add Multiple mgear NPO's

Hello,

So I have quite a few post custom steps that I have scripted for my rig. However, for some of my customs steps I need to add NPO’s to some of the control’s. At the moment I have quite a few I need to add and its taking long for me to add them every time. So I was just wondering what would be the most efficient way to go about doing this? Is it better just to add them one by one after my build like I have been doing, or should I try and script it? I am new to scripting, so the scripting I have done thus far has just been very basic.

1 Like

Hi Chantelle,

In my opinion, the goal is to have the rig completely built with no manual steps afterwards. If I have to do manual steps, it just means I might forget to do it sometimes. So to answer your question, yes I believe you should try to script it. It will make your life easier.

Notes:

  • rigbits.addNPO() is the function you want.
  • I often prefix PyNodes with “o” to mean object. As opposed to parameters or strings, or other data. That is just my scripting style.
  • You need to pass PyNodes to addNPO, not string names.
import pymel.core as pm
from mgear import rigbits

oControl = pm.PyNode('brow_L0_ctl')
# addNPO returns a list, so if you just add a root to a single control, you can
# use [0] at the end to get the first one, if you need to access oRoot later in your script.
oRoot = rigbits.addNPO(each)[0]

ALSO, addNPO can take a list of objects all at once.
It will add a root to each of the objects in the list.

allMyControls = pm.ls('brow_L0_ctl', 'brow_L1_ctl', 'brow_L2_ctl', 'brow_R0_ctl', 'brow_R1_ctl', 'brow_R2_ctl')
oRoots = rigbits.addNPO(allMyControls)

print(oRoots)
# Will give you a list of all the new NPO roots:
[nt.Transform(u'brow_L0_ctl_npo'), nt.Transform(u'brow_L1_ctl_npo'), nt.Transform(u'brow_L2_ctl_npo'), nt.Transform(u'brow_R0_ctl_npo'), nt.Transform(u'brow_R1_ctl_npo'), nt.Transform(u'brow_R2_ctl_npo')]
5 Likes

And then to bring it together here is how I would format that script. You can put lists on multiple lines in Python, which makes it easier to read and add new items. Like this:

import pymel.core as pm
from mgear import rigbits

allMyControls = pm.ls(
        'brow_L0_ctl',
        'brow_L1_ctl',
        'brow_L2_ctl',
        'brow_R0_ctl',
        'brow_R1_ctl',
        'brow_R2_ctl',
        'nose_C0_ctl', # notice the last one can have a comma too. "Trailing commas".
        )

# You don't have to type every single controllers. Though you can if you want.
# Quickly add more items to the list, using Python's extend() function.

# Add all your left fingers (this depends on what your fingers are named!):
allMyControls.extend(pm.ls('finger_L*_fk*_ctl', type='transform'))
# Add all your right fingers:
allMyControls.extend(pm.ls('finger_R*_fk*_ctl', type='transform'))

# Add roots to everything in a single command:
oRoots = rigbits.addNPO(allMyControls)
5 Likes

Hi Chris,

Thank you so very much! This is really going to help me, and save me so much time! I am going to go try it out now.

Hi Chris,

I tried it out and its working beautifully! Thank you so much again!
I am working on a student film, and I need to rig 4 characters, and I am already very pressed for time. You have save me hours of work!

Would I be able to script something similar for the rigbits Rope tool? I have used it a couple times so far (for a tail and ears for 2 characters) and I am redoing it every time I rebuild.

No problem! Glad it helped.

Did you see this thread? Getting a good Tail setup with mGear

I just use the chain_FK_spline_01 for our tails.

I’ve never tried the Rope tool.

1 Like

Hi Chris

yeah I did, but I find i’m getting a better result with the spring chain and rope tool combination. Thank you though.

Hi @chrislesage, Do you know why this script is not working in the latest 5 mgear version?

// Error: An exception of type TypeError occurred. 
// Error: Traceback (most recent call last):
//   File "C:\Users\Milio_PC\Documents\maya\modules\scripts\mgear\shifter\guide.py", line 1475, in runStep
//     customStep = imp.load_source(fileName, runPath)
//   File "C:\Program Files\Autodesk\Maya2024\Python\lib\imp.py", line 172, in load_source
//     module = _load(spec)
//   File "<frozen importlib._bootstrap>", line 719, in _load
//   File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
//   File "<frozen importlib._bootstrap_external>", line 883, in exec_module
//   File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
//   File "A:/mGear/Build/Characters\Journey/scripts/post/NPO.py", line 17, in <module>
//     oRoots = rigbits.addNPO(allMyControls)
//   File "C:\Users\Milio_PC\Documents\maya\modules\scripts\mgear\rigbits\__init__.py", line 29, in addNPO
//     oTra = pm.createNode(
//   File "C:\Users\Milio_PC\Documents\maya\modules\scripts\mgear\pymaya\cmd.py", line 252, in wrapper
//     res = func(*args, **kwargs)
// TypeError: Invalid arguments for flag 'p'.  Expected string, got Transform

Hi Milio, Miquel shared a bug report template on Github for the beta. You can report this and fill out the information there. UPDATE: mGear 5.0 Beta 03 Available and open call for feedback

Also I edited your post to include code blocks.

A quick glance looks like you are mixing / and \ in your path. It’s likely a parsing error because \ acts like an escape character. So you need to use / or \\ in your paths. But I don’t know for sure. If that’s from the script, that might be the cause of the bug. Or it might be unrelated.

A:/mGear/Build/Characters\Journey/scripts/post/NPO.py

1 Like

Thank you Chris.

The script has been working fine until today when I started testing out latest beta version.

Already reported a bug chain component related, but didn’t want to add more noise to the bug list adding some post-script issues.

Cheers.

Oh I see! I didn’t even notice you were replying and referring to the script above. Anyway, no I haven’t had time to try 5.0 yet. But if it doesn’t use PyMEL anymore, maybe that’s why it’s failing if you send it PyNodes.

1 Like

oooh!! The first line is importing pymel! :sweat_smile:

that should work if you have pymel installed in Maya 2024 :stuck_out_tongue:

I haven’t even looked at the code yet. The error seems like it’s expecting a string. So maybe not? It might need a PyNode.name() instead of the PyNode directly.

1 Like

I am looking in to this. Just yesterday night I was talking about it with @yamahigashi on github

1 Like