Have you ever found yourself writing an expression that prints out attribute values so you can analyse the behaviour of a node? Then I don't need to tell you that this kind of expression time is time-consuming to write, while printing to the Script Editor slows performance considerably.
Of course you could keyframe your attributes and manually step through the timeline frame by frame to force a refresh of the Channel Box and look for your attributes values there, but the drawback is that the Channel Box only displays one node at a time.
Instead, here is a method that uses the HUD to query and display attribute values when you're working interactively, or during the playback of your animation.
The key to getting immediate feedback from the HUD is the trigger you use. In all examples that follow, we'll use the (self-explanatory) flag: -attachToRefresh
1) Display a selected object's attributes:
//Display position in world space of a selected object in the HUD
headsUpDisplay -rem HUDObjectPosition;
//
//Define a procedure that returns a value to be used by the HUD
//
global proc float[] objectPosition ()
{
string $selectedNodes[] = `ls -long -selection -type dagNode`;
float $position[3];
if (size($selectedNodes) > 0)
{
string $mainObject = $selectedNodes[(size($selectedNodes)-1)];
$position = `xform -q -ws -t $mainObject`;
headsUpDisplay -e -label $mainObject HUDObjectPosition;
}
else
{
$position[0] = 0;
$position[1] = 0;
$position[2] = 0;
headsUpDisplay -e -label "Nothing selected" HUDObjectPosition;
}
return $position;
}
// Create a HUD object to display the return value of the
// above procedure
//
// Attributes:
//
// - Section 1, block 0, represents top second slot of the view.
// - Set blockSize to "medium", instead of the default "small"
// - Assigned the HUD the label: "Position"
// - Defined the label font size to be large
// - Use the trigger: attachToRefresh
//
headsUpDisplay -section 1
-block 0
-blockSize "medium"
-label "Nothing selected"
-labelFontSize "large"
-command "objectPosition()"
-attachToRefresh
HUDObjectPosition;
// end of example
2) Dynamically update the HUD with selected attributes:
When you have run this script, you simply have to highlight attributes in the Channel Box to see them displayed in the HUD.
// The following works with the selected channels in the CB.
headsUpDisplay -rem HUDcbChannels;
// Define a procedure that returns the values of selected CB
// channels to be used by the Heads Up Display
global proc float[] cbChannelsHUD ()
{
$attrs = `selectedChannelBoxPlugs`;
float $cbChannels[];
int $index = 0;
if (size($attrs) > 0)
{
for ($cbPlug in $attrs)
{
$cbChannels[$index]=`getAttr $cbPlug`;
$index++;
}
}
return $cbChannels;
}
// Create a HUD object to display the return value
// of the above procedure
//
// Attributes:
//
// - Section 2, block 0, represents top third slot of the view.
// - Set the blockSize to "medium", instead of default "small"
// - Assigned the HUD the label: "CB"
// - Defined the label font size to be large
// - Assigned the HUD a command to run
// - Attached to Refresh to get the data to refresh as desired
//
headsUpDisplay -section 2
-block 0
-blockSize "medium"
-label "CB"
-labelFontSize "large"
-command "cbChannelsHUD()"
-attachToRefresh
HUDcbChannels;
// end of example
3) Watch attributes from multiple nodes:
In reality, you probably want to watch a bunch of attributes that don't belong to your selected objects, or you want to compare attributes from a multi-selection....here is a script that incorporates the idea of a watchList - using a global variable and a couple of shelf scripts, which could be hotkeys or MM that add to the watchList and clear it.
// this is the clear-it shelf script
clear($watchList);
// this is the shelf script that adds to the watchList,
// just select some channels you’d like to watch in CB
// and add them to the watchList
string $watchList[];
$listCB = `selectedChannelBoxPlugs`;
for ($listAt in $listCB)
{
$watchSize = size($watchList);
$watchList[$watchSize] = $listAt;
}
// and the rest is the similar HUD that just needs to
// be turned on and off, updating the watchList
// updates the HUD
headsUpDisplay -rem HUDcbChannels;
// Define a procedure that returns the values of selected
// CB channels to be used by the Heads Up Display
global proc string[] cbChannelsHUD ()
{
global string $watchList[];
$attrs = $watchList;
string $cbChannels[];
int $index = 0;
if (size($attrs) > 0)
{
for ($cbPlug in $attrs)
{
$cbChan=`getAttr $cbPlug`;
$cbChannels[$index]=$cbPlug + " " + string($cbChan);
$index++;
}
}
return $cbChannels;
}
// Create a HUD object to display the return value
// of the above procedure
//
// Attributes:
//
// - Section 2, block 0, represents top third slot of the view.
// - Set the blockSize to "medium", instead of default "small"
// - Assigned the HUD the label: "CB"
// - Defined the label font size to be large
// - Assigned the HUD a command to run
// - Attached to Refresh to get the data to refresh as desired
//
headsUpDisplay -section 2
-block 0
-blockSize "medium"
-command "cbChannelsHUD()"
-attachToRefresh
HUDcbChannels;
// end of example
I hope you've enjoyed this mini-tutorial. Many thanks to John Cresson for his input and the scripts.
Owen





Subscribe
Comments