require 'sketchup.rb'
module PPP
def FFFFF
# variables to control the maximum step height and depth
max_step_height = 8
max_step_depth = 12
step_width = 36
p1 = Geom::Point3d.new(0, 0, 0)
p2 = Geom::Point3d.new(100, 0, 100)
h = (p2 - p1).z
puts "height = #{h}"
p3 = Geom::Point3d.new(p2.x, p2.y, p1.z)
v2 = p3 - p1
l = v2.length
puts "length = #{l}"
n1 = (h / max_step_height).to_i
puts "n1 = #{n1}"
n2 = (l / max_step_depth).to_i
puts "n2 = #{n2}"
numSteps = [n1, n2].max
puts "numSteps = #{numSteps}"
v1 = Geom::Vector3d.new 0, 0, (h/numSteps)
v2.length = l/numSteps
v3 = v1 * v2
v3.length = step_width
model = Sketchup.active_model
entities = model.entities
edges = []
model.start_operation "FFFFF"
pt1 = p1
for i in 1..numSteps
# create the front of the step
pt2 = pt1 + v1
pt3 = pt2 + v3
pt4 = pt1 + v3
edges[0] = entities.add_line(pt1, pt2)
edges[1] = entities.add_line(pt2, pt3)
edges[2] = entities.add_line(pt3, pt4)
edges[3] = entities.add_line(pt4, pt1)
entities.add_face edges
# now make the top
pt1 = pt2
pt4 = pt3
pt2 = pt1 + v2
pt3 = pt4 + v2
edges[3] = edges[1]
edges[0] = entities.add_line(pt1, pt2)
edges[1] = entities.add_line(pt2, pt3)
edges[2] = entities.add_line(pt3, pt4)
entities.add_face edges
# move to the next step
pt1 = pt2
end
model.commit_operation
end
end
UI.menu("Draw").add_item("楼梯") {PPP.FFFFF}
|