Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import maya.mel as mel
- import maya.OpenMayaUI as apiUI
- import os,sys, random
- try:
- from PySide2.QtCore import *
- from PySide2.QtGui import *
- from PySide2.QtWidgets import *
- from PySide2.QtUiTools import *
- from shiboken2 import wrapInstance
- except ImportError:
- from PySide2.QtCore import *
- from PySide2.QtGui import *
- from PySide2.QtWidgets import *
- from PySide2.QtUiTools import *
- from shiboken2 import wrapInstance
- def getMayaWindow():
- """
- Get the main Maya Window as a QtGui.QMainWindow instance
- """
- ptr = apiUI.MQtUtil.mainWindow()
- if ptr is not None:
- return wrapInstance(long(ptr), QWidget)
- class cgpWindow(QMainWindow):
- def __init__(self,parent= getMayaWindow()):
- super(cgpWindow,self).__init__()
- #Set variables
- self.setWindowTitle("PLUG IN SUNSHINE")
- self.winWidth = 300
- self.winHeight = 100
- self.setGeometry(10,20,self.winWidth,self.winHeight)
- self.setWindowFlags(Qt.Tool)
- self.setAttribute(Qt.WA_DeleteOnClose)
- self.setWindowFlags(Qt.WindowStaysOnTopHint)
- #Set initialize
- self.initUI()
- def initUI(self):
- """
- Method for initializing the UI
- Create default MainWindow Widget
- """
- mainWidget= QWidget()
- self.mainLayout =QVBoxLayout()
- #Create items for the UI
- self.loadObjUi()
- self.loadCrvUi()
- self.executeAleatorio()
- self.CentrarObjeto()
- self.loadNumObjUi()
- """
- self.MinMaxToUi()
- self.RotarsToUi()
- self.TranslateToUi()
- self.ScalartsToUi()
- self.Ejecutar()
- """
- #Set signals and slots
- self.loadObjButton.clicked.connect(self.mainLoadObj)
- self.loadCrvButton.clicked.connect(self.mainLoadObj)
- self.OrdenAleatorioButton.clicked.connect(self.randomizeTranslate)
- self.CenterButton.clicked.connect(self.randomizeTranslate)
- """
- self.loadRotateButton.clicked.connect(self.executeOverideRotate)
- self.loadTranslateButton.clicked.connect(self.executeOverideTranslate)
- self.loadScalartsButton.clicked.connect(self.executeOverideScalarts)
- self.EjecutarButton.clicked.connect(self.AhoraSiEjecuta)"""
- #Partent Widget to Layout and Layout to QMainWindow
- mainWidget.setLayout(self.mainLayout)
- self.setCentralWidget(mainWidget)
- #Show UI
- self.show()
- def loadObjUi(self):
- """
- Method for adding the Ui elements for the Load Obj
- """
- #Label Items
- loadObjLabel= QLabel("Load Object:")
- #Line Edit Items
- self.loadObjLineEdit = QLineEdit()
- self.loadObjLineEdit.setEnabled(False)
- #Button Edit Items
- self.loadObjButton =QPushButton ("<< Load")
- self.loadObjButton.setToolTip("Selecciona uno o más objetos")
- #Create Layout
- loadObjLayout = QHBoxLayout()
- loadObjLayout.addWidget(loadObjLabel)
- loadObjLayout.addWidget(self.loadObjLineEdit)
- loadObjLayout.addWidget(self.loadObjButton)
- #Add layout to MainWindow
- self.mainLayout.addLayout(loadObjLayout)
- def loadCrvUi(self):
- """
- Método para insertar curva en el UI
- """
- #Label Items
- loadCrvLabel= QLabel("Agrega tu curva:")
- #Line Edit Items
- self.loadCrvLineEdit = QLineEdit()
- self.loadCrvLineEdit.setEnabled(False)
- #Button Edit Items
- self.loadCrvButton =QPushButton ("<< Load")
- self.loadCrvButton.setToolTip("Selecciona una o más curvas")
- #Create Layout
- loadCrvLayout = QHBoxLayout()
- loadCrvLayout.addWidget(loadCrvLabel)
- loadCrvLayout.addWidget(self.loadCrvLineEdit)
- loadCrvLayout.addWidget(self.loadCrvButton)
- #Add layout to MainWindow
- self.mainLayout.addLayout(loadCrvLayout)
- def executeAleatorio(self):
- """
- Method for executing oren Aleatorio
- """
- #Label Items
- loadOrdenAleatorioLabel= QLabel(" ")
- #Create Buttom
- self.OrdenAleatorioButton= QCheckBox ("Aleatorio")
- #Button Edit Items
- self.OrdenAleatorioButton.setToolTip("Orden en el que aparecen los objetos. Al desactivar será el orden de selección")
- #Parent Under main Layout
- OrdenAleatorioBtLayout =QHBoxLayout()
- OrdenAleatorioBtLayout.addWidget(loadOrdenAleatorioLabel)
- OrdenAleatorioBtLayout.addWidget(self.OrdenAleatorioButton)
- #Add layout to MainWindow
- self.mainLayout.addLayout(OrdenAleatorioBtLayout)
- def CentrarObjeto(self):
- """
- Method for Centrar Objeto
- """
- #Create Buttom
- self.CenterButton= QPushButton ("Centra tu Objeto")
- #Button Edit Items
- self.CenterButton.setToolTip("Colocar pivote en el centro del objeto")
- #Parent Under main Layout
- CenterBtLayout =QHBoxLayout()
- CenterBtLayout.addWidget(self.CenterButton)
- self.mainLayout.addLayout(CenterBtLayout)
- def loadNumObjUi(self):
- """
- Method for adding the Ui el numero de objetos que vas a agregar
- """
- #Label Items
- loadNumLabel= QLabel("# Objetos a crear")
- #Line Edit Items
- self.loadNumSpinBox = QSpinBox()
- self.loadNumSpinBox.setMaximum(1000)
- self.loadNumSpinBox.setMinimum(1)
- #Button Edit Items
- self.loadNumButton =QPushButton ("<< Load")
- self.loadNumButton.setToolTip("Cuantos objetos quieres crear")
- #Create Layout
- loadNumLayout = QHBoxLayout()
- loadNumLayout.addWidget(loadNumLabel)
- loadNumLayout.addWidget(self.loadNumSpinBox)
- loadNumLayout.addWidget(self.loadNumButton)
- #Add layout to MainWindow
- self.mainLayout.addLayout(loadNumLayout)
- ###----------------
- def mainLoadObj(self):
- """
- Method for loading objects into the Ui Line Edit
- """
- #Grab item form maya
- obj= cmds.ls (sl=True)
- grp=cmds.group(obj,name="cloud")
- self.loadObjLineEdit.setText(grp)
- def randomizeTranslate(self):
- """
- Method for randomize MinMax
- """
- #Get text form Ui
- objName = str(self.loadObjLineEdit.text())
- randomRotarsMin = random.randrange(-100,0)
- self.loadObjRatateLineEditMin.setText(str(randomRotarsMin))
- randomRotarsMax = random.randrange(0,100)
- self.loadObjRatateLineEditMax.setText(str(randomRotarsMax))
- randomTranslateMin = random.randrange(-100,0)
- self.loadObjTranslateLineEditMin.setText(str(randomTranslateMin))
- randomTranslateMax = random.randrange(0,100)
- self.loadObjTranslateLineEditMax.setText(str(randomTranslateMax))
- randomScalartsMin = random.randrange(-100,0)
- self.loadObjScalartsLineEditMin.setText(str(randomScalartsMin))
- randomScalartsMax = random.randrange(0,100)
- self.loadObjScalartsLineEditMax.setText(str(randomScalartsMax))
- #cmds.setAttr(objName+".translate",randomX, randomY, randomZ, type="double3")
- def MinMaxToUi (self):
- """
- Method for adding the other elements to Ui (MinMax)
- """
- #Label Items
- loadMinMaxObjLabel= QLabel(" ")
- loadMinObjLabel= QLabel("Min")
- loadMaxObjLabel= QLabel("Max")
- #Create Layout
- loadMinMaxLayout = QHBoxLayout()
- loadMinMaxLayout.addWidget(loadMinMaxObjLabel)
- loadMinMaxLayout.addWidget(loadMinObjLabel)
- loadMinMaxLayout.addWidget(loadMaxObjLabel)
- #Add layout to MainWindow
- self.mainLayout.addLayout(loadMinMaxLayout)
- def RotarsToUi (self):
- """
- Method for adding the other elements to Ui (Rotate)
- """
- #Label Items
- loadRotateObjLabel= QLabel("Rotars:")
- #Line Edit Items
- self.loadObjRatateLineEditMin = QLineEdit()
- self.loadObjRatateLineEditMax = QLineEdit()
- self.loadObjRatateLineEditMin.setEnabled(False)
- self.loadObjRatateLineEditMax.setEnabled(False)
- #Button Edit Items
- self.loadRotateButton =QPushButton ("Overide")
- self.loadRotateButton.setToolTip("Cambiar el número")
- #Create Layout
- loadRotateLayout = QHBoxLayout()
- loadRotateLayout.addWidget(loadRotateObjLabel)
- loadRotateLayout.addWidget(self.loadObjRatateLineEditMin)
- loadRotateLayout.addWidget(self.loadObjRatateLineEditMax)
- loadRotateLayout.addWidget(self.loadRotateButton)
- #Add layout to MainWindow
- self.mainLayout.addLayout(loadRotateLayout)
- def TranslateToUi (self):
- """
- Method for adding the other elements to Ui (Translate)
- """
- #Label Items
- loadTranslateObjLabel= QLabel("Translate:")
- #Line Edit Items
- self.loadObjTranslateLineEditMin = QLineEdit()
- self.loadObjTranslateLineEditMax = QLineEdit()
- self.loadObjTranslateLineEditMin.setEnabled(False)
- self.loadObjTranslateLineEditMax.setEnabled(False)
- #Button Edit Items
- self.loadTranslateButton =QPushButton ("Overide")
- self.loadTranslateButton.setToolTip("Cambiar el número")
- #Create Layout
- loadTranslateLayout = QHBoxLayout()
- loadTranslateLayout.addWidget(loadTranslateObjLabel)
- loadTranslateLayout.addWidget(self.loadObjTranslateLineEditMin)
- loadTranslateLayout.addWidget(self.loadObjTranslateLineEditMax)
- loadTranslateLayout.addWidget(self.loadTranslateButton)
- #Add layout to MainWindow
- self.mainLayout.addLayout(loadTranslateLayout)
- def ScalartsToUi (self):
- """
- Method for adding the other elements to Ui (Scalarts)
- """
- #Label Items
- loadScalartsObjLabel= QLabel("Scalarts:")
- #Line Edit Items
- self.loadObjScalartsLineEditMin = QLineEdit()
- self.loadObjScalartsLineEditMax = QLineEdit()
- self.loadObjScalartsLineEditMin.setEnabled(False)
- self.loadObjScalartsLineEditMax.setEnabled(False)
- #Button Edit Items
- self.loadScalartsButton =QPushButton ("Overide")
- self.loadScalartsButton.setToolTip("Cambiar el número")
- #Create Layout
- loadScalartsLayout = QHBoxLayout()
- loadScalartsLayout.addWidget(loadScalartsObjLabel)
- loadScalartsLayout.addWidget(self.loadObjScalartsLineEditMin)
- loadScalartsLayout.addWidget(self.loadObjScalartsLineEditMax)
- loadScalartsLayout.addWidget(self.loadScalartsButton)
- #Add layout to MainWindow
- self.mainLayout.addLayout(loadScalartsLayout)
- def Ejecutar(self):
- """
- Method for executing ramdom translate
- """
- #Create Buttom
- self.EjecutarButton= QPushButton ("Execute")
- #Parent Under main Layout
- EjecutarBtLayout =QHBoxLayout()
- EjecutarBtLayout.addWidget(self.EjecutarButton)
- self.mainLayout.addLayout(EjecutarBtLayout)
- def executeOverideRotate(self):
- """
- Method for activar las cajitas de min max de rotar
- """
- self.loadObjRatateLineEditMin.setEnabled(not self.loadObjRatateLineEditMin.isEnabled())
- self.loadObjRatateLineEditMax.setEnabled(not self.loadObjRatateLineEditMax.isEnabled())
- def executeOverideTranslate(self):
- """
- Method for activar las cajitas de min max de transladar
- """
- self.loadObjTranslateLineEditMin.setEnabled(not self.loadObjTranslateLineEditMin.isEnabled())
- self.loadObjTranslateLineEditMax.setEnabled(not self.loadObjTranslateLineEditMax.isEnabled())
- def executeOverideScalarts(self):
- """
- Method for activar las cajitas de min max de escalar
- """
- self.loadObjScalartsLineEditMin.setEnabled(not self.loadObjScalartsLineEditMin.isEnabled())
- self.loadObjScalartsLineEditMax.setEnabled(not self.loadObjScalartsLineEditMax.isEnabled())
- def AhoraSiEjecuta (self):
- """
- Método para ejecutar
- """
- objName = str(self.loadObjLineEdit.text())
- randomRotateX = random.randrange(float(self.loadObjRatateLineEditMin.text()),float(self.loadObjRatateLineEditMax.text()))
- randomRotateY = random.randrange(float(self.loadObjRatateLineEditMin.text()),float(self.loadObjRatateLineEditMax.text()))
- randomRotateZ = random.randrange(float(self.loadObjRatateLineEditMin.text()),float(self.loadObjRatateLineEditMax.text()))
- randomTranslateX = random.randrange(float(self.loadObjTranslateLineEditMin.text()),float(self.loadObjTranslateLineEditMax.text()))
- randomTranslateY = random.randrange(float(self.loadObjTranslateLineEditMin.text()),float(self.loadObjTranslateLineEditMax.text()))
- randomTranslateZ = random.randrange(float(self.loadObjTranslateLineEditMin.text()),float(self.loadObjTranslateLineEditMax.text()))
- randomScalartsX = random.randrange(float(self.loadObjScalartsLineEditMin.text()),float(self.loadObjTranslateLineEditMax.text()))
- randomScalartsY = random.randrange(float(self.loadObjScalartsLineEditMin.text()),float(self.loadObjTranslateLineEditMax.text()))
- randomScalartsZ = random.randrange(float(self.loadObjScalartsLineEditMin.text()),float(self.loadObjTranslateLineEditMax.text()))
- cmds.setAttr(objName+".translate",randomTranslateX, randomTranslateY,randomTranslateZ, type="double3")
- cmds.setAttr(objName+".scale",randomScalartsX, randomScalartsY,randomScalartsZ, type="double3")
- cmds.rotate( str(randomRotateX)+'deg', str(randomRotateY)+'deg', str(randomRotateZ)+'deg', objName )
- #-----------------------------------------------------------
- #------------------------------------------------------------
- #---------------------------------------------------------
- def showUi():
- global win
- try:
- win.close()
- except:
- pass
- win = cgpWindow()
- showUi()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement