Jump to content
Sign in to follow this  
danielsweeney

set absolute reference? python

Recommended Posts

Hi Everyone,

 

can anyone give me a heads up on how to do this?

 

if I want to set a relative reference I usually do something like this.

 

node = hou.node('/obj/geo1/')
p1 = node.parm('sphere1/scale')
p2 = node.parm('sphere2/scale')

p2.set(p1)

 

but what if I want the path to be an absolute reference?

 

cheers for your help.

 

D

Share this post


Link to post
Share on other sites

You could build an expression pointing to the parm instead, something like this

node_one = hou.node("/obj/geo1/sphere1")
node_two = hou.node("/obj/geo1/sphere2")

node_two.parm("scale").setExpression('chs("' + node_one.path() + '/scale")')

Share this post


Link to post
Share on other sites

ah ok. so just do it manually.

 

just didn't know if there was a more elegant solution. and you can set absolute reference with right-click. thought there might be a function for it. 

 

cheers for the help.

 

D

Share this post


Link to post
Share on other sites
Posted (edited)

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:
            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)

 

hello daniel,this is some code for modifying from relative to absolute path in channel reference,i don't know whether it's a complete solution,but it could be useful in some situation,hope helpful

Edited by Benyee

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  

×