Python Resources

Updated on Feb 5 2022

Python Resources

Deborah R. Fowler



Introduction to Python in Houdini

Posted on Oct 17  2018
Updated on Feb 16  2020


Last day (class 12) we introduced Houdini. Today we will continue our discussion by introducing a snowman in python.
IF YOU WORK AT HOME BE SURE TO MATCH TO THE SAME VERSION WE ARE USING (see instructions here)

We are going to build the snowman by copying correctly sized spheres onto points. The steps are as follows:
MISSIN GIMAGE
MISSING IMAGE

Next add the line to manipulate the radius, baseRadius *= .8 and you have the code given below



Variations - rather than have the sphere centered on the origin, what if it were on the ground plane? How about parameters? How about making this a function?

A very common thing to do in Houdini is to set an object so that it stays on the ground plane. For example, the sphere below is on the grid by referencing the parameter rady and translating it up that value.
In this way, no matter what the size of the sphere, it will sit on the groundplane. So the expression in ty (Center's parameter) is set to ch("rady") which is the value of the radius in the y direction

MISSING IMAGE

This requires some changes to our code since the first sphere is already sitting on the grid, we do not need to move it. The next sphere will be the diameter of the previous spheres

MISSING IMAGE

Finally, user defined parameters are added so that we have a tool we could use to allow arbitrary amounts of snowballs and adjustable radius.
User defined parameter are added using the parameter dialog box and then are evaluated as seen below. Then the code is wrapped in a function and called.

MISSING IMAGE