Maya Python - Connecting UI to functions -


i working on creating little bullet spray generator run in maya using python , i'm stuck on how take values inputted user in ui , use them in functions. bulletspread function needs take value creategunui, distctrl slider , multiply value in gundictionary spread. put, need know how take inputted values slider in ui , use them in functions.

i've included code below, appreciated!

import maya.cmds cmds import random import math      #dictionary containing weapon names , presets - presets contain values shot sliders, distance sliders , multipliers 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 create wall def createwall():     wall = cmds.polycube(h=10, w=15, d=1, name='wall')     cmds.move(0,5,0, 'wall')    newrange = 0;     #function generate bullet spread def bulletspread(gunselected, distance):     weaponname = gundictionary["weaponselected"]     multiplier = gundictionary[weaponname + "_preset"][2]     distance = ???     newrange = distance * multiplier     print newrange        #function create drop-down menu in createselectui def printnewmenuitem(item):     print item     gundictionary["weaponselected"] = item     return gundictionary["weaponselected"]        #function take weapon selected in ui1 , call ui2, calls function calculate bullet spread def ui_refreshselweapon(fun, *args):     creategunui(gundictionary["weaponselected"])        #ui allowing user pick selection of guns in drop-down menu def createselectui():      cmds.window("gun_select")     cmds.columnlayout(adjustablecolumn=true)      gunselectctrl = cmds.optionmenu(label='gun', changecommand=printnewmenuitem)     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 choose number of shots , distance 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 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) 

thank you!!

i replaced lambda function partial module. used pass args through maya ui.

i don't understand why don't track distance data through different functions. have read code , print values @ each step see goes, if don't understand flow. why in "goshoot", define variable gunselected inputed if use gundictionary["weaponselected"] instead of gunselected. in "bulletspread", specify 3 args , input 1 under "goshoot". can't work if functions not linked properly.

you can find , version of code below :

import maya.cmds cmds import random import math functools import partial      #dictionary containing weapon names , presets - presets contain values shot sliders, distance sliders , multipliers 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, distance, *pargs):      print "begin"     weaponname = gunselected     cmds.deleteui(weaponname)     createwall()     bulletspread(gundictionary["weaponselected"], distance)   #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 create wall def createwall():     wall = cmds.polycube(h=10, w=15, d=1, name='wall')     cmds.move(0,5,0, 'wall')    #function generate bullet spread def bulletspread(gunselected, distance):     weaponname = gundictionary["weaponselected"]     multiplier = gundictionary[weaponname + "_preset"][2]     distance = distance     newrange = distance * multiplier     print newrange        #function create drop-down menu in createselectui def printnewmenuitem(item):     print item     gundictionary["weaponselected"] = item     return gundictionary["weaponselected"]        #function take weapon selected in ui1 , call ui2, calls function calculate bullet spread def ui_refreshselweapon(fun, *args):     creategunui(gundictionary["weaponselected"])        #ui allowing user pick selection of guns in drop-down menu def createselectui():      cmds.window("gun_select")     cmds.columnlayout(adjustablecolumn=true)      gunselectctrl = cmds.optionmenu(label='gun', changecommand=printnewmenuitem)     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()  def refreshvalues(*args):     function = args[0]     weapon = args[1]     get01 = cmds.intslidergrp(args[2],query=true, value=true)     get02 = cmds.intslidergrp(args[3],query=true, value=true)     print get01, get02     function(weapon, get01, get02)  weapon_uidic = {}  #called after gun select, allows user choose number of shots , distance 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 target (metres)',                                                   minvalue=disttotarget[0], maxvalue=disttotarget[1], value=disttotarget[2], field=true)      weapon_uidic["firebutton"] = cmds.button(label = "fire",  command = '')     cmds.button(weapon_uidic["firebutton"], e=1,                                                                                   c=partial(refreshvalues,                                                       goshoot,                                                       gundictionary["weaponselected"],                                                       weapon_uidic["numbulletsctrl"],                                                       weapon_uidic["distctrl"]))      cmds.button(label = "cancel", command = cancelshoot)      cmds.showwindow(weaponname) 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -