The program draws the stairs according to the values given. Program Creates a Web dialog with appropriate definitions. User enters the values through WebDialog for variable called the stairs. Ruby code defines a loop and form a group of surfaces. The loop creates the surface along of each rounds.The surface is moved by x and z axes for each loop round.
require 'sketchup.rb'
wd=UI::WebDialog.new("Spiral Staircase Drawing", false, "Info",200, 500, 200, 500, true )
wd.set_file( "C:/Program Files/SketchUp/SketchUp 2017/Tools/Stairs.html" )
wd.show()
wd.add_action_callback("getUserInput1"){|action_context, user_input1|
wd.add_action_callback("getUserInput2"){|action_context, user_input2|
number_stairs = user_input1.to_i
width = user_input2.to_i
model = Sketchup.active_model
entities = model.active_entities
stairs = number_stairs
model = Sketchup.active_model
entities = model.active_entities
for x in (0..stairs).step(4)
group = entities.add_group
stairentities = group.entities
face = stairentities.add_face [0,x,x],[x+90,x,x],[x+90,x+20,x],[0,x+10,x]
tr = Geom::Transformation.rotation([0,0,0],[0,0,1],x.degrees)
Sketchup.active_model.active_entities.transform_entities(tr,face)
face.material = "gray"
face.pushpull(width)
end
wd.execute_script("dataFromSketchup('#{number_stairs}')")
wd.execute_script("document.write('Spiral stairs ready.')")
wd.execute_script("alert('Stairs Ready.')");
}
}
<!DOCTYPE html>
<html>
<head>
<title>Draw Stairs
</title>
</head>
<center><h1>Spiral Staircase App</h1>
<script>
function sendDataToSketchUp() {
var user_input1 = formid.ddlselect[formid.ddlselect.selectedIndex]
var user_input2 = document.getElementById('id2');
query = 'skp:getUserInput1@' + user_input1.value
window.location.href = query;
query = 'skp:getUserInput2@' + user_input2.value
window.location.href = query;
}
</script>
<body>
<script>
function dataFromSketchUp() {
}
</script>
</body>
<center><p>Stairs Drawing App</p>
<form>
<br>
<center>Step Height: <br><br> <input id='id2' type='number' name='breadth' value=0 required>
<br>
<br>
</form>
<form name="formid">
<select name="ddlselect" onchange="myFunction()">
<option value="50">13 Steps</option>
<option value=40>11 Steps</option>
<option value=30>8 Steps</option>
<option value=20>6 Steps</option> </select>
</form>
<label id="country"></label>
<br>
<center> <button onclick='sendDataToSketchUp()'>Spiral Staircase</button>
</body>
</html>