Toggle Visibility

I wrote this a while ago but only remembered to post it up after having to reconfigure Maya – I was fed up of ctrl+h only hiding objects rather than properly toggling visibility so I wrote a script that will correctly toggle visibility on/off on selected objects. If you have a group of objects selected and half of them have visibility on and half have visibility off, it will turn the ones that were off to on and vice versa.

import maya.cmds as mc
selectedNodes = mc.ls(selection=True)

for selectedNode in selectedNodes:
currentVis = mc.getAttr(“{selectedNode}.visibility.”.format(selectedNode=selectedNode))
if currentVis == 0:
mc.setAttr(“{selectedNode}.visibility.”.format(selectedNode=selectedNode), 1)
else:
mc.setAttr(“{selectedNode}.visibility.”.format(selectedNode=selectedNode), 0)

In windows >settings/preferences > hotkey editor, I added this script to a new action (to replace the previous hide selected objects, which is in the display tab) – with the below settings (remember to reassign the hotkey <ctrl+h> to it (or whichever you prefer) and to make sure you’ve selected python rather than MEL.

Leave a Reply

Your email address will not be published. Required fields are marked *