Somewhat “safer” way of making a PyNode

I always kept running into problems when making PyNodes in my script and the error messages Maya gives you aren’t always the best.  So I wrote a little helper function, especially useful when you have more than one object with the same name in your scene.

def pynode(object_name, specific_on_multiple=False, pick_most_root=False, pick_most_leaf=False, pick_index=None):
    Returns a PyNode of the given object name with better error messages and additional options

    :param object_name: name of the object you want to make a PyNode
    :param specific_on_multiple: <bool> When set to True, allows you set the next flags to return a specific object when there are multiple objects with the same name
    :param pick_most_root: <bool> returns the most root object if there are multiple objects with the same name
    :param pick_most_leaf: <bool> returns the most leaf object if there are multiple objects with the same name
    :param pick_index: <int> returns this index of object if there are multiple objects with the same name
    :return: a PyNode
    if object_name is None:
        raise RuntimeError("Can't make a PyNode when object_name type is None")
    if pm.objExists(object_name):
            return pm.PyNode(object_name)
            if not type(object_name) == str:
                node_name = object_name.nodeName()
                node_name = object_name
            multiple_nodes = sorted([str(node) for node in], key=len)

            if len(multiple_nodes) > 1:
                if specific_on_multiple is False:
                    error_message = "There are multiple nodes with this name:"
                    for node in multiple_nodes:
                        error_message += "\n%s" % node
                    raise RuntimeError(error_message)
                    if pick_most_root is True:
                        return pm.PyNode(multiple_nodes[0])
                    elif pick_most_leaf is True:
                        return pm.PyNode(multiple_nodes[-1])
                    elif pick_index is not None:
                            selected_node = multiple_nodes[pick_index]
                        except IndexError:
                            raise IndexError("%s is not a valid index, valid indices are 0 to %s"
                                             % (pick_index, len(multiple_nodes) - 1))
                        return pm.PyNode(selected_node)

                    raise ValueError("When custom_on_multiple is set to True, either pick_most_root or pick_most_leaf "
                                     "should be set to True as well")
        raise ValueError("Object (%s) doesn't exist" % object)

Skin Saver tool

I finally found the time to update my old skin saver tool. I’ve cleaned up the code a bit, added some extra functionality and just made it work a bit smoother than before. You can find it on my Gumroad page:


nv Eye Rigger

I completed the script I was writing to quickly set up a cartoony eye in Maya. It works pretty good and it’ll save you a lot of time when you’re setting up the eye lids for your characters. And, as outlined by the post below, I think it’s one of the best techniques to rig an eye 🙂


You can find it for the low low price of 5 euros on my Gumroad page:

Best eye rigging technique ever!

I started working on an eye rig solution based on Marco Giordano’s work. All credit goes to him for coming up with it. I had seen it once before, but learned the technique through Wade Ryer’s course. The setup works by having locators ride a curve and joints pointing towards those locators. When you then deform the curve, the locators move, which in turn move the joints, which in turn moves the skin. The beauty about this set up is that it really feels like the eye lids are sliding over the eye ball. I’ve added some driven behavior for looking up, down, left and right and the whole things feels really good when you move it.

Because this is something I’d like to add to more of my rigs, I started scripting out the process. I’m still working on it, but wanted to add a little update on the whole thing anyway 🙂

A quickie, set a Maya enum by string

I’m just adding this here on my site because I always need to find it in older scripts and I don’t want to keep digging for it. So, as far as I know, there’s no easy way to set an enum attribute by a string value in Python. You can only set it by index value, which doesn’t do you much good if you don’t know the index of the value you need. In case you need it here’s a quick little function to use a string value to set the enum:

def set_enum_by_string(node, attribute, string):
    enum_string = pm.attributeQuery(attribute, node=node, listEnum=True)[0]
    enum_options = enum_string.split(":")
    index = enum_options.index(string)
    pm.setAttr("%s.%s" % (node, attribute), index)

Example use:
set_enum_by_string(“my_super_cube”, “color”, “green”)