This instructable will show you how to create a recursive object in Maya using the MEL (Maya Embedded Language) scripting language. In addition, it will cover how to 3D print these objects using an Objet Eden 260V.

Materials you will need:

1. Autodesk Maya 2014 Software
2. McNeel Rhinoceros Software
3. 3D printer

## Step 1: What Is Recursion?

Recursion is the process through which self-similar items, or objects, are repeatedly duplicated. A common, real world example of this is when you orient two mirrors to face each other in parallel and they continuously reflect a single image into infinity - this is known as infinite recursion. For this instructable we will simply focus on the duplication of a single geometry in order to create a larger, three dimensional object.

## Step 2: Opening the Maya File and Preparing the Recursive Script

To begin creating a recursive object in Maya open the "Starting Sphere.mb" file provided in this step. It will automatically set both your Maya units and Maya grid to an inch configuration and provide a .5" sphere to begin playing with. Next, go to "Window/General Editors" in the menu bar and select "Script Editor". Once open, copy and paste the text from "MEL recursive sciprt.txt" into the bottom section of the Script Editor as shown in the above image.

## Step 3: Running the Recursive Script

To run the script you must first select the sphere that currently exists in the scene - do so by single clicking it with your left mouse button. It will illuminate green when selected. Next, highlight all of the text that you copied into the scipt editor by clicking and dragging over it all using the left mouse button. It will illuminate blue when selected. After you have both the sphere and the script selected, go to "Command" and select "Execute" in the Script Editor menu bar. This will run the script and create all duplications of the sphere in the Maya scene.

## Step 4: Changing Script Variables

You may have noticed that your recursive object doesn't look the same as the one in the image I provided. That is because this script is using random variables to decide where to place each sphere. You can freely change these variables to generate different effects - simply alter the numbers within any "rand" variable to do so. For example, "rand(-.49,.49)" could be changed to "rand(-2,2)" - this would make the script move the duplicated spheres up to 2" as opposed to just up to .49". Be careful, though - if you remove or change any of the additional objects, such as a "(", ")", "=", or ";" the script will no longer run. This is because these are specific objects within the script that give it specific instructions and not having them will simply cause the script to fail.

You can also make the object much larger by having the script run longer. Currently, the script only makes 200 duplications. If you want it to run longer simply change the "while (\$countC <= 200);" to "while (\$countC <= 1000);". At the end of the day that count number can be whatever you like. A fun exercise is to see how many objects you can make before crashing the program - my current computer begins to really slow down around 10k spheres...

## Step 5: Exporting the Object for 3D Printing

To export the object for 3D printing, select all of the spheres by clicking and dragging with your left mouse button over all of the objects in the scene. Once selected, go to "File" in the menu bar and select "Export Selection". In the window that pops up drop down the "Files of type" menu and select "OBJexport". Then name your file as you see fit and click "Export Selection" to finish the export process.

If when you drop down the "Files of type" menu you don't see "OBJexport" it means that the OBJ plugin isn't loaded. To load it for use simply go to "Window/Settings/Preferences" in the menu bar and select "Plug-in Manager". Once the plug-in manager window has opened, scroll down and check the boxes to load the "objexport.mll" file. Once completed, close the plug-in manager window and begin the above process over again.

## Step 6: Arranging Your Object for the 3D Printer in Rhinoceros

In Rhinoceros go to "File" in the menu bar and select "Open". Select your recently created OBJ file in the pop-up window and select "Open" to bring the file into Rhino. An OBJ import window will pop-up, but no changes to this will need to be made and you can simply click "OK". Usually, an OBJ file will open in Rhino in millimeters. You can change this to inches, if you want, by going to "File" in the menu bar and selecting "Properties". When the "Document Properties" window pops up, select "Units" and drop down the "Model Units" menu and select "Inches". Of course, you can simply leave the model in millimeters as well.

You can now freely use the "Move" and "Rotate" commands to move and rotate the objects in order to orient them properly for your 3D printer. These commands can be used by simply typing "move" and hitting "Enter" on the keyboard and "rotate" and hitting "Enter" on the keyboard respectively. Before activating any commands be sure to select all geometry in the scene by clicking and dragging across it all using your left mouse button.

The Objet Eden 260V prints faster in the X and Y axis than it does in the Z axis - therefore, I have oriented my file to place as much of the object in the X and Y axis as possible. Given that 3D printers can take some time to print, as well as be expensive to run, I've also used the "Scale" command (type "scale" and hit "Enter" on your keyboard) to reduce the size of my print to no longer than 3" along its largest axis. This will speed things up and prevent the print from costing too much.

## Step 7: Exporting an STL

Once you are finished orienting your object you need to export it as a STL for the 3D printer. To do this, simply make sure all of your geometry is selected and go to "File" in the menu bar and select "Export Selected". When the "Export" pop-up appears, drop down the "Save as type" menu and select "STL (Stereolithography) (*stl)". Then name your file as you see fit and click "Save". A pop-up titled "STL Export Options" will appear - select "Binary" and click "OK".

## Step 8: 3D Printing

Load the STL file into your 3D printing software and send it to your machine. Each 3D printer and printing software works a bit differently - therefore, you will have to use the settings that work best for your specific setup. For the Eden 260V, I was able to simply let the geometry overlap and then print. For some other printers, such as the Type A Machines Series 1, you would need to "Boolean Union" the geometry together before exporting from Rhino for the print to be successful.

