cwisbg

# Rando

Jun 9th, 2014
423
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.12 KB | None | 0 0
  1. # Rando
  2. # cwisbg.com
  3. import random as r
  4. from pymel.core import *
  5. def snapToSurface():
  6.     # select list, then snap to object
  7.     sl = selected()  
  8.     startL = spaceLocator(n="startL")
  9.     endL = spaceLocator(n="endL")
  10.     cp = createNode("closestPointOnMesh",n="snapperCheck")
  11.     snapList = sl
  12.     snapto = snapSurfaceMesh
  13.     snapto.getShape().worldMatrix[0] >> cp.inputMatrix
  14.     startL.translate >> cp.inPosition
  15.     cp.position >> endL.translate
  16.     snapto.getShape().worldMesh[0] >> cp.inMesh
  17.     for s in snapList:
  18.         st = s.getTranslation()
  19.         move(startL, st)
  20.         et = endL.getTranslation()
  21.         move(s,et)
  22.     delete(cp,startL,endL)
  23.     alignToSurface()
  24.     select(sl)
  25. def alignToSurface():
  26.     alignCheck = alignToSurfaceBox.getValue()
  27.     sl = selected()
  28.     for s in sl:
  29.         if alignCheck:
  30.             nc = normalConstraint(snapSurfaceMesh, s, aim= [0,1,0],u= [0,1,0],wut = "vector",wu =[0,1,0])
  31.             delete(nc)
  32.         else:
  33.             pass
  34. def checkMe():
  35.     boxValue = checkBox1.getValue()
  36.     print "Checked", boxValue
  37. def buttonPressed():
  38.     cbScale = checkBoxScale.getValue()
  39.     cbTrans = checkBoxTranslate.getValue()
  40.     cbRot = checkBoxRotate.getValue()
  41.     cbX = checkBoxX.getValue()
  42.     cbY = checkBoxY.getValue()
  43.     cbZ = checkBoxZ.getValue()
  44.     keyCheck = keyBox.getValue()
  45.     amntS = float(sText.getText())
  46.     amntS1 = float(sText1.getText())
  47.     amntT = float(tText.getText())
  48.     amntR = float(rText.getText())
  49.     sl = selected()
  50.     slEnd = sl
  51.     for s in sl:
  52.         tx = 0
  53.         ty = 0
  54.         tz = 0
  55.         rx = 0
  56.         ry = 0
  57.         rz = 0
  58.         sx = 0
  59.         sy = 0
  60.         sz = 0          
  61.         if cbScale:
  62.             if cbX or cbY or cbZ:
  63.                 sr = r.uniform(amntS,amntS1)
  64.             scale(s,sr,sr,sr,r=1)
  65.         if cbTrans:
  66.             if cbX:
  67.                 tx = r.uniform(-amntT,amntT)
  68.             if cbY:
  69.                 ty = r.uniform(-amntT,amntT)
  70.             if cbZ:
  71.                 tz = r.uniform(-amntT,amntT)
  72.             move(s,tx,ty,tz,os=1,r=1)  
  73.         if cbRot:
  74.             if cbX:
  75.                 rx = r.uniform(0,amntR)
  76.             if cbY:
  77.                 ry = r.uniform(0,amntR)
  78.             if cbZ:
  79.                 rz = r.uniform(0,amntR)
  80.             rotate(s,rx,ry,rz,os=1,r=1)
  81.              
  82.         if keyCheck:
  83.             setKeyframe(s)
  84.    
  85.     snapCheck = snapToSurfaceBox.getValue()
  86.     if snapCheck:
  87.         snapToSurface()
  88.     alignToSurface()
  89.    
  90.            
  91.        
  92.            
  93. def scaleCheck():
  94.     sc = checkBoxScale.getValue()
  95.     if sc:
  96.         sText.setEnable(1)
  97.         sText1.setEnable(1)
  98.     else:
  99.         sText.setEnable(0)
  100.         sText1.setEnable(0)
  101. def transCheck():
  102.     bc = checkBoxTranslate.getValue()
  103.     if bc:
  104.         tText.setEnable(1)
  105.     else:
  106.         tText.setEnable(0)
  107. def rotCheck():
  108.     bc = checkBoxRotate.getValue()
  109.     if bc:
  110.         rText.setEnable(1)
  111.     else:
  112.         rText.setEnable(0)  
  113.                              
  114. def addSnapSurface():
  115.     global snapSurfaceMesh
  116.     snapSurfaceMesh = selected()[0]
  117.     snapSurface.setText(str(snapSurfaceMesh))
  118.     snapToSurfaceBox.setEnable(1)
  119.     snapToSurfaceBox.setValue(1)
  120.     alignToSurfaceBox.setValue(1)
  121.     alignToSurfaceBox.setEnable(1)
  122.     snapToSurfaceBtn.setEnable(1)
  123.     alignBtn.setEnable(1)
  124.     print snapSurfaceMesh
  125.    
  126. def randoScale():
  127.     sl = selected()
  128.     amntS = float(sText.getText())
  129.     amntS1 = float(sText1.getText())
  130.     for s in sl:
  131.         sr = r.uniform(amntS,amntS1)
  132.         scale(s,sr,sr,sr,r=1)  
  133. def randoTrans():
  134.     sl = selected()
  135.     amntT = float(tText.getText())
  136.     for s in sl:
  137.         tx = r.uniform(-amntT,amntT)
  138.         ty = r.uniform(-amntT,amntT)
  139.         tz = r.uniform(-amntT,amntT)
  140.         move(s,tx,ty,tz,os=1,r=1)    
  141. def randoRot():
  142.     sl = selected()
  143.     amntR = float(rText.getText())
  144.     for s in sl:
  145.         rx = r.uniform(0,amntR)
  146.         ry = r.uniform(0,amntR)
  147.         rz = r.uniform(0,amntR)
  148.         rotate(s,rx,ry,rz,os=1,r=1)          
  149.        
  150.        
  151.        
  152.                
  153. win = window(title= "Rando Gui", s=0)
  154. mainLayout = frameLayout(l="Randor",cll=1)
  155.  
  156. checkBoxLayout = frameLayout(l="Randor",p=mainLayout,cll=1)
  157.  
  158. scaleLayout = rowColumnLayout(nc=2,p=checkBoxLayout)
  159. checkBoxScale = checkBox(l = "Scale",p=scaleLayout,cc =Callback(scaleCheck))
  160. scaleBtn = button(l="Rand Scale", command=Callback(randoScale),p=scaleLayout)
  161. scaleTxtLayout = rowColumnLayout(nr=1,p=scaleLayout)
  162. sText = textField(tx=".5",p=scaleTxtLayout,w=50,en=0)
  163. sText1 = textField(tx="1.5",p=scaleTxtLayout,w=50,en=0)
  164.  
  165.  
  166. transLayout = rowColumnLayout(nc=2,p=checkBoxLayout)
  167. checkBoxTranslate = checkBox(l = "Trans",p=transLayout,cc =Callback(transCheck))
  168. transBtn = button(l="Rand Trans", command=Callback(randoTrans),p=transLayout)
  169. tText = textField(tx="10",p=transLayout,w=50,en=0)
  170.  
  171.  
  172. rotLayout = rowColumnLayout(nc=2,p=checkBoxLayout)
  173. checkBoxRotate = checkBox(l = "Rot",p=rotLayout,v=0,cc =Callback(rotCheck))
  174. transBtn = button(l="Rand Trans", command=Callback(randoRot),p=rotLayout)
  175. rText = textField(tx="360",p=rotLayout,w=50)
  176.  
  177.  
  178. checkLayout = rowColumnLayout(nr=1,p=checkBoxLayout)
  179. checkBoxX = checkBox(l = "X",p=checkLayout,v=1)
  180. checkBoxY = checkBox(l = "Y",p=checkLayout,v=1)
  181. checkBoxZ = checkBox(l = "Z",p=checkLayout,v=1)
  182.  
  183.  
  184. keyBox = checkBox(l = "Key",p=checkBoxLayout,v=0)#,bgc =[1,0,0])
  185. snapToSurfaceBox = checkBox(l = "SnapToSurface",p=checkBoxLayout,v=0,en=0)
  186. alignToSurfaceBox = checkBox(l = "AlignToSurface",p=checkBoxLayout,v=0,en=0)
  187. randoBtn = button(l="Randomiz Checked!", command=Callback(buttonPressed),p=checkBoxLayout,bgc =[.1,.9,.4])
  188.  
  189.  
  190. #snapToSurfaceLayout = frameLayout(l = "snap surface",p=mainLayout,w=50,cll=1,cl=1)
  191. addSurfaceButton = button(l="Add Surface",p=checkBoxLayout,command = Callback(addSnapSurface))
  192. snapSurface = textField("surface",p=checkBoxLayout)
  193. alignBtn = button(l="Align To Surface!", command=Callback(alignToSurface),p=checkBoxLayout,en=0)
  194. snapToSurfaceBtn = button(l="Snap Selected",p=checkBoxLayout,command = Callback(snapToSurface),en=0)
  195.  
  196.  
  197.  
  198.  
  199. win.show()
Advertisement
Add Comment
Please, Sign In to add comment