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')]
4 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.