Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

To be really useful, however, your scripts must be readable, easy to customize, and bulletproof. Follow these suggestions when you create scripts and you will find that you and your associates spend less time looking for bugs and more time producing high quality motion capture animation:

Table of ContentsmaxLevel

Scroll only
scroll-viewporttrue
scroll-pdftrue
scroll-officetrue
scroll-chmtrue
scroll-htmltrue
scroll-docbooktrue
scroll-eclipsehelptrue
scroll-epubtrue
2

Use spacing

Using the right spacing and indentation makes your scripts easier to read, easier to use, easier to customize. Spacing does not affect the execution of a script, so you can use as many spaces, line breaks, and tabs as you like.

...

The following is an example of a poorly spaced script. As you can see, it is difficult to understand the structure of the script, to identify the variables, or to figure out what the script does.

Code Block
languagetext
if ( ( `getCount $ selectionArray ` ) == 2 ){

...


vector $source1 = $selectionArray[0].Translation; vector $source2 = 

...


$selectionArray[1].Translation; vector $position = ( $source2 - $source1 );

...


float $distance = `getLength $position `; print ( "The distance between " + (

...


 string ($selectionArray[0]) ) +" and " + ( string ($selectionArray[1]) ) + " is " + ( string ( $distance ) ) + "mm ." );

...


} if ( ( `getCount $ selectionArray ` ) != 2 )

...


print "Must have exactly 2 nodes selected."; $text = "Default scaling";

Here is the same script that is easier to read with improved spacing:

Code Block
languagetext
if( ( `getCount $selectionArray` ) == 2 )
{
    vector $source1 = $selectionArray[0].Translation;
    vector $source2 = $selectionArray[1].Translation;
    vector $position = ( $source2 - $source1 );
    float $distance = `getLength $position `;

    print ( "The distance between " + 
    ( string ($selectionArray[0]) ) +
    " and " + ( string ($selectionArray[1]) ) +
    " is " + ( string ( $distance ) ) + "mm ." );
}
else
{
    print "Must have exactly 2 nodes selected.";
}
$text = "Default scaling";

Each command statement is on its own line. The If/Then loop elements are on their own lines. Variables are defined on their own lines. Print statements are structured so you can see at a glance what elements are being assembled. Take time to format scripts whenever you create them. You will find that the investment pays off the very next time you need to use them.

...

Add comments to your scripts so it is easy for you and for others to understand what each section of the script does, and what data can be changed. To add a comment to a script, just put two forward slashes at the start of the comment line //.

Code Block
languagetext
// Default locator number is lucky.

...


 int $locator = 7;

...


 // Select the head markers and make a rigid body

Use a naming convention

If you develop and use some kind of consistent strategy you routinely use for defining variables and naming objects, you will save yourself hundreds, if not thousands, of hours of debugging time.
Follow these suggestions to use a convention to name variables and objects logically and concisely:

...

  • Bulletproof scripting
    When composing HSL scripts, keep all levels of users in mind. Make sure that the HSL script considers user errors and handles these errors gracefully. Think about the errors that your HSL script might encounter. After checking for an error and finding that it is present, have a reasonable contingency action in your HSL script for that error, such as politely informing you of the missing components.
    Example:
    module $selected = `getModules -selected -primary`;
    int $num_selected = `getCount $selected`;
    string $primaryName;
    // This conditional will run if there was
    // at least one marker selected.
    if ( $num_selected >= 1 ){
    select;
        select $selected[0];
        $primaryName = `getProperty $selected[0] "Name" `;
    print ( "Made " + string( $primaryName) + " primary and only selection." );
    }
    // This statement will be executed if no markers were selected.
    if ( $num_selected == 0 ){
       print "No markers were selected.";

    }
    In this example, if the user has not selected any markers, the script creates an error message rather than failing.

...