Search code examples
pythonmayamel

Invalid flag "testVisibility" in Autodesk Maya 2016


I'm trying to determine if a set of mesh nodes is currently visible or not. Using pymel and isVisible() works, but it's a huge performance hit. Looking through the documentation, I found something that would (hopefully) solve my problem, the flag testVisibility on the Command hide.

According to the documentation the flag command will return a value that tells me if the specified nodes are visible or not.

The problem is, that flag doesn't exist.

import maya.cmds as cmds

cmds.sphere(name='testsphere')
cmds.hide('testsphere', testVisibility = True)

Gives an error

# Error: Invalid flag 'testVisibility'
# Traceback (most recent call last):
#   File "<maya console>", line 4, in <module>
# TypeError: Invalid flag 'testVisibility' # 

Same thing with the shortname of the flag "tv", as well as doing the whole thing in MEL: hide -testVisibility;.

The documentation includes this flag since Maya 2016. This is also the Maya version that I am using currently (more specifically, Maya 2016 SP5). Using the built-in link to the python documentation I arrive at the same documentation as I posted above. Looking through the changelog of SP6 doesn't mention anything of it either, so I assume it won't solve my problem.

I tried the same command on Maya 2017 and it works. That won't help me much though because that's not the Maya version that our team uses currently.

I can't contact Autodesk support because I'm not a subscriber (thanks autodesk, great help).

So my questions are:

  • is there something that I'm missing/that I overlooked? Are these flags only implemented in some kind of super duper developer plugin? Do Maya versions only use the API of the previous versions or something?

    • is there a way to check if a command has a flag, without try-catching it?
    • any workarounds that are not as performance draining as the pymel route I mentioned above?

Solution

  • You're right. I also tried tv flag for hide command and it definitely doesn't work.

    Try setter/getter:

    import maya.cmds as cmds
    
    cmds.sphere(name="testsphere")
    cmds.setAttr("testsphere.visibility", False)
    cmds.getAttr("testsphere.visibility")
    

    I tested it in Maya 2016/2018.

    # Result: False #