Jump to content

Creating Shaders in active node view with Python?


HappehLemons

Recommended Posts

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')
myNode.createNode('principledshader')

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
Link to comment
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')

 

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...