Jump to content

python sop with expression and local variable support


dougb

Recommended Posts

Hi,

I'm just starting to convert some of our tools over to Python and I have hit my first wall. I need to be able to evaluate expressions (hscript expressions and/or python) with full support for local variables while looping over a set of points or prims. I found the curPoint() method within the Sop/PopNode() classes however it does not exactly work as expected (like the HDK), or perhaps I am over complicating things.

Has anyone created a Sop or Pop with support for expressions (including local vars)? Think point sop or attribute create.... For what its worth I have a bunch of 'utility' nodes that I am porting and I do plan to release them to the general public as soon as they work and I get buy off from the Sony suits. I also have mail in to support but figured I would try the general population too.

thanks,

Doug

Link to comment
Share on other sites

Hey Doug, I'm pretty sure that Python Sops don't support local variables in parameter evaluation due to the fact that they don't really cook for each point. I'll have to ask tomorrow once the guys in TO get back to confirm.

curPoint() is the HOM equivalent of $PT in an expression, but returning a hou.Point object which is kind of not useful. You can get the numerical equivalent by doing hou.curPoint().number().

Local vars can also be gotten using lvar() (lvar('PT'), lvar('VY'), lvar('BLAHX'), though not particularly useful when trying to perform actions in the cooking loop of a python sop.

Sorry for the lackluster and short explanation but I'm running out the door. Hopefully I was at least a tiny bit helpful and I'll be able to provide some more in depth info tomorrow.

Link to comment
Share on other sites

I believe Doug already knows this, but for anyone else who cares, the ability to do this has been backported to Houdini 9.5 and will be available in tomorrows build, 9.5.274.

The function that allows this to work now is the hou.SopNode.setCurPoint() function. This takes a hou.Point as an argument.

This can be used as follows to set the point position based on a 't' parameter from within a Python Sop operator.

for point in geo.points()
    hou.pwd().setCurPoint(point)
    new_pos = hou.pwd().evalParmTuple('t')
    point.setPosition(new_pos)

This iterates through each point and sets the point as being current, so evaluating something like '$PT' in the parameter will correctly resolve to the current point.

If you use Python geometry operators, definitely check out the Journal tomorrow as a bunch of useful abilities have been added.

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