Multiple selected nodes to /obj/geo/object merge

   3465   5   1
User Avatar
Member
6 posts
Joined: April 2013
Offline
hello,

something is wrong with the second line. any ideas?
basically i want to object merge all selected sop nodes into its own /obj/geo container with the proper naming.
thanks…

selNodes = hou.selectedNodes()
selNodes_children = []for node in selNodes:
    for child in node.children():
        selNodes_children.append(child)geo = hou.node('/obj').createNode('geo')
geo.children()[0].destroy()
objmerge = geo.createNode('object_merge')
#for parm in objmerge.parms():
#    print parmobjmerge.parm('numobj').eval()
objmerge.setParms({'numobj':len(selNodes_children)})
for i in range(len(selNodes_children)):
    objmerge.setParms({'objpath%d'%(i + 1) : selNodes_children[i].path()})
User Avatar
Member
106 posts
Joined: June 2011
Offline
import hou
selNodes = hou.selectedNodes()
selNodes_children = []
for node in selNodes:
    for child in node.children():
        selNodes_children.append(child)

geo = hou.node('/obj').createNode('geo')
if geo.children():
    geo.deleteItems(geo.children())

objmerge = geo.createNode('object_merge')
objmerge.setParms({'numobj':len(selNodes_children)})
for i in range(len(selNodes_children)):
    objmerge.setParms({'objpath%d'%(i + 1) : selNodes_children[i].path()})

Hope it helps
-J
User Avatar
Member
6 posts
Joined: April 2013
Offline
thanks i was impatient and got help from a colleague…
that code works as a shelf tool. any idea how it could work on a button referencing itself into a geo container?

for each selection:

import hou
selected = hou.selectedNodes()
root = hou.node("/obj")
for node in selected:
        merge_name = node.parent().name() + "_" + node.name()
        container = root.createNode("geo", merge_name + "_extracted")
        merge = container.createNode("object_merge", "objm--" + merge_name)
        merge.parm("objpath1").set(node.path())
        merge.parm("xformtype").set("local")
        container.moveToGoodPosition()

each selection into one geo container:

import hou
selected = hou.selectedNodes()
root = hou.node("/obj")
container = root.createNode("geo", "extracted")
merge = container.createNode("object_merge", "objm--")
merge.parm("numobj").set(0)
merge.parm("xformtype").set("local")
for node in selected:
    i = merge.evalParm("numobj") + 1
    current_path = ("objpath"+str(i))
    merge.parm("numobj").set(i)
    merge.parm(current_path).set(node.path())
Edited by ballinger500 - June 30, 2019 12:08:08
User Avatar
Member
106 posts
Joined: June 2011
Offline
You need to convert your geo container into a digital asset first and add your code as a function under the scripts tab in TypeProperties. Then add a button and have the button run your function as a callback script.
Please check these docs for more info about digital assets.

https://www.sidefx.com/docs/houdini/assets/intro.html [www.sidefx.com]


-J
User Avatar
Member
6 posts
Joined: April 2013
Offline
yes. but the code searches for selected nodes, not the node where the button lives. like fetching itself and obj merge it…
User Avatar
Member
1 posts
Joined: Oct. 2018
Offline
what can i do if object_merge is create within the same sop network?
esadiku
  • Quick Links