Fix broken NURBS surface in Maya

Fix broken NURBS surface in Maya

In this post, I will talk about a simple script that repairs all the broken NURBS surfaces in a scene.

Preface

Xwift is a shelf that contains specialized scripts when I was producing my animated film. I want to write some blogs to document them, in case there’s anyone out there that needs some inspiration.

Everything is developed and tested using Maya 2022.

Swift is not (well, not yet) open-source and therefore I will not share the whole script in my post. However, after reading my posts I believe you can implement your own, given some time and effort.

Introduction

Okie this one will be a short one. There are often times when the rigger in your production wants to go fancy and use NURBS surfaces instead of NURBS curves for rigs to make things much, much easier to click. In my case, Cody Wilcoxon (Seriously, this guy is a Maya god).

But Maya lags behind. Sometimes, when referenced, all the NURBS surfaces on your fancy rig break. It is nasty.

Broken NURBS Surfaces A Rig with broken NURBS surfaces

The Fix

First, we need to dig the Maya documentation for rebuilding NURBS surfaces.

Good for you, I did the work already. In case if you are interested, here’s the documentation for rebuildSurfaces.

Let’s write a helper function that help execute the commands.

# Returns a command that when executed, will rebuild the given surface.
def rebuild_surface_cmd(surface, caching = "1",
                        replaceOriginal = "1",
                        endKnots = "1",
                        keepRange = "0",
                        keepControlPoints = "0",
                        keepCorners = "0"):
    general_cmds = " -ch " + caching + " -rpo " + replaceOriginal + " -end " + endKnots
    keep_cmds = " -kr " + keepRange + " -kcp " + keepControlPoints + " -kc " + keepCorners
    surface_cmd = " \"" + surface + "\""
    
    cmd = "rebuildSurface" + general_cmds + keep_cmds + surface_cmd
    return cmd

Now, we need to get a list of all the surfaces. We can do that by using cmds.ls(type='nurbsSurface') and feed all of them into the function above.

def fix_broken_NURBS(self):
    surface_list = cmds.ls(type='nurbsSurface')
    for surface in surface_list:
        command = rebuild_surface_cmd(surface)
        try:
            mel.eval(command) 
        except RuntimeError:
            print("[Fix-it] Failed to rebuild the following surface: " + surface)
        except:
            print("[Fix-it] Unknown error occurred while trying to execute: " + command)
    print("[Fix-it] Fix Broken NURBS - Successfully rebuilt all available NURBS Surfaces.")

Bind fix_broken_NURBS() to a button and you are all set.

Fixed NURBS Surfaces A Rig with fixed NURBS surfaces

Demo

Seriously, this is low key satisfying to watch. Fixed NURBS Surfaces

Conclusion

Next time when you see every single NURBS surface on a rig is broken, keep calm and press the button.

Note: For advanced use, you can consider integrate this into your asset manager from your studio when you try to reference a rig into the scene. The animators will be happy!

If you want to quickly say hi just shoot me a message using the contact portal.

Fix broken NURBS surface in Maya
Older post

Automating Script Install in Maya

Newer post

Rename Negative Padding Render in Maya

Fix broken NURBS surface in Maya