Larger Python Functions in Parm Expression? (Object Merge)

   1435   1   0
User Avatar
Member
61 posts
Joined: Feb. 2006
Offline
Hi,
So I get that syntax differs a bit in python parm expressions vs scripts or pythonSOP but I am a bit stumped on this one. I have a scripts I use to automate alembic and Collada imports. One particular function is to filter the contents of collada geo type nodes and any of those nodes that are visible or not. A simple exmaple would be along the lines of :

for node in hou.selectedNodes():
if node.type().name() == ‘geo’:
new_name = ‘Mesh_’ + str(node)
node.setName(new_name, 1)

I am appending names say in this example of geo type nodes so that I merge various sets in another node using object_merge nodes. So, in this example, I would set the objmerge parm to a wildcard ‘Mesh_*’ and so import the various geo meshes I want.

It works fine but it would be super convenient if instead I could set a longer function expression as a python parm instead to filter the merge elements. I haven't been able to work that out though as an expression. Is it possible? Say, to set a python parm expression that in pseudo code will do this?
i.e.,

for nodes in nodes:
if node.type.name = ‘geo’
if node.isVisible():
merge node

So far, I have been working along the lines of using my existing scripts to put the filtered objects into a list and then set the parm expression to a space separated line of string object names with their paths. Obviously though, that is kinda hard coded at the time it is run. I wonder if there is a way for the parm to evaluate the merge filters itself using functions directly (instead of just setting the parm merge field to a string like ‘/obj/object/Mesh1 /obj/object/Mesh2 /obj/object/Mesh3 /obj/object/Mesh4’ etc. or ‘Mesh*’)

Thanks!
Edited by frankvw - March 26, 2018 11:20:11

Attachments:
Screenshot from 2018-03-26 16-01-24.png (41.4 KB)

User Avatar
Member
8575 posts
Joined: July 2007
Offline
you can do anything you want in python, just make sure your expression results in space separated list of paths or patterns

to pull in all displayed objects from /obj level except for objects with object merge using the expression (to avoid recursion) you can use expression like this in your path:

root = hou.node("/obj")
nodes = root.glob("*")
thisobj = hou.pwd().creator()

outnodepaths = [node.path() for node in nodes if node.isObjectDisplayed() and node != thisobj]

return " ".join(outnodepaths)

just be aware that such expression will update only when Object Merge is cooked again, not necessarily immediately as you change display of the objects or add new object
Tomas Slancik
FX Supervisor
Method Studios, NY
  • Quick Links