Hi everyone! I'm trying to make a general layout tool for maya scripting course, I have the interface generally down, but I am having trouble adding a translate function to the floatFieldGrp for location. If anyone could help me sort it out, it would be greatly appreciated! Thanks!
Here is the script so far:
import maya.cmds as cmds
import random
#Creates the board to layout buildings, might put into UI later if I have time.
cmds.polyPlane(width=100, height = 100, name = 'Ground')
#Define class, put DL to avoid confusion between other potential window items.
class DL_Window (object):
#creates method to construct window, call function "self".
def __init__(self):
#Creating some attributes, like name, title, and size of the window as it will initially appear on the screen.
self.window = 'DL_Window'
self.title = "City Layout Creator"
self.size = (400,400)
# will close old window if it's still open
if cmds.window(self.window, exists = True):
cmds.deleteUI (self.window, window= True)
#creates the new window
self.window = cmds.window (self.window, title=self.title, widthHeight=self.size)
#adjusts all UI to fit in the column
cmds.columnLayout(adjustableColumn = True)
#Create a title, and seperator from the name of the UI, and the function of the UI
cmds.text(self.title)
cmds.separator(height = 20, width = 100)
#Some customizable widgets that can adjust name, location of building on map, subdivisions for extruding windows or doors, and lastly the button.
self.cubeName = cmds.textFieldGrp( label = 'Building Name:')
self.cubeSize = cmds.floatFieldGrp ( numberOfFields = 3, label = 'size:', value1=1, value2=1,value3=1 )
self.cubeLocation = cmds.floatFieldGrp (numberOfFields = 3, label = 'location:', value1=1,value2=1,value3=1)
self.cubeSubdivs =cmds.intSliderGrp(field=True, label = 'subdivs', minValue=1,maxValue=20, value=1)
self.cubeCreateButton = cmds.button(label= 'Create Building', command=self.createBuilding)
#Repeat Steps for Trees
cmds.separator(height = 20, width = 100)
cmds.text("Tree Generator")
cmds.separator(height = 20, width = 100)
self.treeName = cmds.textFieldGrp( label = 'Tree Name:')
self.treeSize = cmds.floatFieldGrp ( numberOfFields = 3, label = 'size:', value1=1, value2=1,value3=1 )
self.treeLocation = cmds.floatFieldGrp (numberOfFields = 3, label = 'location:', value1=1,value2=1,value3=1)
self.treeSubdivs =cmds.intSliderGrp(field=True, label = 'subdivs', minValue=1,maxValue=20, value=1)
self.cubeCreateButton = cmds.button(label= 'Create Tree', command=self.createBuilding)
# Displays the window in Maya
cmds.showWindow()
def createBuilding (self, *args):
print ("A button has been pressed")
name = cmds.textFieldGrp(self.cubeName, query = True, text=True)
width = cmds.floatFieldGrp (self.cubeSize, query=True, value1=True)
height = cmds.floatFieldGrp (self.cubeSize, query=True, value2=True)
depth = cmds.floatFieldGrp (self.cubeSize, query=True, value3=True)
translateX = cmds.floatFieldGrp (self.cubeLocation, query = True, value1=True)
translateY = cmds.floatFieldGrp (self.cubeLocation, query = True, value2=True)
translateZ = cmds.floatFieldGrp (self.cubeLocation, query = True, value3=True)
subdivs = cmds.intSliderGrp (self.cubeSubdivs, query=True, value=True)
cmds.polyCube(name = name, width = width, height = height, depth = depth, translateX=translateX, translateY=translateY, translateZ=translateZ, subdivisionsWidth = subdivs,subdivisionsHeight = subdivs,subdivisionsDepth = subdivs)
#Calling the class here
myWindow = DL_Window()