I want to display a HUD in the viewport that shows the status of preserve UVs,

I want to display a HUD in the viewport that shows the status of preserve UVs,

32110155
Participant Participant
798 Views
2 Replies
Message 1 of 3

I want to display a HUD in the viewport that shows the status of preserve UVs,

32110155
Participant
Participant

I want to display a HUD in the viewport that shows the status of preserve UVs, is there any way to write such a mel or python?

0 Likes
Accepted solutions (1)
799 Views
2 Replies
Replies (2)
Message 2 of 3

32110155
Participant
Participant

import maya.cmds as cmds

# Get Preserve UVs settings
PreserveUV = cmds.polyOptions(query=True, preserveUV=True)


if cmds.headsUpDisplay('PreserveUVsHUD', exists=True):
cmds.headsUpDisplay('PreserveUVsHUD', remove=True)


if preserve_uvs[0]:
cmds.headsUpDisplay('PreserveUVsHUD', section=2, block=2, blockSize="large", dfs="large", label="Preserve UVs : enable")


can't work

0 Likes
Message 3 of 3

Kahylan
Advisor
Advisor
Accepted solution

Hi!

 

To be honest, your code doesn't make a lot of sense, you have variables that get defined and never used and others that you don't define but use as conditions, the way you want to check for the preserveUV option is an invalid flag, etc. Also if you want your HUD to update you need to bind it to an event or a condition.

Something I personally wouldn't do, is that you want to turn your HUD off and on based on the condition that your HUD displays. Because once you remove the HUD, the script it exectues wont run again. This simply doesn't work on its own, you would need to have another script (callback or scriptjob) running in the background that checks for the condition and turns the HUD on and off.  I get the appeal of having it turn on when the option is turned on, but the extra effort you need to go through is just not worth it in my opinion.

 

So here is how I would do it, having a simple HUD that you turn on and off using two commands, which displays the status of "Preserve UVs" in its Data section.

 

This is the command to turn it on:

import maya.cmds as cmds

def preserveUVDisplay(*args):
    
    preserveUVs = cmds.optionVar(q= 'trsManipsPreserveUvs')
    
    if preserveUVs == 1:


        return True
    else:

        return False
    


if cmds.headsUpDisplay('PreserveUVsHUD', exists=True):
    cmds.headsUpDisplay('PreserveUVsHUD', remove=True)


cmds.headsUpDisplay('PreserveUVsHUD', section=3, block=0, blockSize="large", dfs="large", label="Preserve UVs :", atr = True, command = preserveUVDisplay)

 

This is the command to turn it off:

import maya.cmds as cmds

if cmds.headsUpDisplay('PreserveUVsHUD', exists=True):
    cmds.headsUpDisplay('PreserveUVsHUD', remove=True)

 

I bound the refresh of the HUD to mayas Idle refresh, so you won't see it change immediately, but after you click somewhere else in the Main Window. I'm not sure if there is a condition or an event that would immediately change it once this options is toggled, I couldn't find one during my research.

 

I hope it helps!

 

0 Likes