Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.18 KB | None | 0 0
  1. '''
  2.  
  3. Description: Script well let you place a bone or locator at the average location of the two selected verticies
  4.  
  5. '''
  6. #!user/bin/env python
  7.  
  8. import maya.cmds as cmds
  9.  
  10. class avrPos:
  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_PosPlace_v1.0', q=True, exists=True):
  14.             cmds.deleteUI('OG_PosPlace_v1.0', window=True)
  15.         #Create the actual gui window  
  16.         posGUI = cmds.window( title='OG_Pos_Place_v1.0', iconName='OG_POS', 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.         #Create the layout we want on the GUI  
  21.         posTypeForm = cmds.formLayout(numberOfDivisions=100)
  22.         #store all text that will appear on the gui
  23.         self.text1 = cmds.text( label='Select the verticies you want to position your utility!')
  24.         #store and create all buttons in this gui
  25.         pushButtonJnt = cmds.button( label="Place Joint", w=100, h=45, command='averagePos(bone=1)')
  26.         pushButtonLoc = cmds.button( label="Place Locator", w=100, h=45, command='averagePos(loc=1)')
  27.         #Now lets move all text and buttons around the GUI where we want them
  28.         moveButtons = cmds.formLayout( posTypeForm, edit=True, attachForm=[(pushButtonJnt, 'bottom', 10), (pushButtonJnt, 'left', 25), (pushButtonLoc, 'bottom', 10), (pushButtonLoc, 'right', 45)])
  29.         moveText = cmds.formLayout( posTypeForm, edit=True, attachForm=[(self.text1, 'top', 10), (self.text1, 'left', 5)])
  30.        
  31.        
  32.         #execute the GUI to show
  33.         cmds.showWindow( posGUI )
  34.        
  35.     def averagePos(self,bone=0, loc=0):
  36.         #store the vert selection
  37.         vertSel = cmds.filterExpand( ex=True, sm=31)
  38.    
  39.         #Raise an error if nothing is selected
  40.         if not vertSel:
  41.             raise RuntimeError('No verticies were selected')
  42.  
  43.         clustSet = cmds.cluster(n='Dummy_Cluster')
  44.  
  45.         if clustSet:
  46.             clear = cmds.select(clear=True)
  47.             if bone:
  48.                 mkobj = cmds.joint(p=(0,0,0))
  49.            
  50.             if loc:
  51.                 mkobj = cmds.spaceLocator(p=(0,0,0), n='Dummy_Position_LOC_')
  52.             position = cmds.delete(cmds.pointConstraint(clustSet, mkobj, w=1))
  53.             cmds.delete(clustSet)
  54.                
  55. if __name__=='__main__':
  56.     avrPos()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement