Week 7


/// 1.Maya Cubes

a) create a 20 units height rectangular box with 15 subdivisions along X, 10 along Y and 15 along Z, and

b) move this cube to position [1, 1.70, 4].

import maya.cmds as cmds

cmds.polyCube(w=15,h=10,d=15) #this creates a polyCube with the above measurements

cmds.move(1,1.70,4) #this moves the polyCube

///2. Adding Functionalities


 c) rotate the cube from the previous activity by 40 degrees around the X axis, 60 degrees around the Y axis and 20 degrees around the Z axis

cmds.rotate(40,60,20)

d) freeze the cubes translations

cmds.makeIdentity( apply=True )

e) modifying its name to become “myCube999”

cmds.rename('pCube1', 'myCube999')

f)delete a cube

cmds.delete( 'myCube999')

///3.Modularizing scripts


# a function called my_create, to create a rectangular box of a user specified height, and subdivisions along X, Y and Z;

import maya.cmds as cmds #imports maya commands

def my_Create ():

    cmds.polyCube(w=1,h=1,d=1)

my_Create()

#a function called my_move, to move a cube to a user specified position XYZ;

def my_move ():  

   cmds.move(1,1.70,4)

my_move()

#a function called my_rotate, to rotate a cube around X, Y and Z axes by a user specified amount of RX, RY and RZ degrees;

def my_rotate():

 cmds.rotate(40,60,20)

my_rotate()

#a function called my_freeze, to freeze the translation and rotation;

def my_freeze():

 cmds.makeIdentity( apply=True )

my_freeze()

 # a function called my_modify, to modify the name of the asset to be a user specified name

def my_modify():

 cmds.rename('pCube1', 'myCube999')

my_modify()

#a function called my_select, to select the cube and delete it

def my_select():

  cmds.select('myCube999', tgl=True)

 cmds.delete( 'myCube999')

 ///5. Maya Windows


import maya.cmds as cmds

window = cmds.window(title="Long Name", iconName="Short Name", widthHeight=(200, 55)) #creates a window with the name Long name and with size x=200 and y=55. To change the size of the window, just change the numbers in widthHeight= ()

cmds.columnLayout(adjustableColumn=True) #a window must have a layout so we set it with this command

cmds.button(label="Do Nothing") #creates a button named label equal to "Do Nothing". when we press it nothing happens

cmds.button(label="Close", command=('cmds.deleteUI(\"' + window + '\", window=True)')) #button that is named as "Close". When pressed it deletes the window

cmds.setParent("..")

cmds.showWindow(window) #This command shows the window we just created


 

Leave a comment

Log in with itch.io to leave a comment.