Hour of code
Watch video below for a quick demonstration on how to load and run the code (Make full-screen):
Use the handout as a resource and answer the questions on the backside. Download Handout Steps:
|
Sample Code
def draw_stairs
# Create some variables. stairs = 12 rise = 8 run = 11 width = 60 thickness = 2 # Get handles to our model and the Entities collection it contains. model = Sketchup.active_model entities = model.entities # Loop across the same code several times for step in 1..stairs # Calculate our stair corners. x1 = 0 x2 = width y1 = run * step y2 = run * (step + 1) z = rise * step # Create a series of "points", each a 3-item array containing x, y, and z. pt1 = [x1, y1, z] pt2 = [x2, y1, z] pt3 = [x2, y2, z] pt4 = [x1, y2, z] # Call methods on the Entities collection to draw stuff. new_face = entities.add_face pt1, pt2, pt3, pt4 new_face.pushpull thickness end end |