Trying to set my poly cube to a variable, then set attribute to translate Y. Keep getting error

Viewed 67

Here is the code I have so far:

import maya.cmds as cmds

wyndow=cmds.polyCube(width= 5, height= 10, depth=1, subdivisionsWidth=5, subdivisionsHeight=10, subdivisionsDepth=5, name= "Window_1")

cmds.setAttr(wyndow+".translateY", 5)

Im trying to bring my polycube up on translate Y, but I keep getting the error of:

Error: TypeError: file line 3: can only concatenate list (not "str") to list #**

1 Answers

As haggi said, use wyndow[0], which is the transform node for your new polyCube.

Here's the code for that:

import maya.cmds as cmds
wyndow=cmds.polyCube(width=5, height=10, depth=1, subdivisionsWidth=5, subdivisionsHeight=10, subdivisionsDepth=5, name= "Window_1")
cmds.setAttr(wyndow[0] + ".translateY", 5)

Although you're not asking for this, I would likely use variables for the values you're using for your cube. Easier to get to them, and I'm guessing that your Y movement will always be 1/2 the height, you can use the height variable to get that, and allow different size windows. Like this:

import maya.cmds as cmds
wyndowHeight = 10
wyndowWidth = 5

wyndow=cmds.polyCube(width=wyndowWidth, height=wyndowHeight, depth=1, subdivisionsWidth=wyndowWidth, subdivisionsHeight=wyndowHeight, subdivisionsDepth=5, name= "Window_1")
cmds.setAttr(wyndow[0] + ".translateY", (wyndowHeight * 0.5) )
Related