Jump to content
Sign in to follow this  

Creating Shaders in active node view with Python?

Recommended Posts

Posted (edited)

New to Python scripting. Hoping to get a better understand of how to use the documentation and features to create shaders in my currently viewing spot in the Network editor.

What I want to do should be simple enough. I want to create a shelf tool to automatically makes a shader network in the current node network I am viewing.

However, I am a little confused on how to generate a shader using python in a variable location. Here's why I've gotten done so far:

myNode = hou.node('/mat')

This works! However, I would like this to place shaders in my current shader network I'm viewing without having to hardcode it (As it works now it just put them in /mat).

How can I do something like this?

Hope this makes sense!

Edited by HappehLemons

Share this post

Link to post
Share on other sites

you can do something like this, currently it will create your vop nodes in the first found network editor of the Vop type, so even attrib vops or so, you may need to do some more filtering if you want specifically Matnets, but this should get you going

tabs = hou.ui.currentPaneTabs() # get all active tabs
tabs = [tab for tab in tabs if tab.type() == hou.paneTabType.NetworkEditor] # keep only network editors
tabs = [tab for tab in tabs if tab.pwd().childTypeCategory().name() == "Vop"] # keep only Vopnets

if tabs:
    node = tabs[0].pwd()
    ps = node.createNode('principledshader')


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this