top of page

Code snippet: Rigging Bone renaming

Ellie Ansell

A python script used for quickly renaming bone nodes on the spider rig.


"""Desc
Renames the selected node as 'name_01_suffix' such as 'l_leg_01_bne'.
"""

name = hou.pwd().parm("name").eval()
suffix = hou.pwd().parm("suffix").eval()

def rearrange(nodes):
    """
    Rearranges the nodes by the order of children. 
    """
    
    for n in nodes:
        if not n.outputs():
            last_node = n # Assumes the last node is the one with no children.
    list = [last_node]
    
    for n in nodes:
        last_node = last_node.inputs()[0]
        if "bone" in last_node.type().name():
            list.append(last_node)
        else:
            continue
            
    return list.reverse()
    
def rename(name, suffix):
    """
    Renames the selected node as 'name_01_suffix' such as 'l_leg_01_bne'. 
    """
    
    print "Name:{0} \nSuffix:{1}".format(name, suffix)
    node = hou.selectedNodes()
    nodes = [n for n in node if "bone" in n.type().name()]
    nodes = rearrange(nodes) # Rearrange the nodes by order of children, not selection.
    
    for i, n in enumerate(nodes):
        new_name = "{0}_{1:02d}_{2}".format(name, i, suffix)
        print "Setting {0} to {1}".format(n, new_name)
        n.setName(new_name,1)
        
if name and suffix:
    rename(name, suffix)


11 views0 comments

Recent Posts

See All

Comments


  • LinkedIn // Professional Bio
  • Facebook // ellieansellart page
  • Instagram // Informal fun
  • Vimeo

© 2020 by Ellie Ansell

Happily created using Wix.com

bottom of page