In between reading various programming tutorials and beating my head against a wall I tried to draw something, and immediately discovered I still don’t know what I’m doing in any way. But hey, at least it’s colour coded.
I’m trying to draw a staircase using a variable for the number of steps, but I can’t figure out how to draw the middle of the stair. The top and bottom geometry will remain fixed, but how do I create the variable middle? You can see below how I thought it should work, but it doesn’t.
What’s the best way to do this? I haven’t found it yet.
Thanks.
def self.create_stair
model = Sketchup.active_model # Open model
ent = model.entities # All entities in model
sel = model.selection # Current selection
model.start_operation('Create Stair', true)
new_comp_def = Sketchup.active_model.definitions.add("Stair") # Create new component
entities = new_comp_def.entities
@numrise = 5
@rise = 7.25
@run = 10
@width = 42
rise2 = @rise
run2 = @run
points = [
Geom::Point3d.new(0, 0, 0),
Geom::Point3d.new(0, 0, @rise),
Geom::Point3d.new(@run, 0, @rise),
for r in 1..@numrise-1 do
Geom::Point3d.new(run2, 0, rise2+@rise),
Geom::Point3d.new(run2+@run, 0, rise2+@rise),
rise2 = rise2 + @rise
run2 = run2 + @run
end
Geom::Point3d.new(run2*@numrise, 0, 0)
]
face = entities.add_face(points)
face.reverse! if face.normal.z < 0 # Reverse normal
face.pushpull(@width)
tr = Geom::Transformation.new # Empty transformation
cube = Sketchup.active_model.active_entities.add_instance(new_comp_def, tr) # Place stringer
model.commit_operation
end
self.create_stair