from pxr import Usd, UsdGeom, Sdf
stage = hou.pwd().editableStage()
for prim in stage.Traverse():
if prim.IsA(UsdGeom.Xform) and "/Prototypes" in prim.GetPath().pathString:
proto_path = prim.GetPath().pathString
proto_index = proto_path.split("/")[-1]
mesh_index = proto_path.split("/")[-4]
attr = prim.CreateAttribute("primvars:dneg:envTreesID", Sdf.ValueTypeNames.String)
attr.Set(proto_index)
for child_prim in prim.GetChildren():
if child_prim.IsA(UsdGeom.Mesh):
mesh_attr = child_prim.CreateAttribute("primvars:dneg:envTreesID", Sdf.ValueTypeNames.String)
mesh_attr.Set(mesh_index)
print("Assigned the correct envTreesID value to meshes within prototypes.")