LukeLetellier Posted April 3, 2016 Share Posted April 3, 2016 I'm often bringing objects into Houdini that have 20+ primitive groups, and I'd like to figure out a way to easily split them up to put separate materials on each group, then merging them back together. Its rather tedious to do by hand - creating node after node and manually inputting each group name - so a scripting solution sounds like it would be much more appropriate. The psuedo-code would go something like: sn = GetSelectedNode() groups = sn.GetPrimitiveGroups() for x in groups: Create Blast node Connect Blast to sn BlastGroup = x CreateMaterialNode Connect Material to BlastGroup MaterialGroup = x I know how to do this sort of thing in C4D with Python, but I'm not sure of where to start with this sort of thing in Houdini; I've looked through the help guide, but couldn't find exactly what I needed. Thoughts? Quote Link to comment Share on other sites More sharing options...
djiki Posted April 3, 2016 Share Posted April 3, 2016 You could do that by script, but also Houdini have Material node which gives you ability to assign bunch of materials to single object where each material could be assigned to specific group. This way you do not need to blast out separate groups and merge them back. Simply, connect Material node at SOP level and use "+" button to add as many materials you need and select which group(s) material should be attached to. Quote Link to comment Share on other sites More sharing options...
f1480187 Posted April 3, 2016 Share Posted April 3, 2016 import hou node = hou.selectedNodes()[0] mat = node.createOutputNode('material') mat.parm('num_materials').set(0) groups = [g.name() for g in node.geometry().primGroups()] for i, name in enumerate(groups, 1): # Add instance to the multiparm on material node. mat.parm('num_materials').insertMultiParmInstance(i-1) # Set instance's Group and Material parameters. group = mat.parm('group%d' %i) shop = mat.parm('shop_materialpath%d' %i) group.set(name) shop.set('/shop/' + name) # Select material node. mat.setCurrent(on=True, clear_all_selected=True) mat.setDisplayFlag(True) mat.setRenderFlag(True) Open Windows / Python Source Editor (code already there), then select node and press Apply. You can do much more than that. Such as create materials. automat.hipnc 1 Quote Link to comment Share on other sites More sharing options...
LukeLetellier Posted April 4, 2016 Author Share Posted April 4, 2016 Oh my gosh, thank you. Will be diving into that this week! Quote Link to comment Share on other sites More sharing options...
acey195 Posted April 4, 2016 Share Posted April 4, 2016 you can also do this using VEX, using: // string groups[] = detailintrinsic(0,"primitivegroups"); int i,numGroups; numGroups = len(groups); for(i=0;i<numGroups;i++) { // code to assign your materials per group index } // unfortunately this does not let you add instances to the multi parm automatically Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.