Hi there,
I've been trying to figure it out for a while now without sucess so thought I'd ask here.. I'd like to be able to query certain PDG attributes at various points in a TOPs graph in a Python expression, so I can use the data to set things on channels etc.
For example if I have 2 wedge nodes stacked, so that in total they are producing 9 individual wedges, how can I procedurally get that wedge count of 9 in a Python expression?
One way I thought was to just query the number of work items on the second wedge node.. or would a better way be to get the entire list of the ‘wedgeIndex’ attribute and find the max value in that list?
If so, how would I go about doing that in a Python expression?
Also if there's any Python expression examples you guys could point me to it would be super helpful.. for example this thread was great: https://www.sidefx.com/forum/topic/68258/?page=1#post-292979 [www.sidefx.com]
..with the post feom tpetrick showing how to get the list of wedge attributes for a current work item.
This is almost what I need but instead I need the total number of wedges in the graph, so I don't think I can get that from a single work item query like in the example from that thread.
Thanks for any help!
Using Python expression to query TOPs info, ie. wedge count
6083 3 1- Chats
- Member
- 43 posts
- Joined: Dec. 2010
- Offline
- tpetrick
- Staff
- 600 posts
- Joined: May 2014
- Offline
In the general case you need to use a partitioner is you want to access information that spans multiple work items. Work items can cook in parallel, and if your node is dynamic they come into existence at different points in time as well. Partitioner nodes allow you wait for multiple work items to be completed. All partitions have a “partitionsize” attribute which tells you how many work items are in that particular partition. You could, for example, put a Wait for All node after your wedge node, which will have that partitionsize attribute that has the number of work items in the wedge node. You could then wire an attribute copy into both the wedge node and wait for all to copy that onto the wedge work items.
TOP nodes apply their procedure for each input work item, so expressions in parameters are also evaluated per work item. In an expression on a TOP node you can access work item attributes using @attribute, or in Python using pdg.workItem().intAttribValue(“attribute”). Both of those are evaluated against whatever work item the node is processing, and would let you access the attribute copied on earlier.
Alternatively, if you know that the wedge nodes will always be static (which is probably the case), you could use a Python Processor to directly copy the input work item length into an attribute. Or an expression that accesses the input TOP node and gets the number of work items in that node.
I've attached an example file for you that shows all three cases. I've also logged an RFE for the Wedge node to automatically create a “wedgecount” attribute, since that's something we can provide internally.
Edit: Sorry, I believe you mentioned this is another a thread but are you using Houdini 18.0 or 17.5? If you're using 17.5 all three approaches will work in the same way, but some of the API methods I used in my example file are from the improved attribute API in 18.0. I can attach a 17.5 version of the file if you need it.
TOP nodes apply their procedure for each input work item, so expressions in parameters are also evaluated per work item. In an expression on a TOP node you can access work item attributes using @attribute, or in Python using pdg.workItem().intAttribValue(“attribute”). Both of those are evaluated against whatever work item the node is processing, and would let you access the attribute copied on earlier.
Alternatively, if you know that the wedge nodes will always be static (which is probably the case), you could use a Python Processor to directly copy the input work item length into an attribute. Or an expression that accesses the input TOP node and gets the number of work items in that node.
I've attached an example file for you that shows all three cases. I've also logged an RFE for the Wedge node to automatically create a “wedgecount” attribute, since that's something we can provide internally.
Edit: Sorry, I believe you mentioned this is another a thread but are you using Houdini 18.0 or 17.5? If you're using 17.5 all three approaches will work in the same way, but some of the API methods I used in my example file are from the improved attribute API in 18.0. I can attach a 17.5 version of the file if you need it.
Edited by tpetrick - Dec. 5, 2019 20:48:04
- Alejandro Echeverry
- Member
- 691 posts
- Joined: June 2006
- Offline
tpetrick
I've attached an example file for you that shows all three cases. I've also logged an RFE for the Wedge node to automatically create a “wedgecount” attribute, since that's something we can provide internally.
Hi tptrick!
Will this RFE came to a reality soon? I think is a must to have!
Thanks,
Alejandro
Feel The Knowledge, Kiss The Goat!!!
http://www.linkedin.com/in/alejandroecheverry [linkedin.com]
http://vimeo.com/lordpazuzu/videos [vimeo.com]
http://www.linkedin.com/in/alejandroecheverry [linkedin.com]
http://vimeo.com/lordpazuzu/videos [vimeo.com]
- tpetrick
- Staff
- 600 posts
- Joined: May 2014
- Offline
Hey Alejandro, thanks for the reminder about this issue.
Starting with the next daily build of 18.5, there'll be two new attributes on work items in the wedge node. The wedgetotal has the total number of work items, and wedgecount has the value of the Wedge Count parameter. The reason there's a difference is for when you're doing multiple layers of wedging. If you have a wedge node with 4 variations followed by a wedge node with the 3, then the wedgetotal will be 12 in the second node. The wedgecount will be 3, since that's the value for that node. For example:
The attributes also work with the Preserve Wedge Numbers toggle. If you enable that parm, then the wedge counts from each layer are stored in an array. Using the same example set up, the wedgecount would be 4,3 with that option enabled:
This is currently only in 18.5, but I'll backport to 18.0 next week. A portion of the change has to be re-implemented in 18.0 since its making use of a new API method in 18.5.
Starting with the next daily build of 18.5, there'll be two new attributes on work items in the wedge node. The wedgetotal has the total number of work items, and wedgecount has the value of the Wedge Count parameter. The reason there's a difference is for when you're doing multiple layers of wedging. If you have a wedge node with 4 variations followed by a wedge node with the 3, then the wedgetotal will be 12 in the second node. The wedgecount will be 3, since that's the value for that node. For example:
The attributes also work with the Preserve Wedge Numbers toggle. If you enable that parm, then the wedge counts from each layer are stored in an array. Using the same example set up, the wedgecount would be 4,3 with that option enabled:
This is currently only in 18.5, but I'll backport to 18.0 next week. A portion of the change has to be re-implemented in 18.0 since its making use of a new API method in 18.5.
Edited by tpetrick - Oct. 23, 2020 18:04:37
-
- Quick Links