Jump to content

Finding the Number of Groups in a SOP


Recommended Posts

You could use the opinfo -v operator_name command to print out the info for that node. From there, you should see the group listed in amongst the other data, consistently formatted. You can then strip out just the group names in to a string variable then run argc($group_list) to count the number of groups.

-jeff

Link to comment
Share on other sites

  • 2 weeks later...

I've often thought about string handling bits and blobs in houdini but I usually give up quickly because I'm not sure on how to do it. So how exactly would you extract "the 2nd word of the 3rd line" for example?

Say that you want to include something simple in a callback script. Or do you use external unix scripts for this?

Link to comment
Share on other sites

For single line processing, hscript is not too bad. To grab the second word out of a line, you can use the ever so handy arg( string value, float offset) expression where the string is your text and offset is the number of words starting from 0 left to right:

/ -> set myvar = "Long live Arctor the great!"

/ -> echo `arg( $myvar, 1)`

live

/ -> echo `strcat( arg( $myvar, 1), arg( $myvar, 4)`

live great

As you can see, strcat() concatenates two strings together. strcat() is pretty bullet-proof but a bit limiting. You can use a "c-like" string addition as follows:

/ -> echo `arg($myvar, 1) + arg($myvar, 4) + " Arctor"`

live great Arctor

You can go as long as you need. I needed the double quotes around " Arctor" to keep the space.

Now to process line information inside hscript, you can use a foreach() loop and treat every element separately, line by line extracting and running what you need.

If you need to process opscript dumps from operators on disk, then learn a tool like awk and sed, perl, python or any scriptable text formattor editor and use hscript unix commands to execute them.

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.

Guest
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...