Actually, what I think you want is the selectType() command.
https://download.autodesk.com/us/maya/2011help/Commands/selectType.html
Here are some examples of how you could toggle it. “oppositeValue” tests the opposite by using the Python not
keyword.
But in my last example, I toggle on or off polymesh, nurbsSurface, and subdiv all at once by using the not
and any
keywords. But that doesn’t completely disable the icon, which means some other surface type is still active. And “Surface” isn’t an option in this command. So I just don’t know what other flags also need to be turned off to make the icon completely turn off.
import pymel.core as pm
# Turn all ON
pm.selectType(allObjects=True)
# Toggle Joints
oppositeValue = not pm.selectType(joint=True, q=True)
pm.selectType(joint=oppositeValue)
# Toggle NurbsSurface
oppositeValue = not pm.selectType(nurbsSurface=True, q=True)
pm.selectType(nurbsSurface=oppositeValue)
# Toggle Poly Meshes
oppositeValue = not pm.selectType(polymesh=True, q=True)
pm.selectType(polymesh=oppositeValue)
# Toggle (ALMOST) all surface types:
areSurfacesOn = [
pm.selectType(polymesh=True, q=True),
pm.selectType(nurbsSurface=True, q=True),
pm.selectType(subdiv=True, q=True)
]
oppositeValue = not any(areSurfacesOn)
pm.selectType(polymesh=oppositeValue, nurbsSurface=oppositeValue, subdiv=oppositeValue)
So instead, if you want to toggle ALL surfaces, you could either try to find the other flags it wants. Or you could use an ugly mashup of MEL and Python:
import pymel.core as pm
import maya.mel as mel
# Test if ANY of these 3 flags are on or not.
areSurfacesOn = [
pm.selectType(polymesh=True, q=True),
pm.selectType(nurbsSurface=True, q=True),
pm.selectType(subdiv=True, q=True)
]
# Get the opposite value. If they are all True, it will be False.
oppositeValue = not any(areSurfacesOn)
# Get true for True and false for False, for MEL syntax.
lowerCaseBoolean = str(oppositeValue).lower()
mel.eval('setObjectPickMask "Surface" {};'.format(lowerCaseBoolean))