Maya – Use Type node to set the frame number to scene geometry

Maya – Use Type node to set the frame number to scene geometry

Sometimes it’s useful to have a geometry displaying a changing number.  As an example of how to do this, I’m showing how to set the frame number into some geometry using the Maya type node.  You can use a similar system to drive values from an anim curve into the type node, as well.  (Just adjust the python script to call getAttr on your curve instead of querying the current frame.)

The Maya ‘type’ node’s textInput field is a strange beast. To operate correctly, it needs its input to be each individual character encoded as its hex value, but all passed as a space-delimited string.  This script handles the necessary tap dance.

So in order for the Maya type node to write “testString”, a type node’s .textInput attribute needs to be set to the string: “74 65 73 74 53 74 72 69 6e 67” .

frameToType.py.zip

We use the python built-in codecs module to encode each character of our input string into the hexidecimal value that the type node wants as input.

codecs.encode(str(d), 'hex_codec')

We dump these value into an array, then join them to create the space-delimited string:

hexFrameString = " ".join(hexFrameCodes)

Then set that value into the attribute:

mc.setAttr(typeObj+".textInput",hexFrameString,type="string")

 

Leave a reply