[Sidefx-houdini-list] accessing 'reference copy' from python.

Graham Thompson captainhammy at gmail.com
Thu Jul 15 22:39:03 EDT 2010

Yeah there's really nothing in HOM that specifically does it for you,
however it's still pretty easy to do yourself.

You probably don't need to be setting expressions though.  You can
just set a parm on your new node to the same named parm on the
original node; no need to do too much work.  I have a general function
in my parmutils module that does such a thing.

def linkParmsTo(source_node, target_node):
    """ Link the parms of the source node to those of the target node if
        a parameter with the same name exists.
    for so in source_node.parms():
        # Skip folder parms.
        if isinstance(parm_to_link.parmTemplate(), hou.FolderSetParmTemplate):

        parm_to_link_to = target_node.parm(parm_to_link.name())

        # If the target parm exists
        if parm_to_link_to is not None:

For completeness sake here's my shelf/tab menu tool code as well.  It
copies selected nodes in a network editor if invoked from there or
lets you choose nodes if from the shelf.  It handles creating the new
node, linking the parms and sets a comment just like the RMB entry.

import parmutils
import toolutils

# Get the pane the tool was invoked from.
pane = kwargs["pane"]

# If it is a Network Editor then the list of nodes to copy is all the
# selected nodes.
if isinstance(pane, hou.NetworkEditor):
    nodes_to_copy = hou.selectedNodes()

# If it isn't a Network Editor we need to choose a node.
    # Get the active pane to get the current working directory.
    activepane = toolutils.activePane(kwargs)
    # The initial chooser node is the current working directory.
    init_node = activepane.pwd()

    # Select a node to make a copy of.
    node_path = hou.ui.selectNode(None, init_node)
    # Attempt to get the node we selected.  This will result in None if we
    # choose Clear or Cancel.
    source_node = hou.node(node_path)

    # Convert the node to a tuple.
    if source_node is not None:
	nodes_to_copy = (source_node,)
    # Use an empty tuple.
	nodes_to_copy = ()

# Copy the node(s).
for source_node in nodes_to_copy:
    # Get the node type name so we know what to create.
    node_type_name = source_node.type().name()
    # Create a node of the same name at the same level.
    ref_copy = source_node.parent().createNode(node_type_name)
    # Link the parms from the copy node to the source node.
    parmutils.linkParmsTo(ref_copy, source_node)

    # Move the copied node to a good position.
    # Set a comment where the node is referened from.
    ref_copy.setComment("Referenced from %s" % source_node.path())

On Thu, Jul 15, 2010 at 7:19 PM, Campbell McGrouther
<Campbell.McGrouther at rsp.com.au> wrote:
> Hey everyone,
> Has anyone out there had any luck getting 'reference copy' to work from
> within python?
> I want to automate the process of creating a node, and then do the
> equivalent of right clicking and running 'reference copy' on the new node.
> I have written some python to make a copy then run setExpressions to
> link the parms, but it's becoming a bit more work than I expected,
> testing out the different types.
> Methods that look promising in the docs say 'yet to be implemented', but
> possibly I'm missing something.
> Thanks.
> --
> campbell mcgrouther
> vfx artist - lighter | campbell.mcgrouther at rsp.com.au
> rising sun pictures | www.rsp.com.au
> phone +61 8 8400 6400 | mobile +61 406 062 703
> _______________________________________________
> Sidefx-houdini-list mailing list
> Sidefx-houdini-list at sidefx.com
> https://lists.sidefx.com:443/mailman/listinfo/sidefx-houdini-list

More information about the Sidefx-houdini-list mailing list