Jump to content

Get Node path from a string parm in another Node


wandersonp

Recommended Posts

For example I have a geo1 node and the string in shop_materialpath parm is ../../myShader

 

how can I put this node myShader in a variable with absolute path?

 

my fragment of code is this

import hou 

def printUsedMaterials():
    materials = []
    for child in hou.node('/').allSubChildren():
        for parm in child.parms():
            #search in obj node
            if parm.name() == "shop_materialpath" and parm.eval() != "":
                materials.append(parm.eval().split("/")[-1])
            #search in material node
            if parm.name() == "shop_materialpath1" and parm.eval() != "":
                materials.append(parm.eval().split("/")[-1])

    print materials

printUsedMaterials()
Link to comment
Share on other sites

awesome thanks mantragora

the final code with corrections

import hou 

def printUsedMaterials():
    materials = []
    for child in hou.node('/').allSubChildren():
        for parm in child.parms():
            #search in obj node
            if parm.name() == "shop_materialpath" or parm.name() == "shop_materialpath1":
                path = parm.eval()
                if path != "":
                    full_path = child.node(path).path()
                    materials.append(full_path)

    print materials

printUsedMaterials()
Link to comment
Share on other sites

I did few modifications in this script, to track which material node is used in scene, the unused materials dont change the colors, them I can track and organize and clean my shops better

import hou 

def getUsedMaterialsPath():
    materials = []
    for child in hou.node('/').allSubChildren():
        for parm in child.parms():
            #search in obj node
            if parm.name() == "shop_materialpath":
                path = parm.eval()
                if path != "":
                    full_path = child.node(path).path()
                    materials.append(full_path)

    return materials

def changeColorFromUsedMaterials(color):
    materials = getUsedMaterialsPath()

    for material in materials:
        materialNode = hou.node(material)
        materialNode.setColor(color)

changeColorFromUsedMaterials(hou.Color((1, 0, 0)))

Edit: I edited this code coz i need to figure out how to do same thing with the material and shader sops nodes

Edited by wandersonp
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...