[Sidefx-houdini-list] script to clone a node

Graham Thompson captainhammy at gmail.com
Mon Oct 26 15:33:19 EDT 2009


Like Gene said, you can always do a Reference Copy, or you can use opcp -c.

Here's a couple functions I wrote to be python versions of these basically.
 One copies all the values/expressions/animation from one node to another
like opcp -c, the other does a straight up channel reference for each parm
like a reference copy.  I haven't used them in a while, but I think they
should still work.

def copyParmValuesTo(node_to_copy, node_to_copy_to):
    """ Copy parameter values of the source node to those of the target
node
        if a parameter with the same name exists.

        node_to_copy: The node whose parameter values you want to copy.

        node_to_copy_to: The node to copy the parameter values to.
    """
    for parm_to_copy in node_to_copy.parms():
        # Skip folder parms.
        if isinstance(parm_to_copy.parmTemplate(),
hou.FolderSetParmTemplate):
            continue

        parm_to_copy_to = node_to_copy_to.parm(parm_to_copy.name())
        # If the parameter on the target node does not exist, skip this
parm.
        if parm_to_copy_to is None:
            continue

        if parm_to_copy.keyframes():
            # Copy all hou.Keyframe objects.
            for key in parm_to_copy.keyframes():
                parm_to_copy_to.setKeyframe(key)
        else:
            # Copy the raw string.
            if isinstance(parm_to_copy.parmTemplate(),
hou.StringParmTemplate):
                parm_to_copy_to.set(parm_to_copy.unexpandedString())
            # Copy the raw value.
            else:
                parm_to_copy_to.set(parm_to_copy.eval())


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

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

        # If the target parm exists
        if parm_to_link_to is not None:
            parm_to_link.set(parm_to_link_to)


On Mon, Oct 26, 2009 at 12:19 PM, Michael K. O'Brien <mobrien at pixar.com>wrote:

> Hola~
>
> I find that I need to clone nodes every now and then. I usually end up
> copy/pasting a node, then manually setting channel expressions to have one
> node drive the other. Anyone have a script that automates this?
>
> Thought I'd ping the group before I wrote one...
>
> Is there a good script repository out there? I poked around odforce a bit,
> but
> didn't find anything obvious.
>
> MO
>
> --
> Michael O'Brien
> Tools
> Pixar
> mobrien at pixar.com
>
> Censorship is the mother of metaphor.
>                            -Jorges Luis Borges
> _______________________________________________
> 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