Procedural Primitives
Getting Started

return to main index


This tutorial is a brief introduction to the writing, compiling and use of procedural primitives with Maya. The C language code used by this tutorial implements a traditional RiProcedural interface - not the newer RiProcedural2 interface.

The C Code

From Cutter's Template menu choose Procedural Prim->GenSpheresProc.cpp.

Figure 1

Save the file as StarterProc.cpp in the following location,

Compiling and Building the ProcPrim

Use the keyboard shortcut Alt+e, Control+e or Apple+e. A Process Monitor window will open. Ensure the DSO has been successfully compiled and built.

Figure 2

For information on how to set up Cutter's compilation environment refer to C++ Development Environment.

Using the ProcPrim with Maya

From the RenderMan menu choose Archive->Create Procedural Node.

Figure 3

Use the directory browse button to locate the DSO. On Windows the DSO will be named StarterProc.dll.

Figure 4

In the Data textfield enter the following text (make sure there is a space between the two numbers)
    50 0.2
Render a frame and you should be rewarded with 50 spheres of 0.2 units in radius.

Figure 5

Adding an Interface

Passing data to the procedural primitive ( or StarterProc.dll) by editing the Data textfield is very prone to error. This section demonstrates how custom attributes can added to the Attribute Editor and, via a small python script, their values can directly control the Data textfield.

In Maya's outliner choose, Display->Shapes.

Figure 6

In the outliner select the shape node of the RenderManProcedural.

Figure 7

In the Attribute Editor for the RenderManProceduralShape choose,
    Attributes->Add Attributes...

Figure 8

Create an int attribute named "num_spheres",
Create a float attribute named "radius".

Make sure the names are lower case and that "Override nice name" is checked and that the nice name is also lower case. The new attributes will appear at the bottom of the panel. Make sure they have reasonable default values.

Figure 9

Connecting the Interface

A small python script will be used to update the ProcPrim Data textfield when the values of the custom int and float attributes are adjusted. Copy and paste the code from listing 1 into a document and save it as "" in the,
    maya/rfm_scripts/python/ folder.

Listing 1 -

import maya.cmds as cmds
# import rfm2.api.strings as apistr; import proc_data; proc_data.StarterProc(apistr.expand_string("<shape>"))
def StarterProc(shapeName):
    num = str(cmds.getAttr(shapeName + '.num_spheres'))
    rad = str(cmds.getAttr(shapeName + '.radius'))
    text = num + " " + rad + " "
    cmds.setAttr(shapeName + '.data', text, type='string')

In the "RenderManProceduralShape->Scripts->Pre Shape Python Script" textfield copy and paste the following python code. Note the code must be pasted as a single line of text.

import rfm2.api.strings as apistr; import proc_data; proc_data.StarterProc(apistr.expand_string("<shape>"))

Figure 10

Adjust the values of the num_spheres and radius attributes and note upon re-rendering the scene the Data textfield is automatically updated.

Figure 11

© 2002- Malcolm Kesson. All rights reserved.