
This can be adapted to be used in our function to create a new shading node: # create a material with the given name ts(name=material+'MaterialGroup', renderable=True, empty=True) cmds.shadingNode(material, name=material+'Shader', asShader=True) Now if you look up “ surface ShaderList” on the Maya docs, you’ll see a section of example code at the bottom:

This is a tricky part that will require some references to the documentation. The function change_colour() will take in the object, the name of the material and the colour def change_colour(object, material, colour): Since we’ll be changing the colours for both objects, let’s make a function to assign a material to an object and change its colour. We’ll come back to this function later when we need to combine the two shapes. # Create the cone and pompom cone_obj, cone_node = cmds.pol圜one() pompom_obj, pompom_node = cmds.polySphere(r=0.25) # Move the pompom to the right spot on the hat cone cmds.move(0, 1.06, 0) The pompom will have to be scaled down from the default size and moved up on the y axis to be on the right spot on the cone. Now we need to create the polygons that make up the hat: a cone for the base and a sphere for the pompom. def createHat(cone_colour=None, pompom_colour=None):

In this script, if the colour is not specified, a random one will be generated. In this super-simplified model of a party hat, the only two polygons you need are a cone and a sphere (for the pompom on the hat).Ĭreate a function, createHat(), that takes in 2 optional parameters, cone_colour and pompom_colour (that default to None in the case that the user wants a random colour). Start off your script by importing the two external packages that we need: cmds and random (to generate the random colour values later on) import maya.cmds as cmds import random Step 8: Create the hat components

Pick your favourite text editor and make a python file called hatCreator.py in one of the locations listed. This will display the paths in the output window above the editor.
