Hi Daniel, 
the error you're getting is from the  polyCube 
<https://help.autodesk.com/cloudhelp/2018/ENU/Maya-Tech-Docs/CommandsPython/polyCube.html>
 command. 
This commands does not have translation key words argument that you are 
trying to assign to it.

Solution:

# get returned values of polyCube command 
cube = cmds.polyCube(name = name, width = width, height = height, depth = 
depth, subdivisionsWidth = subdivs, subdivisionsHeight = subdivs, 
subdivisionsDepth = subdivs)

# set the 1st returned transform node.  With the move 
<https://help.autodesk.com/cloudhelp/2018/ENU/Maya-Tech-Docs/CommandsPython/move.html>command
 
it is faster as you can set value relatively or absolutely
cmds.move(translateX, translateY, translateZ, cube[0],  r=True)

# or you can also use the setAttr 
<https://help.autodesk.com/cloudhelp/2018/ENU/Maya-Tech-Docs/CommandsPython/setAttr.html>
command
cmds.setAttr("{0}.translate".format(cube[0]),  translateX, translateY,  
translateZ, type="double3")


And.... yeah, here is a check to avoid creating the ground each time. 

# create it once until you delete it:
None if cmds.objExists('Ground') else cmds.polyPlane(width=100, height = 
100, name = 'Ground')

or you can write:
if cmds.objExists('Ground'):
    pass
else:
    cmds.polyPlane(width=100, height = 100, name = 'Ground')


Cheers!
On Wednesday, June 1, 2022 at 9:54:32 PM UTC+2 daniel.w...@gmail.com wrote:

> 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()
>

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to python_inside_maya+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/881f659e-adf3-4b1b-a8c0-fedc64b86dcdn%40googlegroups.com.

Reply via email to