Pages

Sunday, June 21, 2015

Global scale attribute

It's little cool tip used to add a global scale attribute to a controller.

We want to modify the scale of X,Y and Z axes at the same time using the scale tool or a Scale attribute in order to avoid this:

The character is scale on 1 axe, it looks like a crushed potato

We should connect scaleY to scaleX and scaleZ rename scaleY with a better name (ex: Scale) then lock and hide scaleX and scaleZ.

It is impossible to directly rename an attribute undefined by the user with editAttr or renameAttr commands:

renameAttr "pCube.translateX" "newName";
// Error: line 1: No valid object to rename was specified. // 

But we can add a second name for an attribute with the aliasAttr command:

aliasAttr "Scale" "pCube.scaleY";

Now, the name of "pCube.scaleY" displayed in the channelBox is "Scale". 
We just have to lock and hide scaleX and scaleZ (right click on the attribute -> lock and hide selected).




We can also select the object and use one of this scripts:

# using python:
import maya.cmds as cmds
globalScaleName = 'Scale'
selection = cmds.ls(sl=True)
if len(selection) != 0:
    cmds.aliasAttr(globalScaleName, '{0}.scaleY'.format(selection[0]))
    cmds.connectAttr('{0}.scaleY'.format(selection[0]), '{0}.scaleX'.format(selection[0]))
    cmds.connectAttr('{0}.scaleY'.format(selection[0]), '{0}.scaleZ'.format(selection[0]))
    cmds.setAttr('{0}.scaleX'.format(selection[0]), lock=True, keyable=False)
    cmds.setAttr('{0}.scaleZ'.format(selection[0]), lock=True, keyable=False)

// using MEL:
string $globalScaleName = "Scale";
string $selection[] = `ls -sl`;
if (size($selection) != 0) {
    aliasAttr $globalScaleName ($selection[0]+".scaleY");
    connectAttr ($selection[0]+".scaleY") ($selection[0]+".scaleX");
    connectAttr ($selection[0]+".scaleY") ($selection[0]+".scaleZ");
    setAttr -lock true -keyable false ($selection[0]+".scaleX");
    setAttr -lock true -keyable false ($selection[0]+".scaleZ");
}

_____________________________________________________



But there is a little problem : We cannot use a "space" in the attribute name like "Global Scale":

aliasAttr "Global Scale" "pCube1.scaleY";
// Warning: line 1: 'Global Scale' is not a valid alias. Aliases cannot contain reserved symbols or spaces. // 

There is an other and more powerful technique used to do that:
Save the scene in ASCII format (.ma) and open the file with a text editor (like wordpad, sublime text...)
Go to the line used to create your object (you can find it using CTRL+F keyword)







Add the following lines just after the createNode command:
addAttr -ci true -h true -sn "aal" -ln "attributeAliasList" -dt "attributeAlias";
setAttr ".aal" -type "attributeAlias" {"Global Scale","scaleY"};
It will create a cached internally attribute called attributeAliasList (the name does no matter) typed attributeAlias used to set a new name to the scaleY attribute. The syntax is :
http://download.autodesk.com/us/maya/2011help/Commands/setAttr.html
Finally, save the file as an other directory and open it.
Your attribute is changed!


Thanks to Benjamin Warnitz (modeling and texturing) ;)

Friday, May 1, 2015

Scalable wrap

A little tool I made in order to help my friends with the wrap deformer who cannot be scaled correctly by default. The character is malcolm created by AnimSchool.

Scalable wrap from Pierre Willot on Vimeo.

Saturday, April 11, 2015

Reorient joints

A simple MEL scripted rigging tool for reorient planar joints like elbows or knees on a single plane. It's a WIP of my joints placement system. Move your joints as you want ! ;)

Reorient joints normal plane based tool (beta) from Pierre Willot on Vimeo.