Creating new nodes

   2676   2   0
User Avatar
Member
3 posts
Joined: Jan. 2016
Offline
Hi all,

I'm trying to learn how to automatically create new nodes in the /mat context.

This is to automate the process of setting up Redshift materials for FBX, OBJ and similar data from external sources. I've been doing it manually for small numbers of materials, but when I get an FBX with hundreds of them, I'm dead.

The two ways I'd like to do it would be:

1. For FBX, read the list of imported material names in matnet A, and create new Redshift Material Builder nodes with the same names in matnet B, then retarget @shop_materialpath.

2. For OBJ, I'd like to split() the material names from @shop_materialpath, eliminate duplications, and then create new RS Material Builder nodes from those names.

I suspect that the answer lies in Python, and I'm reviewing the masterclass for that now, but I thought I'd check here as this is likely already a solved problem for many of you.

thanks!
User Avatar
Member
26 posts
Joined: Dec. 2019
Offline
Here is a very simple Python example for OBJ , create material based on shop_material attribute.
You can easily rewrite it to cover the file type of FBX , GLTF etc… and any type of render node that you'r using.

Just copy&paste the code into a Python node

node = hou.pwd()
geo = node.geometry()

# Add code to modify contents of geo.
# Use drop down menu to select examples.
shopMatAttrs = geo.findPrimAttrib("shop_materialpath")
matNameArray = shopMatAttrs.strings()
for matName in matNameArray:
	name = matName.split('/')
	matRoot = hou.node("/mat")
	matRoot.createNode("principledshader",name[-1])

Attachments:
2020-03-18 135734.jpg (11.1 KB)

User Avatar
Member
3 posts
Joined: Jan. 2016
Offline
Oh that's great! Thank you!

I'm importing a lot of objects from Lightwave via .fbx and .obj and that'll do the trick. It's a good example to learn from.

Change “principledshader” to “redshift_vopnet” and voila!
Edited by Jim May2 - March 19, 2020 17:25:20
  • Quick Links