Focal Length Hud?

Im looking for a HUD that displays the cameras Focal Length with the option to toggle it on and off. I tried a couple that I found here on highend3D, but when I animated Focal Length the cameras (mm) did not update during the playblast. Can anyone please point me I the direction.

thanks all

Rey

QUOTE(reyrey @ 09/04/07, 05:48 AM) [snapback]272724[/snapback]
I tried a couple that I found here on highend3D, but when I animated Focal Length the cameras (mm) did not update during the playblast.

That is because all mel and mel event evaluations are suspended while in playback!

Well you can force the hud to update by putting a refresh call inside a expression, this however potentially slows down playback by heaps if the mel is complex.

CODE
expression -n "hudRefresh"
          -s ("headsUpDisplay"+
            "-refresh NameOfYourHudHandle;")  
          -o "" -ae 1 -uc al;

Thanks for the reply Jooja, the refresh expression keeps giving me an error..? How can i get the letters (mm) to display after the focal lens #? How can i add the toggle option on/off for the visibility in the HUD?
CODE
global proc FocalLength()
{
string $focus = getPanel -withFocus;
string $camera = modelPanel -q -camera $focus;
float $focal = getAttr ($camera + ".focalLength");

string $label = ("" + $focal);
headsUpDisplay -edit -label $label HUDCameraFL;
}

headsUpDisplay
-s 2
-b 0
-ba "left"
-dw 100
-dfs "large"
-blockSize "large"
-labelFontSize "large"
-command "FocalLength()"
-event "ModelPanelSetFocus"
HUDCameraFL;

rey

You did change NameOfYourHudHandle to the name of your hud handle which seems to be HUDCameraFL?

Besides, the script you use actually uses 1 extra cycle the line:

headsUpDisplay -edit -label $label HUDCameraFL;

is obsolete, and causes a error! from the command line reference, ive underlined the relevant bits:

QUOTE
-command(-c) script

Specifies the procedure or script to run, in order to obtain the desired information. This must return a value or an array of values. A warning will be displayed if the command does not return a value. This flag MUST always be accompanied by a trigger flag (eg. a condition flag, an event flag, an attachToRefresh flag, etc.).

Theres a another design flaw in the script too, string $focus = getPanel -withFocus; isnt exactly what you expect here, it does work, but its a bit no no in maya development terms. You should preferably bind the hud to a fixed camera and use attribute change as event instead. (off course that way you can only monitor one camera but the hud only monitors one camera at a time as it is now anyway), in actuality you should make a condition that monitors BOTH time change and the change command. If your really pro you'd edit the affected attribute with a script job, and enable the expression only on playback.

So quick but unbelievably dirty fix is:
CODE
global proc string XXXFocalLength()
{
string $focus = getPanel -withFocus;
string $camera = modelPanel -q -camera $focus;
float $focal = getAttr ($camera + ".focalLength");

return ("" + $focal + " mm");
}

replace XXX with your initials! (forcalLength is a BAD name for a global procedure, you will have clash sooner or later)

And the rest would be:

CODE
headsUpDisplay
-s 3
-b 0
-ba "left"
-dw 100
-dfs "large"
-blockSize "large"
-labelFontSize "large"
-command "XXXFocalLength()"
-event "ModelPanelSetFocus" "timeChanged "    
HUDCameraFL;

expression -n "hudRefresh"
          -s ("headsUpDisplay"+
            "-refresh HUDCameraFL;")  
          -o "" -ae 1 -uc al;

again change XXX.

PS: i haven't tested if they actually forced huds to work again so test attach to refresh also without the expression.

Thanks again for the reply Jooja, it still gives me an error.

// Error: Invalid object or value: HUDCameraFL //
// Error: Unable to parse the argument list. //

[codebox]//ADDING FOCAL LENGTH

global proc string camFocalLength()
{
string $focus = getPanel -withFocus;
string $camera = modelPanel -q -camera $focus;
float $focal = getAttr ($camera + ".focalLength");

return ("" + $focal + " mm");
}

headsUpDisplay -removePosition 2 0; //clear the previous one
headsUpDisplay
-s 2
-b 0
-ba "left"
-dw 100
-dfs "large"
-blockSize "large"
-labelFontSize "large"
-command "camFocalLength()"
-event "ModelPanelSetFocus" "timeChanged "
HUDCameraFL;

expression -n "hudRefresh"
-s ("headsUpDisplay"+
"-refresh HUDCameraFL;")
-o "" -ae 1 -uc al;

//ADDING FOCAL LENGTH MENU ITEM

global string $gHeadsUpDisplayMenu;

menuItem
-parent $gHeadsUpDisplayMenu
-checkBox true
-label "Focal Length"
-command "headsUpDisplay -e -vis #1 HUDCameraFL"
-annotation "Focal Length: Toggle the display of focal length";[/codebox]