[SESI logo]

Houdini Development Toolkit - Version 6.5

Side Effects Software Inc. 2004

Command And Expression

Saving Houdini Commands in .hip Files

A hip file is a cpio archive of files, each file containing data. You can create a UNIX file-structure representation of this archive by using the cpio_expand program on a hip file.

Within the hip cpio archive, there is a file called .application which saves Houdini Commands to be run when the hip file is loaded. These commands are run after all OPs are loaded.

You can save Houdini commands to be run at start-up in this file of the hip cpio archive. This section explains how to do this via an example.


Display the "last saved" time at Load time

You might find it useful to have a dialog window telling you the last saved time of your file every time you load the file. For example:

We can do this from Houdini by using the text port and typing the command:

unix "xconfirm -c -t 'This hip file was last save at' -t 'Tue Mar 11 20:20:27 1997' -header 'Last saved' >& /dev/null"

This assumes that you have the unix program xconfirm installed on your system (which is probably true, if not, you can substitute another unix program for this example).

All we need to do is save the Houdini unix command in the .application file of the hip cpio archive. This is done through a C++ callback.


The Callback

The OP_Director class has a method setSaveCallback which you can use to register a callback function to be called when a hip file is saved. Thus, our C++ code to store our Houdini command would be as follows: /* * PROPRIETARY INFORMATION. This software is proprietary to * Side Effects Software Inc., and is not to be reproduced, * transmitted, or disclosed in any way without written permission. * * Produced by: * Side Effects Software Inc * 477 Richmond Street West * Toronto, Ontario * Canada M5V 3E7 * 416-504-9876 * * NAME: save_time.C * * COMMENTS: This shows you an example of saving a Houdini * command within the .application file of the * hip cpio archive */ #include <UT/UT_DSOVersion.h> #include <OP/OP_Director.h> #include <OP/OP_Error.h> #include <CMD/CMD_Manager.h> #include <CMD/CMD_Args.h> #include <time.h> /* * this is the callback that is called a hip file is saved. * * any output that write to the provided out_stream will * go in the .application file as a Houdini command to be * sourced when the file is next loaded. * * The second argument is for optional user data stored when * we call OPgetDirector->setSaveCallback(), we have * none is this example */ static OP_ERROR save_time_hipsave_callback( ostream &out_stream, void *) { time_t time_struct; char *time_string; char *nl_ptr; // call the standard C function 'time'. see 'man time' for details time_struct = time(0); time_string = ctime( &time_struct ); // remove the newline from the time string if( nl_ptr = strchr( time_string, '\n' ) ) *nl_ptr = '\0'; // now write the Houdini command which we wish to save in the // .application file of the hip cpio archive out_stream << "unix \"xconfirm -c -t 'This hip file was last saved at' -t '" << time_string << "' -header 'Last saved' >& /dev/null\"" << endl; return UT_ERROR_NONE; } /* * the callback for the save_time command. * * We really should provide an "unsave_time" command to turn off the * saving of the hip file, but that would clutter this example... */ static void cmd_save_time( CMD_Args &args ) { // register a callback to save the save-time. The // second argument is for optional user data (none in this // case OPgetDirector()->setSaveCallback(save_time_hipsave_callback, 0); // give some feedback to the user args.out() << "The save time of .hip files will be saved with the hip files" << endl; } void CMDextendLibrary( CMD_Manager *cman ) { // install the save_time command into the command manager // name = "save_time", options_string = none, help_tag = "", // callback = cmd_save_time cman->installCommand("save_time", "", "", cmd_save_time ); }

The function CMDextendLibrary adds a new command to Houdini called save_time.

When the save_time command is called from Houdini, a call is made to OP_Director::setSaveCallback() to register save_time_hipsave_callback as a callback function to invoke when the hip file is saved.

save_time_hipsave_callback is passed an output stream. Any output written to this stream will be placed in the .application file, which in turn will be run as a sequence of Houdini commands when the file is next loaded. So, in this example, we get the current time and write out the Houdini command to call up a confirm window the next time the file is loaded.

With the new save_time command installed as a shared library, the following sequence of commands should show the new confirm box popping up with the save time:

hscript Version 1.1 (Compiled on 03/11/97)
/ -> save_time
The save time of .hip files will be saved with the hip files
/ -> mwrite foo.hip
/ -> mread foo.hip

This little example actually proves to be pretty useful if you want certain information to come up when the file is loaded, such as "This file depends on such-and-such", or "Don't change cam1's movement or you will destroy the rotoscoping", or "Houdini rocks!".


Review


Table of Contents
Operators | Surface Operations | Particle Operations | Composite Operators | Channel Operators
Material & Texture | Objects | Command and Expression | Render Output |
Mantra Shaders | Utility Classes | Geometry Library | Image Library | Clip Library
Customizing UI | Questions & Answers

Copyright © 2004 Side Effects Software Inc.
477 Richmond Street West, Toronto, Ontario, Canada M5V 3E7