Random Extrude 2.0

Problem I’m solving

Sometimes you want to extrude polygons randomly, but it’s a manual task.

Solution

This script does the random extrude automatically with the given values.

Installation

  1. Simply just drag the InstallerDragnDrop.ms script to the viewport to install.
  2. Right-click on the toolbar > Customize…
  3. Choose the tab ‘Toolbars’
  4. In the Category: dropdown, select ‘ManniiCode’
  5. Drag the script to the toolbar where ever you want!

Code

from pymxs import runtime as rt
import random
rt.execute("fn b2a the_birray = (return the_birray as Array)")
def random_extrude(val_min, val_max):
selected_any = rt.getCurrentSelection()
if len(selected_any) > 0:
our_object = rt.getCurrentSelection()[0]
if rt.classOf(our_object) == rt.Editable_Poly:
#Extrude by Polygons
our_object.extrusionType = 2
selected_polygons = rt.polyop.getFaceSelection(our_object)
#Convert BitArray to Array
selected_polygons_array = list(rt.b2a(selected_polygons))
with pymxs.undo(True,""):
for i in selected_polygons_array:
#random integer
amount_to_extrude = random.randint(val_min, val_max)
our_object.EditablePoly.SetSelection("Face", rt.BitArray(i))
our_object.faceExtrudeHeight = amount_to_extrude
our_object.EditablePoly.buttonOp("Extrude")
#Select the extruded polygons
our_object.EditablePoly.SetSelection("Face", selected_polygons)
else:
rt.messageBox("The object needs to be EditablePoly")

Images