Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.52 KB | None | 0 0
  1. '''
  2.  
  3. Description: This tool will let you set your object(s) to either templete mode, reference or normal mode
  4.  
  5. '''
  6. #!user/bin/env python
  7.  
  8. import maya.cmds as cmds
  9.  
  10. class DisplaySet:
  11.     def __init__(self):
  12.         #Creat the window, but first check to see if its created, if so, then delete it first
  13.         if cmds.window('OG_SetDisplay_v1.0', q=True, exists=True):
  14.             cmds.deleteUI('OG_SetDisplay_v1.0', window=True)
  15.         #Create the actual gui window  
  16.         dspSet = cmds.window( title='OG_SetDisplay_v1.0', iconName='OG_DSPSET', w=300, h=100, s=False)
  17.         #delete the old prefs soo we can see the actual updated window
  18.         if cmds.windowPref( posGUI, exists=True):
  19.             cmds.windowPref( posGUI, remove=True)
  20.            
  21.        
  22.         cmds.showWindow( dspSet )
  23.  
  24.  
  25. def setDisplayType(normal=0, temp=0, ref=0):
  26.     #Lets collete all the objects first and also how many objects selected
  27.     objsel = cmds.ls(sl=True, type='transform')
  28.     intSet = len(objsel)
  29.    
  30.     #Lets go through an error check to see if anything was selected
  31.     if not objsel:
  32.         raise RuntimeError('Nothing was selected. Please select your object(s) first!')
  33.     #For this script, lets hit every object selected
  34.     for i in objsel:
  35.         #Lets check to see if there are any incomming connetions for the Display type
  36.         chklst = cmds.listConnections(i + '.overrideDisplayType', scn=True, p=True)
  37.         #if there is a connection to that, lets break that
  38.         if chklst:
  39.             killAttr = cmds.disconnectAttr(chklst[0], i + '.overrideDisplayType')
  40.         #Once error check is complete, lets set the display up by turning it on first
  41.         setEnable = cmds.setAttr(i + '.overrideEnabled', 1)
  42.         #Now, we will let the user choose which mode to set it at
  43.         if normal:
  44.             setType = cmds.setAttr(i + '.overrideDisplayType', 0)
  45.             finishTyp = 'normal mode'
  46.         if temp:
  47.             setType = cmds.setAttr(i + '.overrideDisplayType', 1)
  48.             finishTyp = 'template mode'
  49.         if ref:
  50.             setType = cmds.setAttr(i + '.overrideDisplayType', 2)
  51.             finishTyp = 'referenced mode'
  52.     #Finlly, for fancy mode, lets confirm it all with which mode its on and how many objects were hit
  53.     finMes = '%s objects has been switched to %s' % (intSet, finishTyp)
  54.     #With the info stored, lets show it in a small confirmation GUI
  55.     confrBox = cmds.confirmDialog( title='OG_Display_Complete!', message=finMes, button=['Close'], defaultButton='Yes', cancelButton='No', dismissString='No')
  56.    
  57. def selectType(normalType=0, tempType=0, refType=0):
  58.    
  59.     selALL = cmds.ls(g=True)
  60.     sepObj = cmds.listRelatives(selALL, allParents=True)
  61.    
  62.     normal, ref, temp = [], [], []
  63.    
  64.     for n in sepObj:
  65.         chkType = cmds.getAttr(n + '.overrideDisplayType')
  66.        
  67.         if chkType == 0:
  68.             normal.append(n)
  69.         if chkType == 1:
  70.             temp.append(n)
  71.         if chkType == 2:
  72.             ref.append(n)
  73.     if normalType:
  74.         try:
  75.             highlight = cmds.select(normal)
  76.         except TypeError:
  77.             errorWindow = cmds.confirmDialog( title='OG_SelectType_Error!', message='There are no objects in the scene in normal mode!', button=['Close'], defaultButton='Yes', cancelButton='No', dismissString='No')
  78.     if tempType:
  79.         try:
  80.             highlight = cmds.select(temp)
  81.         except TypeError:
  82.             errorWindow = cmds.confirmDialog( title='OG_SelectType_Error!', message='There are no objects in the scene in template mode!', button=['Close'], defaultButton='Yes', cancelButton='No', dismissString='No')
  83.     if refType:
  84.         try:
  85.             highlight = cmds.select(ref)
  86.         except TypeError:
  87.             errorWindow = cmds.confirmDialog( title='OG_SelectType_Error!', message='There are no objects in the scene in reference mode!', button=['Close'], defaultButton='Yes', cancelButton='No', dismissString='No')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement