Showing posts with label rename. Show all posts
Showing posts with label rename. Show all posts

Thursday, 7 May 2026

rename, string substitution, replace in every occurence.


This is for replacing *EVERY* occurence of a string. Eg. SOMEONE has manually selected objects to assign materials to and you don't want to change every single instance of the object path!! This will go through your entire houdini script and change it

use this to string subsitute/replace. make a tool - right click on the shelf and select new tool.
Paste this code into the "code" tab and click create.



 import hou


contexts = ["/obj","/mat","/stage"]


def changeParms(node, search, replace):

    string_parms = [p for p in node.parms() if p.parmTemplate().type() == hou.parmTemplateType.String]

    for parm in string_parms:

        if (search in parm.eval()):

            newValue = parm.rawValue().replace(search, replace)

            parm.set(newValue)


input = hou.ui.readMultiInput("Tell me what to look for: ", ("search","replace"), buttons=('OK',"Cancel"), default_choice=0, close_choice=1, title="Replace Files")

if (input[0] == 0):

    search = input[1][0]

    replace = input[1][1]

    for rootNode in contexts:

        for node in hou.node(rootNode).allSubChildren():

            changeParms(node, search, replace)