import maya.cmds as cmds
import shape_utils
# In the "RenderManProgramShape->Scripts->Pre Shape Python Script" copy the following text:
# import rfm2.api.strings as apistr; import proc_data; proc_data.PlaceSpheres(apistr.expand_string("<shape>"))
def PlaceSpheres(shapeName):
tnode = cmds.getAttr(shapeName + '.target')
# If the name of the transform node of the target shape has
# not been specified we assume the RenderManProgram has been
# parented to the polymesh that will "receive" the spheres.
if len(tnode) == 0:
tnode = cmds.listRelatives(shapeName, parent=True)[0]
tnode = cmds.listRelatives(tnode, parent=True)[0]
rad = str(cmds.getAttr(shapeName + '.radius'))
use_local_space = cmds.getAttr(shapeName + '.use_local_space')
coords = shape_utils.get_coordinates(tnode, use_local_space)
rounded = []
# Reduce precision to 3 decimal places - less text to pass.
for coord in coords:
rounded.append(round(coord,3))
coords_str = " ".join(map(str, rounded))
text = rad + ' ' + str(len(coords)) + ' ' + coords_str
cmds.setAttr(shapeName + '.data', text, type='string')