How to create an Absolute Reference Copy of a node

   1071   2   0
User Avatar
Member
36 posts
Joined: Feb. 2016
Offline
Ello, I'd like to make a "master control" node (e.g. subnet with exposed parameters) which is referenced in different geometry contexts. I know I can right click and create a "reference copy" of a node, but it links all the parameters relatively which means I cant copy them to other locations. Is there a way to create an absolute reference copy of a node? This is the workflow I'm hoping for at the moment since I have a lot of parameters and in the different contexts I will need to override(remove reference) different parameters.

After writing all that I realized I'm basically describing an HDA, but maybe this approach could have its own use cases. I've always wondered what's a good way to reference a bunch of parameters, the only 2 techniques I'm aware of for now are individually copy pasting references or making a an entire node a reference copy. And another method is dragging them to the Parameter Interface window, I haven't explored that workflow much yet.
User Avatar
Member
56 posts
Joined: April 2008
Offline
I'm not sure if there are some new approaches in the newer Houdini versions
can achieve the function you mentioned.
This is a script I wrote before that can do batch conversion from relative refs to absolute ones.
You can try it as a python shelf tool.

import string
def abs_path_reference(node):
    parms = node.parms()
    
    #filter string type parameters
    refParms = []
    for i in parms:
        if ( (i.rawValue().find('ch("../') != -1) or (i.rawValue().find('chs("../') != -1) ):
            refParms.append(i)            
    print(str( len(refParms) ) + " parameters channel referenced and modified to:")
    
    #loop for finding out node(s) which channels reference from
    for parm in refParms:
        orig_expr=parm.rawValue()
        absPathStrs=[]
        relPathStrs=[]
        for i in parm.rawValue().split('('):
            for j in i.split(')'):
                if j.find('../')!=-1:                    
                    tmp1=j.split('/')
                    tmp1.pop()
                    tmp2='/'.join(tmp1)
                    relNodePath=tmp2[1:len(tmp2)]
                    refNode=node.node(relNodePath)
                    absNodePath=refNode.path()
                    absPathStrs.append(absNodePath)
                    relPathStrs.append(relNodePath)
                                                
        #setting new expressions
        new_expr=orig_expr
        for index in range(len(relPathStrs)):
            count=new_expr.count(relPathStrs[index])            
            new_expr=new_expr.replace(relPathStrs[index],absPathStrs[index],count)
        print(new_expr)
        parm.setExpression(new_expr)

    print("-------------------------------------------")
            
                                    
#excute script
sels = hou.selectedNodes()
for sel in sels:
    abs_path_reference(sel)
Edited by Benyee - June 22, 2023 08:53:32
User Avatar
Member
36 posts
Joined: Feb. 2016
Offline
Benyee
I'm not sure if there are some new approaches in the newer Houdini versions
can achieve the function you mentioned.
This is a script I wrote before that can do batch conversion from relative refs to absolute ones.
You can try it as a python shelf tool.

import string
def abs_path_reference(node):
    parms = node.parms()
    
    #filter string type parameters
    refParms = []
    for i in parms:
        if ( (i.rawValue().find('ch("../') != -1) or (i.rawValue().find('chs("../') != -1) ):
            refParms.append(i)            
    print(str( len(refParms) ) + " parameters channel referenced and modified to:")
    
    #loop for finding out node(s) which channels reference from
    for parm in refParms:
        orig_expr=parm.rawValue()
        absPathStrs=[]
        relPathStrs=[]
        for i in parm.rawValue().split('('):
            for j in i.split(')'):
                if j.find('../')!=-1:                    
                    tmp1=j.split('/')
                    tmp1.pop()
                    tmp2='/'.join(tmp1)
                    relNodePath=tmp2[1:len(tmp2)]
                    refNode=node.node(relNodePath)
                    absNodePath=refNode.path()
                    absPathStrs.append(absNodePath)
                    relPathStrs.append(relNodePath)
                                                
        #setting new expressions
        new_expr=orig_expr
        for index in range(len(relPathStrs)):
            count=new_expr.count(relPathStrs[index])            
            new_expr=new_expr.replace(relPathStrs[index],absPathStrs[index],count)
        print(new_expr)
        parm.setExpression(new_expr)

    print("-------------------------------------------")
            
                                    
#excute script
sels = hou.selectedNodes()
for sel in sels:
    abs_path_reference(sel)

Fascinating, thank you for sharing, I haven't made a shelf tool before or messed with python in houdini (although I used it quite a bit in C4D), but it looks well worth investigating.
  • Quick Links