referencing interactive layer with Python Script LOP

   1247   3   1
User Avatar
Member
26 posts
Joined: June 2019
Offline
Hi everyone!
I am trying to use the Python Script LOP to reference a layer living on another LOP.
Basically, i want to replicate the Reference LOP in code, when it's set to 'reference from multi-input'
The other node that i am referencing has its save path configured with a configure Layer.

Typically, in my code, I'd like to use sthg like
 GetReferences().AddReferences(<mylayer.usd>)
, but instead of passing a filename, i would like to point to this 'in-memory layer'.

Can this be done ? ( i know it's using the HoudiniLayerInfo somehow).

I've tried calling the root layer, the session layer of the stage? editable stage? of the other node... it doesn't seem to work.
Should i do that with Sdf instead. Not sure how ?

(the motivation behind all this is to use the same code for working on interactive layers or layers on disk, and essentially prototype the code on a Python Script LOP)

Hope this makes sense !
Thanks a lot
User Avatar
Staff
4177 posts
Joined: Sept. 2007
Offline
You need to use the layer's identifier:

node = hou.pwd()

input_node = node.node("../sphere1")
ref_layer = input_node.stage().GetRootLayer()

stage = node.editableStage()
prim = stage.DefinePrim("/foo")
prim.GetReferences().AddReference(ref_layer.identifier, "/sphere1")

Unless there is a default prim designated, you'll also want to specify a prim path to reference from.

Hope that helps!

Attachments:
python_reference_lop_node.hip (96.6 KB)

I'm o.d.d.
User Avatar
Staff
4177 posts
Joined: Sept. 2007
Offline
Some important details that were highlighted after posted this suggestion, as there is currently no robust/trustworthy way in Python to reference nodes using Python. The Reference LOP works behind the scenes to make a locked stage, so it can reference the LOP node safely. The Python approach may never have any issues, but you could find yourself with strange behavior pretty easily too as you click around and display/recook different nodes.

So take the above suggestion with a healthy dose of "YMMV"

If you do end up with strange behavior that keeps breaking things, try using the LOP nodes to re-create layer setups in Solaris. It would probably mean you'd have to be creative to use your scripts and get equivalent behavior to the LOP layers as you get with file-based layers.
I'm o.d.d.
User Avatar
Member
26 posts
Joined: June 2019
Offline
Thanks so much!
.identifier
was indeed what I was missing!
This code will be in a converter hda that should only run once, so hopefully there shouldn't be too much recooking involved
  • Quick Links