Curves to Geometry Script

Ever wonder how to render out your nurbs curves? Maybe you wanted to do a nice rendered animation of a rig for a reel? Well, then this is the script for you 😉


import maya.cmds as cmds
import maya.mel as mel

# Converts every curve in the scene into a paint fx stroke and then a renderable polygon object. 
def curveGeo():
    # get all the curves in the scene.
    curves ="nurbsCurve")
    # this array will hold all of the stroke objects for our brush. We will use it to convert our strokes to polys.
    strokes = []
    # one brush for all these strokes ensures we get just one output shader for our strokes, making editing of the shader easier
    brush = cmds.createNode("brush",n="brush#")
    # this is just one of the necessary actions for the brush to work
    cmds.connectAttr("time1.outTime",brush + ".time")
    meshes = []

    for crv in curves:
        # make a stroke node and append it to our stroke array
        stroke = cmds.createNode("stroke",n="stroke#")
        # connect the attributes necessary to draw the stroke around the curve. 
        # This was found out by just doing it manually and looking at what was made in the node editor
        cmds.connectAttr(brush + ".outBrush",stroke + ".brush")
        cmds.connectAttr(crv + ".worldSpace[0]",stroke + ".pathCurve[0].curve")
        # up the samples for sharp cornered objects like arrows
        cmds.setAttr(stroke + ".pathCurve[0].samples",255)
        cmds.setAttr(stroke + ".displayPercent",100)
        cmds.setAttr(brush + ".depth",1)
        cmds.setAttr(brush + ".globalScale",.25)

    for shape in strokes:
        # This command is only accessible in Mel so we have to do a Mel eval for it. 
        # Unfortunately that means we can't access the resulting groups/geo from this action, as it just returns True

# To turn off cast and recieve shadows, select all the brush groups, pickwalk down, 
# and go to Window - General Editors - Attribute Spread Sheet. 
# Under the Render tab, turn off Cast and Receive Shadows.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s