So it seems that the order of the primitives specified in the Primitives parameter has no bearing, and a Vexpression will always use the ordering from the Scene Graph Tree?
So, if I have this scene structure:
/ -Obj1 -Obj2 -Obj3
but in the Primitives parameter write them in reverse order as
/Obj3 /Obj2 /Obj1
, @elemnum will still use the ordering from the SGT?
If this is the case, then is there a way to override this ordering, and have the Vexpression use the list as it is defined in the Primitives parameter?
I don't think this is possible with VEX, since it's just traversing the stage the way USD presents it? And with VEX being a SIMD-like kernel you can't guarantee ordering when you start threading code...
If you need something to run serially, then I'd use Python; though I guess you could do a manual loop in VEX to make it loop over primitives in a specific order, but that sounds messy compared to Python.
Thank you for clarifying. Some more detail - I'm reading textures from a folder into a string array using Python. I write that array to a primvar, and then use a Vexpression on an Assign Material LOP to override the 'File' parameter on a USD UV Texture VOP.
It works fine, except that I cannot control the ordering of the texture assignment.
Here's the Python code:
node=hou.pwd()stage=node.editableStage()importosfrompxrimportSdf,Usd,UsdGeom# read the texture path from the parameter in the UIuserpath=hou.parm('./tp').eval()# if no custom path is set, use $HIP/tex as the defaultifuserpath=="":texpath=os.path.dirname(hou.hipFile.path())+'/tex'else:texpath=userpathfiles=[]# create an array of acceptable file extensions# only files with these extensions will get added to the files arrayext=(".jpg",".png",".bmp",".hdr",".exr")# get list of file namesfornamesinos.listdir(texpath):ifnames.lower().endswith(tuple(ext)):texname=texpath+'/'+namesfiles.append(texname)# usd thingsasset=stage.GetPrimAtPath('/')primvarsapi=UsdGeom.PrimvarsAPI(asset)# create the primvarprimvar=primvarsapi.CreatePrimvar('texpaths',Sdf.ValueTypeNames.StringArray)# write the file list to the primvarprimvar.Set(files)
Here is the Vexpression:
And here it is in action:
If you see my folder structure, you'll see that they don't match the objects from left to right. I thought I could fix that with the Primitives parameter, but that doesn't work, and I can't see an easy way to fix this without renaming the images to match (which is clunky), or doing manual assignments in the Vexpression, which is also clunky.
Perhaps another way to do the overrides? I only know this way currently.