Procedural Primitives
Adding an Interface


return to main index

Code:
    starter_proc.py


Introduction

This tutorial is a leads on from the tutorial "Procedural Primitives:Getting Started". It is assumed the reader has followed it's instructions has has compiled a DSO (Dynamic Shared Object) called StarterProc.so (OSX and Linux) or StarterProc.dll (Windows).


Passing data to the procedural primitive by editing the Data textfield is very prone to error. This section demonstrates how custom attributes can be added to the RenderManProcedural and, via a small python script, their values can directly control the Data textfield.

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



Figure 1


In the outliner select the shape node of the RenderManProcedural.



Figure 2


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



Figure 3


Create an integer 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 4


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 "starter_proc.py" in the,
    maya/rfm_scripts/python/
folder.


Listing 1 - starter_proc.py


import maya.cmds as cmds
  
# import rfm2.api.strings as apistr; import starter_proc; starter_proc.setDataStr(apistr.expand_string("<shape>"))
def setDataStr(shapeName):
    num = str(cmds.getAttr(shapeName + '.num_spheres'))
    rad = str(cmds.getAttr(shapeName + '.radius'))
    text = rad + " " + num + " "
    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 starter_proc; starter_proc.setDataStr(apistr.expand_string("<shape>"))


Figure 5


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


Figure 6


If the python script starter_proc.py is edited make sure it is imported and reloaded.



Figure 7








© 2002- Malcolm Kesson. All rights reserved.