How to Select All Material-Bound USD.prims Via Python?

   2455   4   2
User Avatar
Member
159 posts
Joined: July 2010
Online
In the Solaris LOPs stage context, in the Scene Graph Tree, when you right-mouse on a material, there is a menu item called Select All Bound Geometry.
I would like to be able to do this via python. i.e. return a list of all the USD.prims that are bound to this material. So that I can programmatically make modifications.

I checked here, but couldn't find any reference to this function:
https://www.sidefx.com/docs/houdini/nodes/lop/pythonscript.html [www.sidefx.com]

Thanks

Attachments:
Screen Shot 2021-12-31 at 2.04.46 PM.png (565.0 KB)

User Avatar
Staff
4438 posts
Joined: July 2005
Offline
On that page, look for the example of using a hou.LopSelectionRule (search for `setPathPattern`). Then just change the setPathPattern call to `ls.setPathPattern('%geofrommat:/materials/iaTank_BrassMaterial')` (see https://www.sidefx.com/docs/houdini19.0/solaris/pattern.html [www.sidefx.com] for more information on specifying patterns).
User Avatar
Member
55 posts
Joined: Nov. 2019
Offline
I don't know if syntheticperson's question was more in the line of, "what is the python equivalent that computes %geofrommat/select all bound geometry?" For %matfromgeo we can use
bound_material, _ = UsdShade.MaterialBindingAPI(prim).ComputeBoundMaterial()
, but I am failing to find anything that could do the %geofrommat.

Does anyone know a python func that could do that?


links: https://docs.omniverse.nvidia.com/kit/docs/omni.kit.usd_docs/latest/USD%20in%20Kit.html [docs.omniverse.nvidia.com]
https://openusd.org/release/api/class_usd_shade_material_binding_a_p_i.html#a5602550a78f68f6a1d1bf62187e22edd [openusd.org]
Edited by Cicuta - July 3, 2023 11:21:30
User Avatar
Member
55 posts
Joined: Nov. 2019
Offline
mtucker
On that page, look for the example of using a hou.LopSelectionRule (search for `setPathPattern`). Then just change the setPathPattern call to `ls.setPathPattern('%geofrommat:/materials/iaTank_BrassMaterial')` (see https://www.sidefx.com/docs/houdini19.0/solaris/pattern.html [www.sidefx.com] for more information on specifying patterns).
The method you suggested, when working with a bit more complex scripts will quickly run into the following warning "Read lock failed because of existing lock: ... This may cause performance issues, and should be avoided if possible", which I am not too sure what it actually means and its implications.

More on that warning in this topic: https://www.sidefx.com/forum/topic/76543/ [www.sidefx.com]

Thanks!
Edited by Cicuta - July 4, 2023 06:20:56
User Avatar
Staff
451 posts
Joined: June 2020
Offline
Cicuta
More on that warning in this topic: https://www.sidefx.com/forum/topic/76543/ [www.sidefx.com]

I'll reply with more info re this topic, on that page.
  • Quick Links