Exercise 3: Solids and Surfaces

Program Generated Auditorium Sweep

The goal of this exercise is to further the concepts developed in Exercise 02 to create a 3-Dimensional parametric shape through geometric controlling operations. The script created will generate a 3D representation of a user-defined auditorium space.

import rhinoscriptsyntax as rs
import math as m

#Colors for visualization
color01 = [0,0,255] #blue
color02 = [255,0,255] #magenta
color03 = [255,0,0] #red

#THE FOLLOWING VARIABLES ARE FOR GENERATING THE SECTIONAL PROFILES FOR THE STAGE, PERFORMER, CHAIR, AND ROWS/RISERS.
#All units are in increments of feet

#How many rows are needed?
nRows = 6

#What is the height and depth of the Stage?
StageH = 4
StageD = 6  

#What is the Height of the Performer?
PerformerH = 6

#What is the tread depth and riser height of the Row?
RowD = 8
RowRiserH = 3

#What is the offset of the front of the chair from the back row riser?
SeatOffset = 2.5

#What is the height of the chair seat from the floor?
SeatFlrH = 1.5

#What is the depth of the chair seat?
SeatD = 2

#What is the height of the chair backrest?
BackH = 2.5

#General size (width) of the space
AuditW = 50

#Desired number of seats per row
nSeatPerRow = 10

def MakeStageProfile ():
    #The following generates the sectional polyline profile of the stage
    StageProfile = rs.AddPolyline (([0,0,0] , [0,0,StageH] , [0,-StageD,StageH]))
    rs.ObjectColor(StageProfile, color01)

    #The following generates the location of the performer and focal point on the stage
    FocalH = StageH+PerformerH
    FocalPt = rs.AddPoint (([0,-3,FocalH]))

def MakeRowProfile ():
    result = []
    
    #The following calculates the sectional polyline profile of the row.
    RowProfile = rs.AddPolyline (([0,0,0,] , [0,RowD,0,] , [0,RowD,RowRiserH]))
    result.append (RowProfile)

    #the following changes the color of the profiles for ease of visualization.
    rs.ObjectColor(RowProfile, color02)
    
    return result

def RowArray ():
    TransX = 0
    TransY = RowD
    TransZ = RowRiserH
    for i in range(1, nRows):
        RowTranslation = [i*TransX, i*TransY, i*TransZ]
        rs.CopyObjects (RowSection, RowTranslation)

StageSection = MakeStageProfile ()
RowSection = MakeRowProfile ()
FullProfile = RowArray ()

#join polyline
JoinedProfile = rs.JoinCurves (rs.GetObjects("Select Curves to Join", rs.filter.curve))

#create sweep for 3D form
def AuditSweep ():
    rail01 = rs.AddArc3Pt ([0,-6,0], [50, -6, 0], [25,-2,0])
    rail02 = rs.AddArc3Pt ([0,50,0], [50, 50, 0], [25,52,0])
    rails = rs.GetObjects("Select two rail curve", rs.filter.curve)
    shapes = rs.GetObjects("JoinedProfile", rs.filter.curve)
    rs.AddSweep2 (rails, shapes)

#The following function generates the seats throughout the surfaces

def SeatGenerator (Seat):
    AuditoriumSweep = rs.GetObjects("Select polysurface to explode", rs.filter.polysurface)
    ExplodedSurface = rs.ExplodePolysurfaces(AuditoriumSweep, True)
    
   
    for i in range (3, nRows*2, 2):
        exsf = ExplodedSurface[i]
        
        domainU = rs.SurfaceDomain(exsf, 0)
        domainV = rs.SurfaceDomain(exsf, 1)
    
        uParam = domainU [0] / 5
        vParam = domainV [1]*.75

        crv = rs.ExtractIsoCurve(exsf, (uParam, vParam), 0)
        SeatPoint = rs.EvaluateCurve (crv, uParam)
        rs.CopyObjects (Seat, SeatPoint)
            
        for j in rs.frange (0, AuditW, (AuditW/nSeatPerRow)):
            SeatPoint = rs.EvaluateCurve (crv, vParam)
            rs.CopyObjects (Seat, SeatPoint)


Auditorium = AuditSweep ()

MySeat = rs.GetObject("Select Seat to Copy")       
 
SeatGenerator (MySeat)

Exercise 2: Functions and Variables

Given the limitations posed by the simple array toolset explored in Exercise 01, the objective of this exercise is to create a parametric script that use variables and invokes functions to have more meaningful control on how shapes and objects are drawn, which in this case, is 2-Dimensional section representation of a tiered auditorium space. The goal of exploring these concepts is to further understand how the program can evolve into one that takes of advantage of control structures in the multi-dimension.

import rhinoscriptsyntax as rs

#Colors for visualization
color01 = [0,0,255] #blue
color02 = [255,0,255] #magenta
color03 = [255,0,0] #red

#THE FOLLOWING VARIABLES ARE FOR GENERATING THE SECTIONAL PROFILES FOR THE STAGE, PERFORMER, CHAIR, AND ROWS/RISERS.
#All units are in increments of feet

#How many rows are needed?
nRows = 25

#What is the height and depth of the Stage?
StageH = 3
StageD = 15  

#What is the Height of the Performer?
PerformerH = 6

#What is the tread depth and riser height of the Row?
RowD = 4
RowRiserH = 2.0

#What is the offset of the front of the chair from the back row riser?
SeatOffset = 1.6

#What is the height of the chair seat from the floor?
SeatFlrH = 1.5

#What is the depth of the chair seat?
SeatD = 1.25

#What is the height of the chair backrest?
BackH = 1.25

def MakeStage ():
    #The following generates the sectional polyline profile of the stage
    StageProfile = rs.AddPolyline (([0,0,0] , [0,0,StageH] , [0,-StageD,StageH]))
    rs.ObjectColor(StageProfile, color01)

    #The following generates the location of the performer and focal point on the stage
    FocalH = StageH+PerformerH
    FocalPt = rs.AddPoint (([0,-3,FocalH]))

def MakeChairAndRow ():
    result = []
    
    #The following calculates the sectional polyline profile of the row.
    RowProfile = rs.AddPolyline (([0,0,0,] , [0,RowD,0,] , [0,RowD,RowRiserH]))
    result.append (RowProfile)
    
    #The following locates the chair on the row "tread"
    ChairLoc = RowD-SeatOffset

    #The following generates the polyline section of the chair's seat.
    ActualSeatD = ChairLoc+SeatD
    
    #The following generates the polyline section of the chair's backrest.
    OverallSeatH = BackH+SeatFlrH
    
    #the following generates the final polyline section of the chair.
    ChairProfile = rs.AddPolyline (([0,ChairLoc,0] , [0,ChairLoc,SeatFlrH] , [0,ActualSeatD,SeatFlrH] , [0,ActualSeatD,OverallSeatH]))
    result.append (ChairProfile)

    #the following changes the color of the profiles for ease of visualization.
    rs.ObjectColor(RowProfile, color02)
    rs.ObjectColor(ChairProfile, color03)
    
    return result

def RowArray ():
    TransX = 0
    TransY = RowD
    TransZ = RowRiserH
    for i in range(0, nRows):
        RowTranslation = [i*TransX, i*TransY, i*TransZ]
        rs.CopyObjects (RowSection, RowTranslation)

rs.DeleteObjects (rs.AllObjects())
Stage = MakeStage ()
RowSection = MakeChairAndRow ()
MakeAllRows = RowArray()

Exercise 1: Python Batch Program

The objective of this exercise is to create a Python Batch program that generates a simple array of a 3D object.

#this links python to rhino
import rhinoscriptsyntax as rs

#this prompts user to select desired object to array
rs.SelectObjects

#Array = Number in X Direction _ Number in Y Direction _ Number in Z Direction _ Spacing in X _ Spacing in Y Direction _ Enter
rs.Command ("selall")
rs.Command ("Array 5 5 1 12 14 enter")

#end