Exercise 04 – Hierarchy, Composition and Transformation

Though the intent of the previous exercise was to a create the 3D surface in which seating layouts can be arranged upon, the objective of Exercise 04 is to [/sourcecode] make use of the visual representation. The script in this exercise extracts structural data information from the generated 3D surfaces and manage that data to execute a seating layout that can not only be arranged upon such surfaces but also is able to be customized to fit user’s needs.

import rhinoscriptsyntax as rs
import math as m

#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

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

#Desired number of seats per row
nSeatPerRow = 10

#function for creating 2D profile of stage.
def StageProfile ():
    #The following generates the sectional polyline profile of the stage
    StageProfile = rs.AddPolyline (([0,0,0] , [0,0,StageH] , [0,-StageD,StageH]))
    blue = [0,0,255]
    rs.ObjectColor(StageProfile, blue)

    #The following generates the location of the performer and focal point on the stage
    FocalH = StageH+PerformerH
    return StageProfile

#function for creating 2D profile of the first row.
def RowProfile ():
    result = []
    
    #The following generates the sectional polyline profile of the first row.
    Row = rs.AddPolyline (([0,0,0,] , [0,RowD,0,] , [0,RowD,RowRiserH]))
    result.append (Row)

    #the following changes the color of the profiles for ease of visualization.
    magenta = [255,0,255]
    rs.ObjectColor(Row, magenta)
    
    return result

#function for creating array from the first row's profile.
def RowArray (Curve):
    result = []
    result.append (Curve)
    TransX = 0
    TransY = RowD
    TransZ = RowRiserH
    for i in range(1, nRows):
        RowTranslation = [i*TransX, i*TransY, i*TransZ]
        result.append (rs.CopyObjects (Curve, RowTranslation))
    return result 

#function for creating 3D sweep from joined 2D profile.
def AuditSweep ():
    return (rs.AddSweep2 (rails, JoinedProfile))
    
#function for finding locations of seats at the first row.
def SeatPathPoints (rail, nSeats):
    SeatPoints = []
    divs = rs.DivideCurve (rail, (nSeats*2))
    for i in range (1, len(divs),2):
        SeatPoints.append (divs[i])
    return SeatPoints
    rs.AddPoints (SeatPoints)

#function for copying seats to each Seat Path Point
def CopySeats (Seat, Points):
    result = []
    RefBox = rs.BoundingBox (Seat)
    RefLine = rs.AddLine (RefBox[0], RefBox[2])
    RefPt = rs.DivideCurve (RefLine,2)[1]
    rs.DeleteObject (RefLine)
    for pt in Points:
        CopyVect = rs.VectorCreate (pt, RefPt)
        result.append (rs.CopyObject (Seat, CopyVect))
    return result

#function for copying rows
def CopyRow (Row, Profile):
    RefBox = rs.BoundingBox (Row)
    RefPt = RefBox[0]
    results = []
    Curves = rs.ExplodeCurves (Profile)
    for i in range (2, len(Curves), 2):
        Pt = rs.DivideCurve (Curves[i],RowD,False,True)[4]
        CopyVect = rs.VectorCreate (Pt, RefPt)
        result = rs.CopyObjects (Row, CopyVect)
        results.append (result)

Stage = StageProfile ()
FirstRow = RowProfile ()
FullProfile = RowArray (FirstRow)
FullProfile.append (Stage)
JoinedProfile = rs.JoinCurves (FullProfile)

origin = [0, -6, 0]
rail01 = rs.AddArc3Pt ((origin), [50, -6, 0], [25,-2,0])
rail02 = rs.CopyObject (rail01,[0,50,0])
rails = [rail01, rail02]

MyAuditorium = AuditSweep()
MySeat = rs.GetObject("Select Seat")

MyRowSeatPoints = SeatPathPoints (rail01,nSeatPerRow)
MyRow = CopySeats (MySeat, MyRowSeatPoints)
CopyMyRow = CopyRow (MyRow, JoinedProfile)

rs.DeleteObjects (MyRow)
rs.DeleteObject (MySeat)
rs.DeleteObjects (rails)

#end

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