Tutorial : Plastic brick castle

From Wikinico

Jump to: navigation, search

IN CONSTRUCTION

The aim of this tutorial is to teach basic methodology about programming through the construction of a brick castle in Python.

First brick first

We need first to be able to create a brick before creating a castle:

Let's write:

def create_brick():
    pass

Now we have a function to create a brick, it's not finished of course but the concept is here, to create a brick we'll call the function create_brick.

In Maya

Because we'll use functions from the maya.cmds package we need to import it:

If you don't understand this line read this : Import in Python

import maya.cmds as cmds


def create_brick():
    cmds.polyCube()

If we call:

create_brick()

It creates a cube of size (1,1,1).

We test it in Maya, it creates a cube, cool. Now we need to have a possibility to change the size. Our plastic bricks will all have the same height (we decide for now it will be 1)

So we would create a brick by deciding the width and depth as:

create_brick( 3, 2 )

So we modify create_brick this way:

def create_brick( width, depth ):
    cmds.polyCube( width=width, height=1, depth=depth )
Personal tools