Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- Description: Script well let you place a bone or locator at the average location of the two selected verticies
- '''
- #!user/bin/env python
- import maya.cmds as cmds
- class avrPos:
- def __init__(self):
- #Creat the window, but first check to see if its created, if so, then delete it first
- if cmds.window('OG_PosPlace_v1.0', q=True, exists=True):
- cmds.deleteUI('OG_PosPlace_v1.0', window=True)
- #Create the actual gui window
- posGUI = cmds.window( title='OG_Pos_Place_v1.0', iconName='OG_POS', w=300, h=100, s=False)
- #delete the old prefs soo we can see the actual updated window
- if cmds.windowPref( posGUI, exists=True):
- cmds.windowPref( posGUI, remove=True)
- #Create the layout we want on the GUI
- posTypeForm = cmds.formLayout(numberOfDivisions=100)
- #store all text that will appear on the gui
- self.text1 = cmds.text( label='Select the verticies you want to position your utility!')
- #store and create all buttons in this gui
- pushButtonJnt = cmds.button( label="Place Joint", w=100, h=45, command='averagePos(bone=1)')
- pushButtonLoc = cmds.button( label="Place Locator", w=100, h=45, command='averagePos(loc=1)')
- #Now lets move all text and buttons around the GUI where we want them
- moveButtons = cmds.formLayout( posTypeForm, edit=True, attachForm=[(pushButtonJnt, 'bottom', 10), (pushButtonJnt, 'left', 25), (pushButtonLoc, 'bottom', 10), (pushButtonLoc, 'right', 45)])
- moveText = cmds.formLayout( posTypeForm, edit=True, attachForm=[(self.text1, 'top', 10), (self.text1, 'left', 5)])
- #execute the GUI to show
- cmds.showWindow( posGUI )
- def averagePos(self,bone=0, loc=0):
- #store the vert selection
- vertSel = cmds.filterExpand( ex=True, sm=31)
- #Raise an error if nothing is selected
- if not vertSel:
- raise RuntimeError('No verticies were selected')
- clustSet = cmds.cluster(n='Dummy_Cluster')
- if clustSet:
- clear = cmds.select(clear=True)
- if bone:
- mkobj = cmds.joint(p=(0,0,0))
- if loc:
- mkobj = cmds.spaceLocator(p=(0,0,0), n='Dummy_Position_LOC_')
- position = cmds.delete(cmds.pointConstraint(clustSet, mkobj, w=1))
- cmds.delete(clustSet)
- if __name__=='__main__':
- avrPos()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement