Home » Featured, Houdini, Python

Customising Houdini Motion Effects

14 July 2009 11,560 views 2 Comments

Introduction

MotionFXNew to Houdini 10 are Motion Effects. If you haven’t come across them yet, just right click on any parameter and have a look inside the “Motion Effects” sub-menu. It offers you a list of choices on how to post-process any animation that you already have assigned to the parameter.

If you want to try it out, just add a null at object level and animate it’s position to do something funky. Now right click on the main Translate parameter (so that you’re indicating all three tx, ty, and tz channels) and select Spring from the Motion Effects sub-menu. You should see your null springing about all over your viewport. If not, try turning your damping to zero and play around with the spring constant.

The Motion Effects menu is just a simplified way of exposing some of the CHOP functionality to your animations. It’s a great way of experimenting with animations to see what it can add. Of course, they only offer fairly simple operations, but are a great way of learning what CHOPs has to offer.

Using the Motion Effects menu for your own tools

As it happens, the menu for Motion Effects also happens to provide a particularly handy hook into the user interface for a TD to exploit. If you investigate the documentation, you’ll find that the menu is entirely driven by an XML file. What the help file neglects to mention however, is that you don’t have to modify the original XML file provided by the default installation. You can also create your own in your user directory. This is great, as it means that you can customise the menu to your own requirements, or just use it to develop in before publishing to your colleagues.

As part of a current project, I needed to export individual animation curves from XSI to Houdini. As with most technical challenges, there’s always more than one way to skin a cat. In my particular case, I happened to have a Python class that would take a selection of XSI animation curves and export them into a *.clip format that can be read directly by a Houdini File CHOP.

With the XSI export already taken care of, I needed a tidy solution to import the curve into Houdini. The Motion Effects menu seemed to be an ideal route.

The handy thing about Motion Effects scripting is that a lot of the contextual information is provided to you. You get told which parameter has been selected as well as which modifier keys were pressed. Essentially, if you ever want something to happen based on the selection of a parameter, then hijacking the Motion Effects menu is a pretty good way to go.

The XML file shown at the bottom of this article takes the following steps:

  1. Obtain reference to parameter, the parameter’s node, and it’s parent. (The variable kwargs is a dictionary provided by the script host for retrieving context information. See the documentation for more info.)
  2. Ask the user for the filename to a *.clip or *.bclip file to load
  3. Create a CHOP network node and add the following CHOP nodes: File, Delete, Rename
  4. Set parameter values on the CHOP nodes to do the following:
    • Delete all but the first channel
    • Rename the first channel to the same name as the parameter that the user selected
    • Set the export path to path of the parameter’s node
  5. Make the connections between the nodes
  6. Set the export flag on the final node in the CHOP network

In less than 20 lines of code, we’ve created a very convenient tool for importing *.clip files.

It would be a simple job to expand on this script to do something a little more intelligent with the CHOP network. For example, it would be possible to analyse the names of the imported clip channels for things like “posx”, “posy”, and “posz” and to apply them to the correct “tx”, “ty”, “tz” channels in Houdini. In my particular situation however, the current functionality is convenient enough for my purposes. At the very least, it provides a handy way of setting up the basic network to handle the *.clip file import.


<?xml version="1.0" encoding="UTF-8" ?>
<menuDocument>
    <menu>
        <subMenu id="motion_effects_menu">
            <label>Motion Effects</label>
            <scriptItem id="LoadClipFile">
                <label>Load Clip File</label>
                <scriptCode>
                    <![CDATA[

param = kwargs["parms"][0]
param_node = param.node()
parent_node = param_node.parent()

filename = hou.ui.selectFile(None, "Load Clip file", False, hou.fileType.Clip, "*.clip,*.bclip", None, False, False, hou.fileChooserMode.Read)

if(filename!=""):
    chopnet_node = hou.node(parent_node.path()+"/chop_ClipImport")
    if chopnet_node==None:
        chopnet_node = parent_node.createNode("chopnet","chop_ClipImport")

    file_node = chopnet_node.createNode("file")
    del_node = chopnet_node.createNode("delete")
    rename_node = chopnet_node.createNode("rename")

    file_node.parm("file").set(filename)
    del_node.parm("select").set(1)
    del_node.parm("selnumbers").set("!0")

    rename_node.parm("renameto").set(param.name())
    rename_node.parm("export").set(param_node.path())

    del_node.setInput(0,file_node)
    rename_node.setInput(0,del_node)

    rename_node.setExportFlag(True)

                    ]]>
                </scriptCode>
            </scriptItem>
        </subMenu>
    </menu>
</menuDocument>

Installing the XML file

Installing this new menu item couldn’t be much easier. Just copy the above XML and paste it into a new text file called MotionEffectsMenu.xml, then save this file into your user/houdini10.0/ directory. It is possible to add your definition to the installation XML file, but it’s not recommended for obvious reasons.

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)
Loading...

2 Comments »

  • Jason said:

    Hey Andy,
    I saw this and thought you might be able to give me a tip on how to use python to clear a cache sop? I also have this question posted on the odforce forum under scripts. I’m finally teaching myself python, after putting it off for a year, and I decide developing my 1st fx tool would be a good idea. Anyways, any tips or suggestions would helpful. If you can’t no worries, I know your a busy man.

    –Jason

  • AndyN (author) said:

    Hi Jason,
    It should be pretty simple to do. You just need to find the cache button on the node and call the pressButton method. Something like this:

    node = hou.selectedNodes()[0] #or however you want to get your node
    button = node.parm(“clear”)
    button.pressButton()

    Is that what you’re after?

    Cheers!
    Andy

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.