Jump to content

dopoption() equivalent in Python


Zero

Recommended Posts

Hello there,

I've searched both the Houdini docs as well as the forums, but I can't find the solution. I'm relatively new to Houdini and have a considerable Python background, so while learning Houdini, I try to do everything in Python. I've learned about the dopoption() command in Hscript, and managed to use it in my own tests but I would really like to use as little Hscript as possible. As a matter of fact, my expression is in Python, but to get the option out of the currently processed object in a DOP node, I have to do:

hscriptExpression("dopoption($DOPNET, $OBJID, 'Position', 'tx')")

I would really like to know what the proper, "pythonic" way of achieving this would be. Many thanks in advance.

Link to comment
Share on other sites

To get the equivalent of dopoption() you can do something like this:

dopobject = some instance of hou.DopObject
position_subdata = dopobject.findSubData("Position")
position_options = position_subdata.options()
tx = position_options.field("tx")

Of course you could always do it using a chained together command:

dopobject.findSubData("Position").options().field("tx")

If you are doing this as part of an expresion you'll have to use lvar("OBJID") in order to help get the currently being worked on DOP object since hou.DopNode does not have a hou.DopNode.curObject() function.

dopobject = hou.pwd().simulation().findObject(str(lvar("OBJID")))

Link to comment
Share on other sites

Brilliant! Thank you so much, that's exactly what I was looking for. And although

pwd().simulation().findObject(str(lvar("OBJID"))).findSubData("Position").options().field("tx")

is much longer than what I had before, at least I've learned a lot more about the hou module. Thanks again.

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