SHARE
TWEET

Untitled

a guest Aug 22nd, 2019 79 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from PySide2 import QtWidgets,QtCore, QtGui
  2. import maya.cmds as mc
  3. import maya.mel as mm
  4. import maya.api.OpenMaya as om2
  5. from maya.app.general.mayaMixin import MayaQWidgetDockableMixin
  6. from functools import partial
  7.  
  8. class UI(MayaQWidgetDockableMixin, QtWidgets.QWidget):
  9.     def __init__(self, *args, **kwargs):
  10.         super(UI, self).__init__(*args, **kwargs)
  11.         self.timer = None
  12.  
  13.         layout = QtWidgets.QVBoxLayout(self)
  14.  
  15.         hl = QtWidgets.QHBoxLayout()
  16.         layout.addLayout(hl)
  17.  
  18.         self.refObjField = QtWidgets.QLineEdit()
  19.         label = QtWidgets.QLabel("snap mesh: ")
  20.         self.setBtn = QtWidgets.QPushButton("<<")
  21.         self.xrayOnBtn = QtWidgets.QPushButton("x-ray on")
  22.         self.xrayOffBtn = QtWidgets.QPushButton("x-ray off")
  23.         hl.addWidget(label)
  24.         hl.addWidget(self.refObjField)
  25.         hl.addWidget(self.setBtn)
  26.         hl.addWidget(self.xrayOnBtn)
  27.         hl.addWidget(self.xrayOffBtn)
  28.  
  29.         self.goBtn = QtWidgets.QPushButton("start tool")
  30.         layout.addWidget(self.goBtn)
  31.  
  32.  
  33.         self.setBtn.clicked.connect(self.setRef)
  34.         self.goBtn.clicked.connect(self.startTool)
  35.         self.xrayOnBtn.clicked.connect(partial(self.xrayToggle,1))
  36.         self.xrayOffBtn.clicked.connect(partial(self.xrayToggle, 0))
  37.  
  38.     def xrayToggle(self, val):
  39.         snapMesh = self.refObjField.text()
  40.         mc.displaySurface(snapMesh, x=val)
  41.  
  42.     def setRef(self):
  43.         sel = mc.ls(sl=1)[0]
  44.         self.refObjField.setText(sel)
  45.  
  46.     def startTool(self):
  47.         snapMesh = self.refObjField.text()
  48.         mc.displaySurface(snapMesh, x=1)
  49.         mc.setToolTo("CreatePolyCubeCtx")
  50.  
  51.         self.timer = QtCore.QBasicTimer()
  52.         self.timer.start(100, self)
  53.  
  54.    
  55.     def timerEvent(self, event):
  56.         currCtx = mm.eval('currentCtx')
  57.         if currCtx == 'CreatePolyCubeCtx':
  58.             return
  59.         snapMesh = self.refObjField.text()
  60.         mc.displaySurface(snapMesh, x=0)
  61.         self.stopTimer()
  62.  
  63.  
  64.     def stopTimer(self):
  65.         if self.timer:
  66.             self.timer.stop()
  67.             self.timer = None
  68.  
  69.  
  70. ui = UI()
  71. ui.show()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top