Deborah R. Fowler
Python
in Houdini Example - Phyllotaxis SOP
Posted July 8 2018
Updated July 12 2018
Phyllotactic Pattern - described here
Here the example is given in a python sop node. Similar
to the point wrangle node, we can create the points for the
phyllotactic pattern in code. This page includes some discussion
about the creation of parameters as well.
Starting with a simple example the code would look like this:
We have used a for loop in python and created a point using Houdini's geo.createPoint() as well as setting the position. Going one step further, we can create user-defined parameters rather than hard-coded values.
There are two methods to do this:
- using code (less common unless running a python script, but discussed below)
- Using the parameter editor interface available on any node by clicking on the gear button top right
This brings up a the parameter interface window where you can drag the type of parameter from the LHS to the RHS as seen in the gif. The parameter is then referenced - for example angle parameter would be node.parm("angle").eval()
This now give you the power to create nodes with gui.
Going one step further - making it a function
Using code for parameter creation in a python SOP:
In python scripting using code is straightforward to create parameters, however there was a small problem I ran into when creating with code in a SOP. Once created, the SOP errors as the parameter is already created. I have listed two solutions below:
- Setting up the parameter interface with one call and commenting it out once created. Not the best solution but will investigate
- Adding the parameter, but checking that it has not previously been added. This is not optimal but works
Results from using this node:
While playing with phyllotaxis in python, adding some other houdini nodes I created "Calcium"