For anyone who would want a template to build a quick UI inside Maya, the below code should be a good starting point. It creates a UI. It has a float field where the user can enter a value and click the “Set distance button” , which inturn prints out the value. Simple example ! But should be useful.

import pymel.all as pm
import math

def newPosition(tests_dist):
    # We should always query back the float field so that we get the actual float value
    tests_dist = cmds.floatField(tests_dist, q=1, v=1)
    print tests_dist

def testing_window():
    ## Make Gui Window
    windowID = "testing_control"

    if window(windowID, exists=True):
        deleteUI(windowID)

    testing_Gui = window(windowID,title="testing float", widthHeight=(200, 200)) 

    masterLayout = rowColumnLayout(["masterLayout"], numberOfColumns=1, columnWidth=[(1,200)])      

    text(label="distance")
    separator(height=10, style="none")
    text(label="EXAMPLE")
    separator(height=10, style="none")

    test_dist = floatField(value = 0.2,precision=4, w = 30) 
    selectAll = button(["Set"],label='Set Distance',  width=85, height=26, align='center',command= lambda *args:newPosition(test_dist))                                     
    showWindow() 

def testing_Gui():
    if window("testing_Gui", exists = True):
        deleteUI("testing_Gui")

    testing_window()

testing_Gui()

 

Leave a Reply