Hi
I'm trying to resolve a LopSelectionRule and yet in the simplest of scenes I get an error saying “infinite recursion” - what am I doing wrong here?
jsmackHi! Any updates on what this warning means and how to deal with it?
instead of hou.pwd(), what about the input node?
Edit:
I get a warning about a read lock fail due to existing lock when I tried it. Not sure how it's supposed to be used.
Tim CrowsonSame, would be awesome to get a deeper understanding on this topic. Thanks!
I have to admit I still see this "Read lock failed because of existing lock" message from time. I am uncertain 1) what it actually means, 2) how it's really effecting performance and 3) what I'm supposed to do about it.
stage()
or editableStage()
, we perform the necessary mutation to ensure the shared stage has the right composition for the node you called that method on. We then lock things so you can get a consistent view of the stage for the lifetime of your variable without it further mutating under your feet.stage()
/editableStage()
multiple times!", but you may be triggering the same effect through other calls - selection rule expansion is the one we most commonly see. If we consider the "Dim the lights" example for the Python LOP, there's a block:ls = hou.LopSelectionRule() ls.setPathPattern('%type:Light') paths = ls.expandedPaths(node.inputs()[0])
expandedPaths
line) is effectively asking for the stage from node.inputs()[0]
, so if you've previously asked for the stage from node
, you've just run into the "need to recompose a whole new stage for you" situation.editableStage()
when you truly need to do the authoring.theLockedStage = node.editableStage()
you can call ls.expandedPaths(stage=theLockedStage)
without the recomposition hit.robp_sidefx
We generally advise doing as much reading up-front as possible (and, if necessary, scoping your variables to help release locks as early as possible) and only callingeditableStage()
when you truly need to do the authoring.
robp_sidefx
Something else we added in Houdini 19.5, which we've perhaps not advertised well enough, is the ability to evaluate selection rules directly against stages rather than nodes (from which we internally extract a stage). So if you've already run something liketheLockedStage = node.editableStage()
you can callls.expandedPaths(stage=theLockedStage)
without the recomposition hit.
robp_sidefx
I hope this offers better insight into the warning you're getting. Do take it seriously with larger scenes; recomposition can be very expensive.
Cicuta
So this means that for now, if we need to access stage to get the data for setPathParent(), there is no way around it. We have to call stage at least twice.
ls.expandedPaths(node.inputs()[0])
can be replaced with ls.expandedPaths(stage=stage)
and the warning will go away.node = hou.pwd() from pxr import Usd, UsdGeom, UsdShade # SHARED coll_path = "/collections/fx" bound_list = [] # READING stage = node.inputs()[0].stage() coll = stage.GetPrimAtPath(coll_path) coll_api = Usd.CollectionAPI(coll, "key") key_coll = coll_api.GetIncludesRel() targets = key_coll.GetTargets() for target in targets: material_path = target.GetParentPath() material = stage.GetPrimAtPath(material_path) ls = hou.LopSelectionRule() expression = "%geofrommat:" + str(material.GetPath()) ls.setPathPattern(expression) bound = ls.expandedPaths(node.inputs()[0])[0] # or replace "node.inputs()[0]" with "stage=stage" bound_list.append(str(bound)) # WRITING stage = node.editableStage() coll = stage.GetPrimAtPath(coll_path) coll_api = Usd.CollectionAPI(coll, "bound") bound_coll = coll_api.GetIncludesRel() bound_coll.SetTargets(bound_list)
stage = node.inputs()[0].stage()
Cicuta
what is the programmatic logic behind the %geofrommat pattern/"Select All Bound Geometry"?
Are there plans on having something similar in python or VEX?
robp_sidefx
It's part of the public Github repo, so I'll take the easy way out here and say "have a look for yourself"
https://github.com/sideeffects/HoudiniUsdBridge/blob/houdini19.5/src/houdini/lib/H_USD/HUSD/XUSD_AutoCollection.C#L1778-L1857 [github.com]