title: Maya Python - Connecting UI to functions
body: <p>I am working on creating a little Bullet Spray Generator to be run in maya using Python and I'm stuck on how to take the values inputted by the user in the UI and use them in functions. The <code>bulletSpread</code> function needs to take the value from  <code>createGunUI</code>, specifically the <code>DistCtrl</code> slider and multiply it by a value in the <code>GunDictionary</code> to get the spread. Simply put, I just need to know how to take the inputted values from a slider in UI and use them in functions. </p>
  
  <p>I've included my code below, any help would be very much appreciated!</p>
  
  <pre><code>import maya.cmds as cmds
  import random
  import math
  
      #Dictionary containing weapon names and presets - presets contain values for shot sliders, distance sliders and multipliers for spread calculation
  GunDictionary = {}
  GunDictionary["weapon"] = ["Pistol", "Shotgun", "SMG", "Sniper", "RPG"]
  GunDictionary["weaponSelected"] = GunDictionary["weapon"][0]
  GunDictionary["Pistol_preset"] = [(1,18,9), (10,50,25), (0.1)]
  GunDictionary["Shotgun_preset"] = [(1,4,2), (10,50,25), (0.3)]
  GunDictionary["SMG_preset"] = [(5,30,15), (10,50,25), (0.2)]
  GunDictionary["Sniper_preset"] = [(1,3,2), (10,50,25), (0.05)]
  GunDictionary["RPG_preset"] = [(1,2,1), (10,50,25), (0)]
  
      #Initial cleanup of UIs
  if (cmds.window("Gun_Select", exists = True)): 
      cmds.deleteUI("Gun_Select")
  
      #Initial cleanup of scene
  cmds.select(all=True)
  cmds.delete()
  
  
      #Fire button condition - creates wall
  def goShoot(gunSelected, numOfShots, *pArgs): 
      print "Begin"
      weaponName = GunDictionary["weaponSelected"]
      cmds.deleteUI(weaponName)
      createWall()
      bulletSpread(GunDictionary["weaponSelected"])
  
  
      #Cancel UI2 - deletes UI2
  def cancelShoot(*pArgs):
      print "cancel"
      weaponName = GunDictionary["weaponSelected"]
      cmds.deleteUI(weaponName)
  
      #Cancel UI1 - deletes UI1
  def cancelSelect(*pArgs):
      print "cancel"
      cmds.deleteUI("Gun_Select")
  
  
      #Function to create wall
  def createWall():
      wall = cmds.polyCube(h=10, w=15, d=1, name='wall')
      cmds.move(0,5,0, 'wall')
  
  
  
  newRange = 0;
      #Function to generate bullet spread
  def bulletSpread(gunSelected, distance):
      weaponName = GunDictionary["weaponSelected"]
      multiplier = GunDictionary[weaponName + "_preset"][2]
      distance = ???
      newRange = distance * multiplier
      print newRange
  
  
  
      #Function to create drop-down menu in createSelectUI
  def printNewMenuItem(item):
      print item
      GunDictionary["weaponSelected"] = item
      return GunDictionary["weaponSelected"]
  
  
  
      #Function to take weapon selected in UI1 and call UI2, also calls function to calculate bullet spread
  def ui_refreshSelWeapon(fun, *args):
      createGunUI(GunDictionary["weaponSelected"])
  
  
  
      #UI allowing user to pick from a selection of Guns in a drop-down menu
  def createSelectUI(): 
      cmds.window("Gun_Select")
      cmds.columnLayout(adjustableColumn=True)
  
      GunSelectCtrl = cmds.optionMenu(label='Gun', changeCommand=printNewMenuItem)
      for i in GunDictionary["weapon"]:
          cmds.menuItem(label=i)
  
      cmds.button(label = "Continue", command = ui_refreshSelWeapon)
  
      cmds.button(label = "Cancel", command = cancelSelect)
  
      cmds.showWindow("Gun_Select")
  
  createSelectUI()
  
  
  
  weapon_uiDic = {}
  
      #Called after gun select, allows user to choose the number of shots and distance from wall
  def createGunUI(gunSelected):
  
      weaponName = GunDictionary["weaponSelected"]
  
      if cmds.window(weaponName, exists=True):
         cmds.deleteUI(weaponName)
  
      cmds.window(weaponName)
      cmds.columnLayout(adjustableColumn=True)
  
      cmds.deleteUI("Gun_Select")
  
      numBullets = GunDictionary[weaponName + "_preset"][0]
      distToTarget = GunDictionary[weaponName + "_preset"][1]
  
      weapon_uiDic["NumBulletsCtrl"] = cmds.intSliderGrp(label='Number of Shots',
                                                         minValue=numBullets[0], maxValue=numBullets[1], value=numBullets[2], field=True)
  
      weapon_uiDic["DistCtrl"] = cmds.intSliderGrp(label='Distance to Target (metres)', 
                                                   minValue=distToTarget[0], maxValue=distToTarget[1], value=distToTarget[2], field=True)
  
      weapon_uiDic["fireButton"] = cmds.button(label = "Fire", 
                                              command = lambda *args: goShoot(cmds.intSliderGrp(weapon_uiDic["NumBulletsCtrl"], 
                                              query=True, value=True), cmds.intSliderGrp(weapon_uiDic["DistCtrl"], query=True, value=True)))
  
      cmds.button(label = "Cancel", command = cancelShoot)
  
      cmds.showWindow(weaponName)
  </code></pre>
  
  <p>Thank you!!</p>