Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 14.77 KB | None | 0 0
  1. import maya.mel as mel
  2. import maya.OpenMayaUI as apiUI
  3. import os,sys, random
  4.  
  5.  
  6. try:
  7.     from PySide2.QtCore import *
  8.     from PySide2.QtGui import *
  9.     from PySide2.QtWidgets import *
  10.     from PySide2.QtUiTools import *
  11.     from shiboken2 import wrapInstance
  12. except ImportError:
  13.     from PySide2.QtCore import *
  14.     from PySide2.QtGui import *
  15.     from PySide2.QtWidgets import *
  16.     from PySide2.QtUiTools import *
  17.     from shiboken2 import wrapInstance
  18.  
  19.  
  20.  
  21. def getMayaWindow():
  22.     """
  23.  Get the main Maya Window as a QtGui.QMainWindow instance
  24.  """
  25.    
  26.     ptr = apiUI.MQtUtil.mainWindow()
  27.     if ptr is not None:
  28.         return wrapInstance(long(ptr), QWidget)
  29.        
  30. class cgpWindow(QMainWindow):
  31.     def __init__(self,parent= getMayaWindow()):
  32.         super(cgpWindow,self).__init__()
  33.        
  34.         #Set variables
  35.         self.setWindowTitle("PLUG IN SUNSHINE")
  36.         self.winWidth  = 300
  37.         self.winHeight = 100
  38.         self.setGeometry(10,20,self.winWidth,self.winHeight)
  39.         self.setWindowFlags(Qt.Tool)
  40.         self.setAttribute(Qt.WA_DeleteOnClose)
  41.         self.setWindowFlags(Qt.WindowStaysOnTopHint)
  42.        
  43.         #Set initialize
  44.         self.initUI()
  45.        
  46.     def initUI(self):
  47.         """
  48.      Method for initializing the UI
  49.      Create default MainWindow Widget
  50.      """
  51.         mainWidget= QWidget()
  52.         self.mainLayout =QVBoxLayout()
  53.        
  54.         #Create items for the UI
  55.         self.loadObjUi()
  56.         self.loadCrvUi()
  57.         self.executeAleatorio()
  58.         self.CentrarObjeto()
  59.         self.loadNumObjUi()
  60.        
  61.         """
  62.        self.MinMaxToUi()
  63.        self.RotarsToUi()
  64.        self.TranslateToUi()
  65.        self.ScalartsToUi()
  66.        self.Ejecutar()
  67.        """
  68.        
  69.        
  70.        
  71.        
  72.         #Set signals and slots
  73.         self.loadObjButton.clicked.connect(self.mainLoadObj)
  74.         self.loadCrvButton.clicked.connect(self.mainLoadObj)
  75.         self.OrdenAleatorioButton.clicked.connect(self.randomizeTranslate)
  76.         self.CenterButton.clicked.connect(self.randomizeTranslate)
  77.        
  78.         """
  79.        self.loadRotateButton.clicked.connect(self.executeOverideRotate)
  80.        self.loadTranslateButton.clicked.connect(self.executeOverideTranslate)
  81.        self.loadScalartsButton.clicked.connect(self.executeOverideScalarts)
  82.        self.EjecutarButton.clicked.connect(self.AhoraSiEjecuta)"""
  83.        
  84.        
  85.        
  86.         #Partent Widget to Layout and Layout to QMainWindow
  87.         mainWidget.setLayout(self.mainLayout)
  88.         self.setCentralWidget(mainWidget)
  89.        
  90.         #Show UI
  91.         self.show()
  92.        
  93.     def loadObjUi(self):
  94.         """
  95.        Method for adding the Ui elements for the Load Obj
  96.        """
  97.         #Label Items
  98.         loadObjLabel= QLabel("Load Object:")
  99.        
  100.        
  101.        
  102.         #Line Edit Items
  103.         self.loadObjLineEdit = QLineEdit()
  104.         self.loadObjLineEdit.setEnabled(False)
  105.        
  106.         #Button Edit Items
  107.         self.loadObjButton =QPushButton ("<< Load")
  108.         self.loadObjButton.setToolTip("Selecciona uno o más objetos")
  109.        
  110.         #Create Layout
  111.         loadObjLayout = QHBoxLayout()
  112.         loadObjLayout.addWidget(loadObjLabel)
  113.         loadObjLayout.addWidget(self.loadObjLineEdit)
  114.         loadObjLayout.addWidget(self.loadObjButton)
  115.          
  116.         #Add layout to MainWindow
  117.         self.mainLayout.addLayout(loadObjLayout)
  118.        
  119.     def loadCrvUi(self):
  120.         """
  121.        Método para insertar curva en el UI
  122.        """
  123.         #Label Items
  124.         loadCrvLabel= QLabel("Agrega tu curva:")
  125.        
  126.        
  127.        
  128.         #Line Edit Items
  129.         self.loadCrvLineEdit = QLineEdit()
  130.         self.loadCrvLineEdit.setEnabled(False)
  131.        
  132.         #Button Edit Items
  133.         self.loadCrvButton =QPushButton ("<< Load")
  134.         self.loadCrvButton.setToolTip("Selecciona una o más curvas")
  135.        
  136.         #Create Layout
  137.         loadCrvLayout = QHBoxLayout()
  138.         loadCrvLayout.addWidget(loadCrvLabel)
  139.         loadCrvLayout.addWidget(self.loadCrvLineEdit)
  140.         loadCrvLayout.addWidget(self.loadCrvButton)
  141.          
  142.         #Add layout to MainWindow
  143.         self.mainLayout.addLayout(loadCrvLayout)
  144.        
  145.     def executeAleatorio(self):
  146.         """
  147.      Method for executing oren Aleatorio
  148.      """
  149.         #Label Items
  150.         loadOrdenAleatorioLabel= QLabel("   ")
  151.      
  152.         #Create Buttom
  153.         self.OrdenAleatorioButton= QCheckBox ("Aleatorio")
  154.        
  155.         #Button Edit Items
  156.         self.OrdenAleatorioButton.setToolTip("Orden en el que aparecen los objetos. Al desactivar será el orden de selección")
  157.        
  158.         #Parent Under main Layout
  159.         OrdenAleatorioBtLayout =QHBoxLayout()
  160.         OrdenAleatorioBtLayout.addWidget(loadOrdenAleatorioLabel)
  161.         OrdenAleatorioBtLayout.addWidget(self.OrdenAleatorioButton)
  162.        
  163.         #Add layout to MainWindow
  164.         self.mainLayout.addLayout(OrdenAleatorioBtLayout)
  165.        
  166.        
  167.     def CentrarObjeto(self):
  168.         """
  169.      Method for Centrar Objeto
  170.      """
  171.  
  172.      
  173.         #Create Buttom
  174.         self.CenterButton= QPushButton ("Centra tu Objeto")
  175.        
  176.         #Button Edit Items
  177.         self.CenterButton.setToolTip("Colocar pivote en el centro del objeto")
  178.        
  179.         #Parent Under main Layout
  180.         CenterBtLayout =QHBoxLayout()
  181.         CenterBtLayout.addWidget(self.CenterButton)
  182.  
  183.        
  184.        
  185.         self.mainLayout.addLayout(CenterBtLayout)
  186.        
  187.     def loadNumObjUi(self):
  188.         """
  189.        Method for adding the Ui el numero de objetos que vas a agregar
  190.        """
  191.         #Label Items
  192.         loadNumLabel= QLabel("# Objetos a crear")
  193.        
  194.        
  195.        
  196.         #Line Edit Items
  197.         self.loadNumSpinBox = QSpinBox()
  198.         self.loadNumSpinBox.setMaximum(1000)
  199.         self.loadNumSpinBox.setMinimum(1)
  200.        
  201.         #Button Edit Items
  202.         self.loadNumButton =QPushButton ("<< Load")
  203.         self.loadNumButton.setToolTip("Cuantos objetos quieres crear")
  204.        
  205.         #Create Layout
  206.         loadNumLayout = QHBoxLayout()
  207.         loadNumLayout.addWidget(loadNumLabel)
  208.         loadNumLayout.addWidget(self.loadNumSpinBox)
  209.         loadNumLayout.addWidget(self.loadNumButton)
  210.          
  211.         #Add layout to MainWindow
  212.         self.mainLayout.addLayout(loadNumLayout)
  213.        
  214.        
  215. ###----------------      
  216.        
  217.        
  218.     def mainLoadObj(self):
  219.         """
  220.      Method for loading objects into the Ui Line Edit
  221.      """
  222.        
  223.         #Grab item form maya
  224.         obj= cmds.ls (sl=True)
  225.         grp=cmds.group(obj,name="cloud")
  226.        
  227.         self.loadObjLineEdit.setText(grp)
  228.  
  229.     def randomizeTranslate(self):
  230.         """
  231.      Method for randomize MinMax
  232.      """
  233.         #Get text form Ui
  234.         objName = str(self.loadObjLineEdit.text())
  235.         randomRotarsMin = random.randrange(-100,0)
  236.         self.loadObjRatateLineEditMin.setText(str(randomRotarsMin))
  237.         randomRotarsMax = random.randrange(0,100)
  238.         self.loadObjRatateLineEditMax.setText(str(randomRotarsMax))
  239.         randomTranslateMin = random.randrange(-100,0)
  240.         self.loadObjTranslateLineEditMin.setText(str(randomTranslateMin))
  241.         randomTranslateMax = random.randrange(0,100)
  242.         self.loadObjTranslateLineEditMax.setText(str(randomTranslateMax))
  243.         randomScalartsMin = random.randrange(-100,0)
  244.         self.loadObjScalartsLineEditMin.setText(str(randomScalartsMin))
  245.         randomScalartsMax = random.randrange(0,100)
  246.         self.loadObjScalartsLineEditMax.setText(str(randomScalartsMax))
  247.        
  248.         #cmds.setAttr(objName+".translate",randomX, randomY, randomZ, type="double3")
  249.        
  250.     def MinMaxToUi (self):
  251.         """
  252.       Method for adding the other elements to Ui (MinMax)
  253.       """
  254.        
  255.         #Label Items
  256.         loadMinMaxObjLabel= QLabel("  ")
  257.         loadMinObjLabel= QLabel("Min")
  258.         loadMaxObjLabel= QLabel("Max")
  259.        
  260.        
  261.         #Create Layout
  262.         loadMinMaxLayout = QHBoxLayout()
  263.         loadMinMaxLayout.addWidget(loadMinMaxObjLabel)
  264.         loadMinMaxLayout.addWidget(loadMinObjLabel)
  265.         loadMinMaxLayout.addWidget(loadMaxObjLabel)
  266.  
  267.          
  268.         #Add layout to MainWindow
  269.         self.mainLayout.addLayout(loadMinMaxLayout)
  270.        
  271.     def RotarsToUi (self):
  272.         """
  273.       Method for adding the other elements to Ui (Rotate)
  274.       """
  275.         #Label Items
  276.         loadRotateObjLabel= QLabel("Rotars:")
  277.  
  278.         #Line Edit Items
  279.         self.loadObjRatateLineEditMin = QLineEdit()
  280.         self.loadObjRatateLineEditMax = QLineEdit()
  281.         self.loadObjRatateLineEditMin.setEnabled(False)
  282.         self.loadObjRatateLineEditMax.setEnabled(False)
  283.        
  284.         #Button Edit Items
  285.         self.loadRotateButton =QPushButton ("Overide")
  286.         self.loadRotateButton.setToolTip("Cambiar el número")
  287.        
  288.         #Create Layout
  289.         loadRotateLayout = QHBoxLayout()
  290.         loadRotateLayout.addWidget(loadRotateObjLabel)
  291.         loadRotateLayout.addWidget(self.loadObjRatateLineEditMin)
  292.         loadRotateLayout.addWidget(self.loadObjRatateLineEditMax)
  293.         loadRotateLayout.addWidget(self.loadRotateButton)
  294.          
  295.         #Add layout to MainWindow
  296.         self.mainLayout.addLayout(loadRotateLayout)
  297.        
  298.     def TranslateToUi (self):
  299.         """
  300.       Method for adding the other elements to Ui (Translate)
  301.       """
  302.         #Label Items
  303.         loadTranslateObjLabel= QLabel("Translate:")
  304.  
  305.         #Line Edit Items
  306.         self.loadObjTranslateLineEditMin = QLineEdit()
  307.         self.loadObjTranslateLineEditMax = QLineEdit()
  308.         self.loadObjTranslateLineEditMin.setEnabled(False)
  309.         self.loadObjTranslateLineEditMax.setEnabled(False)
  310.        
  311.         #Button Edit Items
  312.         self.loadTranslateButton =QPushButton ("Overide")
  313.         self.loadTranslateButton.setToolTip("Cambiar el número")
  314.        
  315.         #Create Layout
  316.         loadTranslateLayout = QHBoxLayout()
  317.         loadTranslateLayout.addWidget(loadTranslateObjLabel)
  318.         loadTranslateLayout.addWidget(self.loadObjTranslateLineEditMin)
  319.         loadTranslateLayout.addWidget(self.loadObjTranslateLineEditMax)
  320.         loadTranslateLayout.addWidget(self.loadTranslateButton)
  321.          
  322.         #Add layout to MainWindow
  323.         self.mainLayout.addLayout(loadTranslateLayout)
  324.        
  325.     def ScalartsToUi (self):
  326.         """
  327.       Method for adding the other elements to Ui (Scalarts)
  328.       """
  329.         #Label Items
  330.         loadScalartsObjLabel= QLabel("Scalarts:")
  331.  
  332.         #Line Edit Items
  333.         self.loadObjScalartsLineEditMin = QLineEdit()
  334.         self.loadObjScalartsLineEditMax = QLineEdit()
  335.         self.loadObjScalartsLineEditMin.setEnabled(False)
  336.         self.loadObjScalartsLineEditMax.setEnabled(False)
  337.        
  338.         #Button Edit Items
  339.         self.loadScalartsButton =QPushButton ("Overide")
  340.         self.loadScalartsButton.setToolTip("Cambiar el número")
  341.        
  342.         #Create Layout
  343.         loadScalartsLayout = QHBoxLayout()
  344.         loadScalartsLayout.addWidget(loadScalartsObjLabel)
  345.         loadScalartsLayout.addWidget(self.loadObjScalartsLineEditMin)
  346.         loadScalartsLayout.addWidget(self.loadObjScalartsLineEditMax)
  347.         loadScalartsLayout.addWidget(self.loadScalartsButton)
  348.          
  349.         #Add layout to MainWindow
  350.         self.mainLayout.addLayout(loadScalartsLayout)
  351.        
  352.     def Ejecutar(self):
  353.         """
  354.       Method for executing ramdom translate
  355.       """
  356.         #Create Buttom
  357.         self.EjecutarButton= QPushButton ("Execute")
  358.        
  359.         #Parent Under main Layout
  360.         EjecutarBtLayout =QHBoxLayout()
  361.         EjecutarBtLayout.addWidget(self.EjecutarButton)
  362.        
  363.         self.mainLayout.addLayout(EjecutarBtLayout)
  364.        
  365.     def executeOverideRotate(self):
  366.         """
  367.       Method for activar las cajitas de min max de rotar
  368.       """
  369.  
  370.         self.loadObjRatateLineEditMin.setEnabled(not self.loadObjRatateLineEditMin.isEnabled())
  371.  
  372.         self.loadObjRatateLineEditMax.setEnabled(not self.loadObjRatateLineEditMax.isEnabled())
  373.  
  374.  
  375.  
  376.     def executeOverideTranslate(self):
  377.         """
  378.       Method for activar las cajitas de min max de transladar
  379.       """
  380.         self.loadObjTranslateLineEditMin.setEnabled(not self.loadObjTranslateLineEditMin.isEnabled())
  381.        
  382.         self.loadObjTranslateLineEditMax.setEnabled(not self.loadObjTranslateLineEditMax.isEnabled())
  383.        
  384.     def executeOverideScalarts(self):
  385.         """
  386.       Method for activar las cajitas de min max de escalar
  387.       """
  388.        
  389.         self.loadObjScalartsLineEditMin.setEnabled(not self.loadObjScalartsLineEditMin.isEnabled())
  390.  
  391.         self.loadObjScalartsLineEditMax.setEnabled(not self.loadObjScalartsLineEditMax.isEnabled())
  392.        
  393.     def AhoraSiEjecuta (self):
  394.         """
  395.       Método para ejecutar
  396.       """
  397.         objName = str(self.loadObjLineEdit.text())
  398.  
  399.  
  400.  
  401.         randomRotateX = random.randrange(float(self.loadObjRatateLineEditMin.text()),float(self.loadObjRatateLineEditMax.text()))
  402.         randomRotateY = random.randrange(float(self.loadObjRatateLineEditMin.text()),float(self.loadObjRatateLineEditMax.text()))
  403.         randomRotateZ = random.randrange(float(self.loadObjRatateLineEditMin.text()),float(self.loadObjRatateLineEditMax.text()))
  404.        
  405.         randomTranslateX = random.randrange(float(self.loadObjTranslateLineEditMin.text()),float(self.loadObjTranslateLineEditMax.text()))
  406.         randomTranslateY = random.randrange(float(self.loadObjTranslateLineEditMin.text()),float(self.loadObjTranslateLineEditMax.text()))
  407.         randomTranslateZ = random.randrange(float(self.loadObjTranslateLineEditMin.text()),float(self.loadObjTranslateLineEditMax.text()))
  408.  
  409.         randomScalartsX = random.randrange(float(self.loadObjScalartsLineEditMin.text()),float(self.loadObjTranslateLineEditMax.text()))
  410.         randomScalartsY = random.randrange(float(self.loadObjScalartsLineEditMin.text()),float(self.loadObjTranslateLineEditMax.text()))
  411.         randomScalartsZ = random.randrange(float(self.loadObjScalartsLineEditMin.text()),float(self.loadObjTranslateLineEditMax.text()))
  412.  
  413.  
  414.  
  415.        
  416.         cmds.setAttr(objName+".translate",randomTranslateX, randomTranslateY,randomTranslateZ, type="double3")
  417.         cmds.setAttr(objName+".scale",randomScalartsX, randomScalartsY,randomScalartsZ, type="double3")
  418.         cmds.rotate( str(randomRotateX)+'deg', str(randomRotateY)+'deg', str(randomRotateZ)+'deg', objName )
  419.  
  420.  
  421. #-----------------------------------------------------------
  422. #------------------------------------------------------------
  423. #---------------------------------------------------------
  424.  
  425. def showUi():
  426.     global win
  427.    
  428.     try:
  429.         win.close()
  430.     except:
  431.         pass
  432.        
  433.     win = cgpWindow()
  434.  
  435. showUi()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement