Hi,
When I Object Merge, the operator wipe all materials applied directly to obj.
Does someone has a ready made custom obj merge to do that ?
# Support multiple selected nodes for n in hou.selectedNodes(): # Only operate on Obj Merge SOPs if n.type().name() == 'object_merge': # Set variables for our nodes p = n.parent() m = p.createNode('material') objnode = hou.node(hou.parm(n.path()+"/objpath1").eval()) # Connect the material sop to the obj merge sop m.setInput(0,n) # Point the material sop to the obj's material hou.parm(m.path() + "/shop_materialpath1").set(hou.parm(objnode.path() + "/shop_materialpath").eval()) # Move it below the merge node m.moveToGoodPosition()
goldleaf
Here's one way; add this bit of Python to a shelf tool:
# Support multiple selected nodes
for n in hou.selectedNodes():
# Only operate on Obj Merge SOPs
if n.type().name() == ‘object_merge’:
# Set variables for our nodes
p = n.parent()
m = p.createNode('material')
objnode = hou.node(hou.parm(n.path()+“/objpath1”).eval())
# Connect the material sop to the obj merge sop
m.setInput(0,n)
# Point the material sop to the obj's material
hou.parm(m.path() + “/shop_materialpath1”).set(hou.parm(objnode.path() + “/shop_materialpath”).eval())
# Move it below the merge node
m.moveToGoodPosition()
Now, any selected Obj Merge SOPs will get a Material SOP connected to its output, set to the Obj Node's material.
The attached hip file is an example. Note that the merged and Obj Merge'd geometries all need to have matching attributes. If they don't match, then non of the materials will render correctly.
Hope that helps!
/shop_materialpath1
text inside the string.
objnode
isn't a Geometry object, there won't be a shop_materialpath
parameter. I guess the script will only work if the Object Merge SOPs are merging from objects, instead of directly from SOPs. You could probably check if objnode is type geo
, and if not, switch to using its parent. Putting omething like the following code before the evaluation line might work, (though I'm not great with Python, so I'm just guessing) :if objnode.type().name() != 'geo': objnode = objnode.parent()
# Support multiple selected nodes for n in hou.selectedNodes(): # Only operate on Obj Merge SOPs if n.type().name() == 'object_merge': # Set variables for our nodes p = n.parent() m = p.createNode('material') objnode = hou.node(hou.parm(n.path()+"/objpath1").eval()) # Connect the material sop to the obj merge sop m.setInput(0,n) # Move it below the merge node m.moveToGoodPosition() # Point the material sop to the obj's material if objnode.type().name() != 'geo': objnode = objnode.parent() hou.parm(m.path() + "/shop_materialpath1").set(hou.parm(objnode.path() + "/shop_materialpath").eval())
objnode
was not a Geometry object. I don't often edit other people's posts apart from forum formatting issues, but I figure if it's intended to be a reference for others and you don't mind, it's probably worth it.