Scripting Tool Progress 2

I’ve now more or less finished all the features I wanted to include in my tool.

I now have a functionality in the check box for colouring the control shapes. Finding the python command that would change the colour was pretty hard to find but turns it was just an attribute of the object. You first set current_ctrl_shape+”.overrideEnabled” to 1 which allows you to override display settings, then you choose the colour by editing another attribute current_ctrl_shape+”.overrideColour” to a colour index number (13 being red for example).

Initially I had planned to check the joint name and detect if it had a left or right label on it. So jnt_L_arm would be detected as being on the left hand side and therefore be red. I know the code to do this in other code languages but was unable to find it for Python. I did however come up with an alternative to finding out the location of a joint and it was to simply query its translation X value. I originally had it check the translation of the group which only worked sometimes, checking the joint location has been more reliable.

I’ve also coded in the simpler advanced options such as adding in an Orient Constraint and locking translation values. Both of these were handled with a maya command each and just saves the user from searching for these themselves.

Additionally I wanted the ‘general’ control shape to be resized and shaped easily by the user. In order to leave the attributes of the object at zero this is usually done in “hull” mode (right click the object and select hull mode). This was a hard command to find in python as well as its not so obvious.

With the help of Grant Clarke (tutor) we used a method of importing mel scripts that are used by Maya to do some operations.

However while hull mode was opened up, you still had to additionally click the object and select in a menu to edit the CVs. This was just as bothersome as opening hull mode. I wanted the process of creating the control shape to editing it to be instant.

Looking at ‘echo all commands’ I noticed this command appear when you physically click on a “hull mode” selected object: select -r ctrl_root.cv[0:7] To me this seemed like the missing piece in the puzzle and so in python I managed to get it to work in this format: maya.cmds.select(current_ctrl_shape+”.cv[0:7]”)

So the mel script wasn’t needed at all, this simple command does it. Not sure what the [0:7] is all about entirely but individual CVs are referred to as [1] or [2] so the [0:7] probably means all CVs in that object (since there are 8 of them). Oh, perhaps 0:7 means 0 to 7. Well maybe I learned something there. Anyway, I was happy with this functionality as it greatly increases user readability and I managed to work out the second half of the problem without even needing to look up anything on the web.

Leave a Reply