Atom Posted May 29, 2015 Share Posted May 29, 2015 (edited) Hi All, I have been importing FBX files and often they have a lot of nodes but only a few materials. Most of the time I discard the imported materials and override with new ones. However, the standard FBX import offers no arrangement feature and I am left with a task of individually selecting each node and then clicking on the material tab to see what material, if any, is applied to each object node. I wrote a short script that scans all geo based nodes at the /obj level and stacks them vertically based upon shared materials. Then I can simply select the vertical stack of nodes and override the materials for all those shared objects in one paste. Before Script: After Script: Script: Place this code in a new shelf tool. import hou def returnShopPath(passed_name): result = None n = hou.node(passed_name) if n != None: result = n.parm("shop_materialpath").eval() return result def childrenOfNode(node, filter): # Return nodes of type matching the filter (i.e. geo etc...). result = [] if node != None: for n in node.children(): t = str(n.type()) if t != None: for filter_item in filter: if (t.find(filter_item) != -1): # Filter nodes based upon passed list of strings. result.append('%s~%s' % (n.name(), t)) result += childrenOfNode(n, filter) return result def uniquifyList(seq, idfun=None): #http://www.peterbe.com/plog/uniqifiers-benchmark # f5 order preserving if idfun is None: def idfun(x): return x seen = {} result = [] for item in seq: marker = idfun(item) # in old Python versions: # if seen.has_key(marker) # but in new ones: if marker in seen: continue seen[marker] = 1 result.append(item) return result # Construct paths. node_path = '/obj' x_spacing = 2 y_spacing = 1 # Get a list of all materials applied to geometry objects. lst_geo_mat = [] nodes = childrenOfNode(hou.node(node_path),["Object geo"]) #Other valid filters are Sop, Object, cam. for node in nodes: ary = node.split("~") if len(ary) > 0: node_candidate = "%s/%s" % (node_path, ary[0]) n = hou.node(node_candidate) if n !=None: shop_path = returnShopPath(node_candidate) if shop_path != None: lst_geo_mat.append(shop_path) # Scan the unique material list for matching /obj nodes and stack them up vertically. unique_materials = uniquifyList(lst_geo_mat) for (i,mat) in enumerate(unique_materials): if i%2==0: y = 0 else: # Stagger vertical start so long names are still readable and do not collide horizontaly. y = 0.5 for node in nodes: ary = node.split("~") if len(ary) > 0: node_candidate = "%s/%s" % (node_path, ary[0]) n = hou.node(node_candidate) if n !=None: shop_path = returnShopPath(node_candidate) if shop_path == mat: # This node should be vertically layed out with it's companions sharing this material. node_loc = hou.Vector2((i*x_spacing,y*y_spacing)) n.setPosition(node_loc) y += 1 Edited May 29, 2015 by Atom Quote Link to comment Share on other sites More sharing options...
anim Posted May 29, 2015 Share Posted May 29, 2015 you can as well always just pick material in Material Palette and click Select button to select all objects with that material, then you can change it to whatever you want or select another material and use Assign button Quote Link to comment Share on other sites More sharing options...
Atom Posted May 30, 2015 Author Share Posted May 30, 2015 (edited) Hmm... Where is this select button located? I don't see one in the SHOP network area and the basic select tool has no options to select from material. Using version 14. Edited May 30, 2015 by Atom Quote Link to comment Share on other sites More sharing options...
anim Posted May 30, 2015 Share Posted May 30, 2015 (edited) it's in Material Palette pane tab (or Alt+G for floating one) Edited May 30, 2015 by anim Quote Link to comment Share on other sites More sharing options...
Atom Posted May 31, 2015 Author Share Posted May 31, 2015 Ah, thanks again. I have not spent a lot of time in using the Material panel. But now that I see the SELECT button I probably won't need my script after all. 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.