Categories
code of the day cotd

Code of the Day: XTools

XTools 4.1.1 by andrewosiow: https://www.creativecrash.com/maya/downloads/scripts-plugins/polygon/c/x-tools–5

This tool creates an interface of tools of having a number of tools in one area. The buttons overload 20 of the standard interface, and each button has a popup menu that are similar to the tool. This puts a lot of functionality in one place.

Language: MEL & Python
Type: Maya Editor Script
Script Files: 4
Number of lines: 7443 (MEL) + 5046 (Python) = 12489 (Total)

Functionality: 8.5
The functionality leverages a lot of the initial toolset, but does offer a few unique tools as well. The interface is unobtrusive and there is quite a lot of stuff available in the toolbox in a single place. A number of tools are the standard toolset, but there are a few overloaded and custom functions (additional merging and splitting, quick mirroring tools etc.). One thing I found interesting was the use of a .ma file as an installer, which had custom embedded MEL in it to make it easier to install (and possibly more comfortable for people who don’t want to run .exe files).

Design: 6.5
The first thing I noticed is the size of the files. Besides a few of the bootstrap shelf scripts, the majority of code is in two files (7346 lines MEL file and a 5046 lines python file). It seems that the XTools underwent a code rewrite from version 3 to version 4, however the monolithic approach of one file for all the functionality is still there. This is a bit unfortunate since with each of the individual tools, each one of them could have had a separate file and reused the common elements. Some of the functions make use of a significant number of both local and global variables (over 25 global variables in one of the functions). Some of the functions are very long, and a number of functions instead of passing parameters, instead grab the values directly from the UI. Some dependency injection and encapsulation would better help the overall design.

Style: 7
The code style is fairly consistent, but would benefit from following more of PEP8 for coding standards. The use of #end tags at the end of the method suggest a VB or Ruby background, which is fine, but just a little unusual in python code. One thing that would help the reader is distinguishing public from protected or private methods, but since the majority of functions start with xt, it is not entirely obvious by looking at them.

Documentation: 9
There is a lot of documentation and sample videos available at: http://www.andrews3dbrain.com/xtooltraining.html. The package comes with a readme, nice .pdf of the toolset and links to videos and extra information. The code has quite a bit of documentation (although would be nicer as docstrings) which helps navigate the code, but it is not uniformly consistent.

Reusability: 6
The code base is large and in a single file, but a number of functions could benefit from reuse. The lack of a lot of parameters or return values means that the code is tightly coupled to the interface and global variables. This code base could benefit from some separate classes to encapsulate some of the functionality (perhaps each of the tools as a separate class) and it would likely simplify and provide a better architecture to the code base (which seems to have just grown over time).

Overall: 8
The functionality is pretty handy, and a lot of elements have been clearly thought about in terms of creating an easy to use interface. The documentation is great and I thought the use of a .ma file as an installer, while unconventional, was also an interesting and clever approach to guarantee installation setup was correct.

Until next time,
Michael Hubbard
https://michaelhubbard.ca

Leave a Reply

Your email address will not be published.