code of the day cotd

Code of the Day: TreadsCreation

Continuing on with the creative crash site today, I downloaded the third most popular download AS_TreadsCreation by asanint:

This is a script to copy (or instance) objects around a curve to create an animated tread (like a tank tread). The treads created have a speed attribute for setting the direction and speed of the tread movement around the curve (negative speed value for reverse).

Language: MEL
Type: Maya Editor Script
Script Files: 1
Number of lines: 446

Functionality: 8
The code creates instances (or copies) an object around a curve, but it would be nice to have options to include spaces between the treads without modifying the tread geometry. Overall for very small treads it works quite well and does as expected. The inclusion of the animation curves for the treads is very nice. All the treads created fall under the same AS_treadsGrp, but it might be a nice option to create a separate group for each set of treads to make it easier to manage multiple groups.

Design: 7
The code is broken up into logical functions with clear functionality. Error handling is logical and handles the majority of cases that the code can get into. Some of the functions (like the treads function) are quite long and use a lot of internal variables which may benefit from refactoring into a few smaller functions. The tread code is unfortunately strictly tied to the interface code, as the functions do not use any parameters, but grab the value directly from specific widget control settings.

Style: 7.5
The code is laid out in a consistent and logical manner. The use of comments is helpful, although I find the indenting the code underneath a comment a little unusual. The use of the asterix is a little overused as it is in both as header decorators and within the code. Usually if such visual breaks within a function are desired, it is better to separate those pieces into a separate function. Some of the spacing around the interface is a little confusing and does not seem to follow the hierarchy of the interface.

Documentation: 7.5
The user documentation points to a link that no longer exists which is not that helpful. The code comments are useful, and the debug messages are helpful in guiding the user in their mistakes. Some of the comments are a little redundant, especially the closing bracket comment that mentions the end of a function, but I suppose this could be the style carried over from a different programming language background (like Visual Basic) which uses “End Sub”.

Reusability: 6
The code for the most part is logically broken up, but since none of the functions take parameters (and instead rely on specific UI elements for their values), the code is tightly coupled with the interface. The treads function is the major functionality outside of the interface, but would require modification to pass in a different set of parameters.

Overall: 7.5
This is a nice little script for quickly creating animated treads. Some additional parameters to allow for a little more customization in the interface would be a nice to have, but for many cases it works well the first time.

Until next time,
Michael Hubbard

Leave a Reply

Your email address will not be published. Required fields are marked *