0

I create script for playblast. I need some HUD data over my video like a user and scene name, fps and current frame...

First i try HUD created by headsUpDisplay() is good, but not have a background... I change color of HUD labels but sometimes they are not readable without a background.

cmds.headsUpDisplay('HUDObjectSceneName', label='label TEXT', 
                    section=2, block=0, blockSize='large', 
                    dfs='large', labelFontSize='large')

Second i try use HUD buttons created by hudButton() - they have a background. But one of my label - is current time. headsUpDisplay() have 'command' to refresh and change label text. But hudButton() does not have this functionality.

label = 'FPS: 25 FRAME:'
cmds.hudButton('HUDHelloButton3', s=9, b=0, vis=1, l=label, 
                bw=blockLen(label), lfs='large')

cmds.headsUpDisplay('HUDCurentFrame', label=label,
                     section=9, block=0, blockSize='large', dfs='large',
                     labelFontSize='large', atr=True, 
                     command=lambda: cmds.currentTime(query=True))

hudButton() have second trouble - width of button is set manually. and when i want long label i need to calculate label width. but HUD font is not fixed and i don't know how right calculate a label width in pixels. After some experiments i create this function to calculate width. It made rough, but at least as that:

def blockLen(label):
    FONT_WIDTH = 8
    THIN_WIDTH = 6
    BLOCK_ADD = 10
    thin_symbol = ' :,.!i[];:\'"|-'

    sum = BLOCK_ADD
    for x in label:
        sum += THIN_WIDTH if x in thin_symbol else FONT_WIDTH

    return sum

I need HUD label with background and dynamic data like a current frame. But i can't find another way how create it?

ps. I try to use scriptJob() to change HUD button label when time changed. But its not worked with playblast...

Massimo
  • 836
  • 3
  • 17
  • 38

3 Answers3

1

scriptJobs do not execute when animations are playing. If you really need to update the hud during playback you can trigger your update from inside an expression. You'll have to call it from mel, unfortunately. And keep it as light as possible, it will slowdown interactive playback for anybody viewing the animation.

You might want to dynamically create the expression before playblasts and then delete it right afterwards so you don't leave it lying around to bother your animators.

You can also get out of using HUD buttons by creating an image plane set to an appropriate color.

theodox
  • 12,028
  • 3
  • 23
  • 36
0

One part of my problem i decided to. I don't find how to update button directly. I create headsUpDisplay() without label - he is able to updated. And i forced him to change the text on my hudButton()

def frame_label():
    label = 'FPS: 24     FRAME: %s' % cmds.currentTime(query=True)
    cmds.hudButton('HUDCurentFrame', e=True, l=label)

# bottom-right: FPS and current frame info
cmds.headsUpDisplay('HUDCurentFrameInvisible', label='', 
                    section=9, block=1, blockSize='large', dfs='large',
                    labelFontSize='large', command=frame_label, atr=True)

cmds.hudButton('HUDCurentFrame', s=9, b=0, vis=1, l='', bw=200, lfs='large')

But second part of my problem not solved. I cant calculate text size in pixels. The correct solution is to get from the Maya which font is used for HUD. And then i can use wx library to calculate width of text using font name...

But how to get font data (name, size and decorations) from Maya?

Massimo
  • 836
  • 3
  • 17
  • 38
0

to your second problem: i was able to find the needed font data (only name, size) but its not really accurate(more hacking, no voting needed), if you change the view port renderer to ViewPort 2.0 and than and changing the sizes of the font you will get the Error (nor on the default renderer):

 # small display ui font size and display ui size
 cmds.displayPref(sfs=9, dfs=10) #font size
 cmds.savePref()

 Failed trying to load font: -*-helvetica-bold-normal-*-9-*-*-*-*-*-iso8859-1

so the used font is helvetica bold and the size is relativ(you own input or the default value like cmds.optionVar(q="defaultFontSize"))

Ari Gold
  • 1,528
  • 11
  • 18
  • i use win and linux in the studio. i think in linux maya use another fonts then in win ( and i use ViewPort 2.0 all time... i try to find how to get data about fonts from maya directly. and i dont know, may be in new version of maya will be another font... – Massimo Dec 16 '16 at 14:29
  • i guess they will choice font types that are supported in both platforms, i try that too, i mean a regular way, but nothing....they will keep there font types, 100 % , but you know now the type and size – Ari Gold Dec 16 '16 at 14:35
  • its default viewport and viewport2.0... in windows. height of the font similar, but width - not... i dont know its a same fonts or not.. but it two different size in one maya for win – Massimo Dec 16 '16 at 14:53