Jump to content

set absolute reference? python


danielsweeney

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

Link to comment
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")')
Link to comment
Share on other sites

  • 5 months later...

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
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...