# -= ml_toggleVisibility.py =- # __ by Morgan Loomis # ____ ___ / / http://morganloomis.com # / __ `__ \/ / Revision 4 # / / / / / / / 2018-05-12 # /_/ /_/ /_/_/ _________ # /_________/ # # ______________ # - -/__ License __/- - - - - - - - - - - - - - - - - - - - - - - - - - - - - # # Copyright 2018 Morgan Loomis # # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to use, # copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the # Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # # ___________________ # - -/__ Installation __/- - - - - - - - - - - - - - - - - - - - - - - - - - # # Copy this file into your maya scripts directory, for example: # C:/Documents and Settings/user/My Documents/maya/scripts/ml_toggleVisibility.py # # Run the tool in a python shell or shelf button by importing the module, # and then calling the primary function: # # import ml_toggleVisibility # ml_toggleVisibility.main() # # # __________________ # - -/__ Description __/- - - - - - - - - - - - - - - - - - - - - - - - - - - # # Toggle the visibility of an object off and on, regardless of the attribute's # locked or keyable state. # # ____________ # - -/__ Usage __/- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # # Select an object, and run the script. If the object is visible, it will be # hidden, and vice-versa. # # # __________ # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /_ Enjoy! _/- - - __author__ = 'Morgan Loomis' __license__ = 'MIT' __revision__ = 4 __category__ = 'animation' shelfButton = {'annotation': 'Toggle the visible state of selected nodes. Force if possible.', 'order': 1} import maya.cmds as mc def main(): sel = mc.ls(sl=True) if not sel: return for each in sel: plug = each+'.v' try: locked = mc.getAttr(plug, lock=True) if locked: mc.setAttr(plug, lock=False) if mc.getAttr(plug): mc.setAttr(plug, 0) else: mc.setAttr(plug, 1) if locked: mc.setAttr(plug, lock=True) except: pass if __name__ == '__main__': main() # ______________________ # - -/__ Revision History __/- - - - - - - - - - - - - - - - - - - - - - - - # # Revision 1: 2015-05-14 : Converted from mel. # # Revision 3: 2018-02-17 : Updating license to MIT. # # Revision 4: 2018-05-12 : Shelf support