pythonscript to press button on node per work item

   3801   6   0
User Avatar
Member
75 posts
Joined:
Offline
I've got a python script I'd like to run from PDG via inProcesScheduler (using single), that runs pressButton()on a node I have in my wedge network.
I'd like this to run as the last step after writing out all my simulation wedges.

When I manually switch my wedge top to each work item, it properly switches and cooks the file path changes I'm doing per workItem correctly. The pressButton() then is supposed to build a new file read node using each adjusted wedge path.

However when I cook the pythonScript top, it seems that whats happening is that the button is being pressed each time, but the wedge parm change is not cooking, and I end up with the same path/name for every file node that the pressButton() is generating.

Is there a proper way I can force a cook one work item at a time, to get my wedge values to update before I run the pressButton()? I tried running node.cook() in my python script right before my pressButton() but that seems to lock up my session.

Any advice would be appreciated
thanks!
User Avatar
Member
75 posts
Joined:
Offline
Anyone ever try this? or have any suggestions for different ways to tackle this idea?
Tried a few other things in the script but still getting either no change in paths, or houdni lockups which I am starting to assume is a cook race condition or something.

thanks
User Avatar
Staff
585 posts
Joined: May 2014
Offline
PDG work items cook in the background, so you can't safely modify the current scene or trigger a cook from within a Python Script TOP. Are you able to attach a .hip demonstrating what you're trying to do?
User Avatar
Member
75 posts
Joined:
Offline
Hmm ok I guess I misunderstood how it works a bit, I thought that inprocessscheduler with “single” would still work in a non-parallel fashion so even if it were working in the background, it would still be “blocking” enough to be able to modify the scene data. If there is no way to currently do this in TOPS I would like to suggest that something like that be added as I can think of a bunch of uses for building “self building” tools or setups like I'm trying to do.

I would have to make a simplified version of the scene i have, to attach. I will try later!

In the mean time, a simple enough work around for me at the moment would be if you could point me in the direction of the python code needed to step thru a tops wedge node in a for loop, like you were clicking on each workitem dot in the UI, so it updates to that wedge, so I can then run my other commands.

Thanks so much for the reply!

-johnc
User Avatar
Staff
585 posts
Joined: May 2014
Offline
Yep, there's an existing RFE to add a job parm to the in process scheduler that lets a work item run on the main thread. Single just means only one work item of that type can run at a time, but the work item still runs on a background thread.
User Avatar
Member
75 posts
Joined:
Offline
Awesome! Good to know it might be coming down the road!

Still digging thru the pdg python docs, I think I found pdg.WorkItem.makeActive() so that may get me on the right track.

thanks!
User Avatar
Staff
585 posts
Joined: May 2014
Offline
The pdg.WorkItem.makeActive context manager actually only works when used during a PDG cook, but there's no real reason for that to be the case. I've fixed it so that starting with tomorrow's daily build you'll be able to use it outside of a cook as well. For example, you'll be able to do something like the following from the Python Shell:

top_node = hou.node('/obj/topnet1/genericgenerator1')
pdg_node = top_node.getPDGNode()
for work_item in pdg_node.workItems:
    with work_item.makeActive():
        print(top_node.parm('pdg_command').eval())

In that example I'm evaluating a parm which has a work item @attribute expression in it, and therefore needs an active work item to evaluate against.

The TOP node itself also has methods for selecting a work item in the UI, but that's specifically for UI interaction (see https://www.sidefx.com/docs/houdini/hom/hou/TopNode.html).
Edited by tpetrick - May 28, 2020 18:05:00
  • Quick Links