Jump to content

Python the Copy SOP and Font SOP


Recommended Posts


Here's an example of the Python code which is being stamped.

import random
x = ['2', 4, 8, 1, 'fubar', '2&1', 1.1]
return random.choice(x)

However once it is stamped into the text parameter of a Font SOP it only outputs the float/integer items and not the strings in the list.

Is it something to do with the Copy SOP's 'val1' parameter being a float?

Basically I need to randomly select items from an externally created list of varying length and stamp those items onto points particles etc...

Can anybody please point out the obvious for me? Cheers!

I've attached my .hip


Link to comment
Share on other sites

As you mentioned, your main problem is that you are trying to return strings and numbers in a float parameter.

The proper solution would be to just have the stamp variable value as $PT from the input points and then stamp from the Text parm on your Font SOP. This method doesn't care if you are returning strings or numbers.

Another issue is that you are just using a pure random generator without any sort of seeding. This results in purely random results every time you cook so there's no continuity. In the attached file I use the $PT stamp var to drive ramdon.seed() so I get randomness but maintain the randomness every cook.

Alternatively you could instead use the standard Houdini randomization, hou.hmath.rand() using the stamp value and then multiply and convert to int accordingly to get the correct range of values.


Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...