## Step 9: Final Object and Summary

Here are some pictures of my final printed object. I decided to print it in a basic white material.

Summary

For this example I decided to use a sphere as my beginning geometry. Keep in mind that this kind of recursive script works on any type of geometry in Maya. If interested, you can continue testing the script on a box, a plane, a torus, or any other geometry you like! Please post images of your results in the comments below!

<p>You can do stuff like that directly in Rhino, using VBScript.<br>Examples from a script I made for generative art congress in Milano 2004.<br>Those are bended surfaces, but it can easily be adapted to create 'solids'.<br>Last pic shows a lasercut lampshade created with this script.<br><br></p>
<p>Thanks for the images! Of course, recursive loops are part of many programming languages so there are several software suites this can be done in. Grasshopper also allows it in various forms, although it isn't necessarily its favorite task (ie. hoopsnake bugs) ;-)</p>
<p>can someone tell me what wrong with this code</p><p>// create a window with a menu bar</p><p>{</p><p> {</p><p>window -title &quot;Simulation&quot; -menuBar true -width 400 -height 300;</p><p>//add a background color</p><p>formLayout -bgc 1 .8 0;</p><p>//define layout</p><p>rowLayout -numberOfColumns 5 -columnWidth5 80 50 50 50 50;</p><p>//create button label and command</p><p>button -bgc 0 0 0 -label &quot;Start Simulation&quot; -command &quot;Start Simulation&quot;;</p><p> button -label &quot;Ball&quot; -command &quot;sphere&quot;;</p><p> button -label &quot;Pipe&quot; -command &quot;cylinder&quot;;</p><p> button -label &quot;Box&quot; -command &quot;polyCube&quot;;</p><p> button -bgc 1 1 1 -label &quot;Quit&quot; -command &quot;deleteUI window Simulation&quot;;</p><p>//create a tear off</p><p>menu -label &quot;edit&quot; -tearOff true;</p><p>//add the menu items</p><p>menuItem -label &quot;New&quot;;</p><p>menuItem -label &quot;Open&quot;;</p><p>menuItem -label &quot;Save&quot;;</p><p>menuItem -divider true;</p><p>menuItem -label &quot;Quit&quot;;</p><p>//add a help menu</p><p>menu -label &quot;Help&quot; -helpMenu true;</p><p>menuItem -label &quot;about Application...&quot;;</p><p>//create some keys for the boxes, translate X using the setKeyframe command.</p><p>setKeyframe -time 1 -value -5 box.translateX;</p><p>setKeyframe -time 25 -value 5 box.translateX;</p><p>//Adding Rotation:</p><p>setKeyframe -time 1 -value -5 box.translateX;</p><p>setKeyframe -time 1 -value 0 box.rotateZ;</p><p>setKeyframe -time 25 -value 5 box.translateX;</p><p>setKeyframe -time 25 -value -360 box.rotateZ;</p><p>//Adding TranslateY:</p><p>setKeyframe -time 1 -value 15 box.translateY;</p><p>setKeyframe -time 1 -value -5 box.translateX;</p><p>setKeyframe -time 1 -value 0 box.rotateZ;</p><p>setKeyframe -time 25 -value 5 box.translateX;</p><p>setKeyframe -time 25 -value -360 box.rotateZ;</p><p>setKeyframe -time 25 -value 0 box.translateY;</p><p>showWindow;</p><p>//Make multiple boxes </p><p>int \$countC = 1;</p><p>do {</p><p> duplicate;</p><p> float \$randA = rand(-.50,.50);</p><p> float \$randB = rand(-.50,.50);</p><p> float \$randC = rand(-.50,.50);</p><p> int \$randD = rand(0,6000);</p><p> int \$randE = rand(0,6000);</p><p> int \$randF = rand(0,6000);</p><p> move -r \$randA \$randB \$randC;</p><p> rotate -r \$randD \$randE \$randF;</p><p> currentTime \$countC;</p><p> \$countC ++;</p><p> }</p><p>while (\$countC &lt;= 200);</p><p> }</p><p>}</p>
<p>OpenScad is a great tool for this as well. You can easily write a 3D fractal in 4-5 lines of code.</p><p>The only drawback is that OpenScad doesn't seem to do very well with high polygon count geometries, so you may need to wait a very long time for things to render.</p>
<p>Yes, thanks - I will try as well. </p><p>Maya does benefit from being able to produce very high mesh counts when using polygons. It also does quite well with high numbers of NURBS objects, though not as well as polys. The major hiccup I run into in some situations is editing once created - that can just be too system intensive at times...</p>
<p>Thx for that, will try that.</p>
<p>Looks a lot like this:</p><p><a href="https://www.instructables.com/id/3D-Print-a-Protein-Modeling-a-Molecular-Machine/" rel="nofollow">https://www.instructables.com/id/3D-Print-a-Protein...</a></p><p>Except that its random.</p>

### About This Instructable

13,953views

55favorites

License:

Bio: MTTR MGMT is an award-winning design practice that ranges widely in discipline, methodology and media. MTTR MGMT’s focus lies on the investigation, representation and ... More »
More by ma77er:
Add instructable to: