Pyramid Script


For my first pyramid script, I used a basic looping code that would allow me to change a variable that could generate a pyramid, of any size of my choice. This was done by having the code update the size and the height of each new cube by 1 each time. This would then repeat the number of times that as the thickness wanted to create a completed pyramid.

This worked well but I decided to make it more advanced by adding a window panel that would allow me to change the pyramid's size without having to run a new code each time.

One way of doing this was, after looking and learning about sliders. Having a slider that would allow me to update the pyramid's size live, within the window. To do this we would use a similar code as before though use a Function that could be activated through a button on the window. 

Firstly, creating a function I had to identify the two key variables, (ignore colour variable). These would be height and Slider. I would then have the slider give a value that would be sent back to the function as the variable "slider_value". Once I had the updated "slider_value" variable I could then run the same code as my first pyramid to generate the structure. 

The other function in this script, and one that I used throughout this project was the Delete all, This allowed me to quickly press the tool to remove all poly models in the scene before I generated a new pyramid. This was done by selecting all, then simply deleting. Pressing the button in the window would run this function.


After making the Slider script, I found that though it was interesting, I would like to see how to make a more detailed script as the slider was not easy to get an exact size for the pyramid. To do this I would use a really similar code, though instead change the slider, into a intField. To do this I did decide to copy over the script and set all slider parameters to fields. This allowed me to type a figure into the text box on my window and generate the pyramid of an exact size.

Once I had these two scripts I wanted to put them together to create my final pyramid generation tool. This was as simple as copying over the two codes and separating the variables to "Slider" or "Field" so that they could work coherently. Finalising my tool window I am happy with how it turned out.

This project was really useful to me as I was able to use lots of techniques to learn a lot more about coding for Maya. My pyramid building window works well for the task and uses multiple commands to give the user lots of choice in generation.

Leave a comment

Log in with itch.io to leave a comment.