Advertisement
Guest User

Untitled

a guest
Jan 9th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 27.19 KB | None | 0 0
  1. require 'Sketchup'
  2. # ------------------  MENU SETUP ---------------------- #
  3. unless $sdm_tools_menu
  4.     $sdm_tools_menu = UI.menu("Plugins").add_submenu("SDM Tools")
  5.     $sdm_Edge_tools = $sdm_tools_menu.add_submenu("Edge Tool")
  6.     $sdm_Face_tools = $sdm_tools_menu.add_submenu("Face Tool")
  7.     $sdm_CorG_tools = $sdm_tools_menu.add_submenu("CorG Tool")
  8.     $sdm_Misc_tools = $sdm_tools_menu.add_submenu("Misc Tool")
  9. end
  10. unless file_loaded?(__FILE__)
  11.     $sdm_Misc_tools.add_item("Stair Maker") { Sketchup.active_model.select_tool SDM::Stair_Maker.new }
  12.     file_loaded(__FILE__)
  13. end
  14. # ------------------------------------------------------ #
  15. module SDM
  16.  
  17.     class Stair_Maker
  18.  
  19.         def initialize
  20.             @ip = Sketchup::InputPoint.new
  21.             @ip1 = Sketchup::InputPoint.new
  22.             @file =  __FILE__.gsub(/.rb$/,'.txt')
  23.             @separator = begin;'1.0'.to_l;'.';rescue;',';end
  24.             @unit=Sketchup.active_model.options["UnitsOptions"]["LengthUnit"]
  25.             if !File.exist?(@file)
  26.                 if @unit< 2
  27.                     @@step_width = 3.feet
  28.                     @@step_tread = 1.feet
  29.                     @@step_riser = 9.inch
  30.                     @@step_count = 12
  31.                     @@step_depth = 2.inch
  32.                     @@step_nturn = 0
  33.                     @@step_trngp = 1.feet
  34.                     @@rail_level = 2.5.feet
  35.                     @@rail_inset = 3.inch
  36.                     @@ss_width_max = 6.feet
  37.                     @@ss_width_min = 4.feet
  38.                     @@stair_hgt = 9.feet
  39.                     @@ss_anginc = 15.0
  40.                 else
  41.                     @@step_width = 1.m
  42.                     @@step_tread = 35.cm
  43.                     @@step_riser = 20.cm
  44.                     @@step_count = 12
  45.                     @@step_depth = 5.cm
  46.                     @@step_nturn = 0
  47.                     @@step_trngp = 35.cm
  48.                     @@rail_level = 90.cm
  49.                     @@rail_inset = 5.cm
  50.                     @@ss_width_max = 2.m
  51.                     @@ss_width_min = 1.m
  52.                     @@stair_hgt = 3.m
  53.                     @@ss_anginc = 15.0
  54.                 end
  55.             end
  56.             self.reset
  57.         end
  58.  
  59.         def reset
  60.             ans=UI.inputbox(["Stair Type:"],["Normal"],["Normal|Spiral|Lshape|Ushape|Ladder"],"Stair Maker 4")
  61.             if !ans then Sketchup.send_action "selectSelectionTool:";return;end
  62.             @stair_type=ans[0]
  63.             case @stair_type
  64.                 when "Normal"
  65.                     self.get_defaults if File.exist?(@file)
  66.                     prompts=["Step Width:","Tread Depth:","Riser Height:","Num of Steps:","Step Depth:","Rail Height:", "Rail Offset:","Height of Stairs:"]
  67.                     defaults=[@@step_width,@@step_tread,@@step_riser,@@step_count,@@step_depth,@@rail_level,@@rail_inset,@@stair_hgt]
  68.                     results=UI.inputbox(prompts,defaults,"Normal Stairs")
  69.                     if !results then; onCancel(nil,nil);return;end
  70.                     @@step_width=results[0].to_l;@@step_tread=results[1].to_l;@@step_riser=results[2].to_l;@@step_count=results[3].to_i
  71.                     @@step_depth=results[4].to_l; @@rail_level=results[5].to_l; @@rail_inset=results[6].to_l;@@stair_hgt=results[7].to_l
  72.                     if @@stair_hgt > 0
  73.                         if @@step_count > 0
  74.                             if @@step_riser != @@stair_hgt/@@step_count
  75.                                 @@step_riser=(@@stair_hgt/@@step_count).to_l
  76.                                 self.reset if UI.messagebox("Riser is now #{@@step_riser}.  Continue?",MB_YESNO)==7
  77.                             end
  78.                         elsif @@step_riser > 0
  79.                             @@step_count=(@@stair_hgt/@@step_riser).floor
  80.                             self.reset if UI.messagebox("Num of steps is now #{@@step_count}.  Continue?",MB_YESNO)==7
  81.                         else
  82.                             UI.messagebox "Enter number of steps or riser hieght"
  83.                             self.reset
  84.                         end
  85.                     end
  86.                     self.put_defaults
  87.                 when "Spiral"
  88.                     self.get_defaults if File.exist?(@file)
  89.                     prompts=["Step Max Width:","Step Min Width:","Riser Height:","Step Depth:","Rail Height:","Rail Offset:","Stair Height:","Num of Steps:","Step AngInc:"]
  90.                     defaults=[@@ss_width_max,@@ss_width_min,@@step_riser,@@step_depth,@@rail_level,@@rail_inset,@@stair_hgt,@@step_count,@@ss_anginc]
  91.                     results=UI.inputbox(prompts,defaults,"Spiral Stairs")
  92.                     if !results then; onCancel(nil,nil);return;end
  93.                     @@ss_width_max=results[0].to_l; @@ss_width_min=results[1].to_l;@@step_riser = results[2].to_l;
  94.                     @@step_depth= results[3].to_l;@@rail_level=results[4].to_l; @@rail_inset=results[5].to_l;
  95.                     @@stair_hgt = results[6].to_l; @@step_count = results[7].to_i;  @@ss_anginc = results[8].to_f
  96.                     if @@step_count > 0
  97.                         if @@stair_hgt > 0.0
  98.                             if @@step_riser != @@stair_hgt/@@step_count
  99.                                 @@step_riser=(@@stair_hgt/@@step_count).to_l
  100.                                 self.reset if UI.messagebox("Riser is now #{@@step_riser}.  Continue?",MB_YESNO)==7
  101.                             end
  102.                         else
  103.                             @@stair_hgt = (@@step_riser * @@step_count).to_l
  104.                             self.reset if UI.messagebox("Height is now #{@@stair_hgt}.  Continue?",MB_YESNO)==7
  105.                         end
  106.                     end
  107.                     self.put_defaults
  108.                 when "Lshape"
  109.                     ans=UI.inputbox(["Type:"],["Open"],["Open|In-Situ"],"Type of construction")
  110.                     if !ans then; onCancel(nil,nil);return;end
  111.                     @design=ans[0]
  112.                     self.get_defaults if File.exist?(@file)
  113.                     if @design == "Open"
  114.                         prompts=["Step Width:","Tread Depth:","Riser Height:","Risers2Landing:", \
  115.                         "Step Depth:","Rail Height:","Rail Offset:","Landing Height:"]
  116.                         defaults=[@@step_width,@@step_tread,@@step_riser,@@step_count,@@step_depth,@@rail_level,@@rail_inset,@@stair_hgt]
  117.                         results=UI.inputbox(prompts,defaults,"L-Shaped Open Stairs")
  118.                         if !results then self.reset end
  119.                         @@step_width=results[0].to_l; @@step_tread=results[1].to_l; @@step_riser=results[2].to_l;
  120.                         @@step_count=results[3].to_i; @@step_nturn=0; @@step_depth=results[4].to_l;
  121.                         @@rail_level=results[5].to_l; @@rail_inset=results[6].to_l;@@stair_hgt=results[7].to_l
  122.                         @Step_Name="Step"+@@step_width.to_i.to_s+@@step_tread.to_i.to_s+@@step_depth.to_i.to_s
  123.                         make_step_comp
  124.                     else
  125.                         prompts=["Step Width:","Tread Depth:","Riser Height:","Risers2Landing:","Rail Height:","Rail Offset:","Landing Height:"]
  126.                         defaults=[@@step_width,@@step_tread,@@step_riser,@@step_count,@@rail_level,@@rail_inset,@@stair_hgt]
  127.                         results=UI.inputbox(prompts,defaults,"L-Shaped In-Situ Stairs")
  128.                         if !results then self.reset end
  129.                         @@step_width=results[0].to_l;@@step_tread=results[1].to_l;@@step_riser=results[2].to_l
  130.                         @@step_count=results[3].to_i;  @@step_nturn=0;
  131.                         @@rail_level=results[4].to_l; @@rail_inset=results[5].to_l;@@stair_hgt=results[6].to_l
  132.                     end
  133.                     if @@stair_hgt > 0
  134.                         if @@step_count > 0
  135.                             if @@step_riser != @@stair_hgt/@@step_count
  136.                                 @@step_riser=(@@stair_hgt/@@step_count).to_l
  137.                                 self.reset if UI.messagebox("Riser is now #{@@step_riser}.  Continue?",MB_YESNO)==7
  138.                             end
  139.                         elsif @@step_riser > 0
  140.                             @@step_count=(@@stair_hgt/@@step_riser/2.0).floor
  141.                             self.reset if UI.messagebox("Num of steps is now #{@@step_count}.  Continue?",MB_YESNO)==7
  142.                         else
  143.                             UI.messagebox "Enter number of steps or riser height"
  144.                             self.reset
  145.                         end
  146.                     end
  147.                     self.put_defaults
  148.                 when "Ushape"
  149.                     ans=UI.inputbox(["Type:"],["Open"],["Open|In-Situ"],"Type of construction")
  150.                     if !ans then; onCancel(nil,nil);return;end
  151.                     @design=ans[0]
  152.                     self.get_defaults if File.exist?(@file)
  153.                     if @design == "Open"
  154.                         prompts=["Step Width:","Tread Depth:","Riser Height:","Risers2Landing:","Steps in Turn:","Gap Run2Run:", \
  155.                         "Step Depth:","Rail Height:","Rail Offset:","Landing Height:"]
  156.                         defaults=[@@step_width,@@step_tread,@@step_riser,@@step_count,@@step_nturn,@@step_trngp,@@step_depth,@@rail_level,@@rail_inset,@@stair_hgt]
  157.                         results=UI.inputbox(prompts,defaults,"U-Shaped Open Stairs")
  158.                         if !results then self.reset end
  159.                         @@step_width=results[0].to_l;@@step_tread=results[1].to_l;@@step_riser=results[2].to_l;
  160.                         @@step_count=results[3].to_i; @@step_nturn=results[4].to_i; @@step_trngp=results[5].to_l
  161.                         @@step_depth=results[6].to_l; @@rail_level=results[7].to_l; @@rail_inset=results[8].to_l;@@stair_hgt=results[9].to_l
  162.                         @Step_Name="Step"+@@step_width.to_i.to_s+@@step_tread.to_i.to_s+@@step_depth.to_i.to_s
  163.                         make_step_comp
  164.                     else
  165.                         prompts=["Step Width:","Tread Depth:","Riser Height:","Risers2Landing:","Gap Run2Run:","Rail Height:","Rail Offset:","Landing Height:"]
  166.                         defaults=[@@step_width,@@step_tread,@@step_riser,@@step_count,@@step_trngp,@@rail_level,@@rail_inset,@@stair_hgt]
  167.                         results=UI.inputbox(prompts,defaults,"U-Shaped In-Situ Stairs")
  168.                         if !results then self.reset end
  169.                         @@step_width=results[0].to_l;@@step_tread=results[1].to_l;@@step_riser=results[2].to_l
  170.                         @@step_count=results[3].to_i;  @@step_trngp=results[4].to_l;@@step_nturn=0;
  171.                         @@rail_level=results[5].to_l; @@rail_inset=results[6].to_l;@@stair_hgt=results[7].to_l
  172.                     end
  173.                     if @@stair_hgt > 0
  174.                         if @@step_count > 0
  175.                             if @@step_riser != @@stair_hgt/@@step_count
  176.                                 @@step_riser=(@@stair_hgt/@@step_count).to_l
  177.                                 self.reset if UI.messagebox("Riser is now #{@@step_riser}.  Continue?",MB_YESNO)==7
  178.                             end
  179.                         elsif @@step_riser > 0
  180.                             @@step_count=(@@stair_hgt/@@step_riser/2.0).floor
  181.                             self.reset if UI.messagebox("Num of steps is now #{@@step_count}.  Continue?",MB_YESNO)==7
  182.                         else
  183.                             UI.messagebox "Enter number of steps or riser height"
  184.                             self.reset
  185.                         end
  186.                     end
  187.                     self.put_defaults
  188.                 else
  189.                     self.get_defaults if File.exist?(@file)
  190.                     prompts=["Ladder Rail Type:","Ladder Height:","Ladder Width:","Rung2Rung:","Wall Offset:"]
  191.                     defaults=["Tube",@@stair_hgt,@@step_width,@@step_riser,@@rail_inset]
  192.                     results=UI.inputbox(prompts,defaults,["Tube|Rect|Line"],"Wall Ladder")
  193.                     if !results then;onCancel(nil,nil);end
  194.                     @ladder_type=results[0].to_s;@@stair_hgt=results[1];@@step_width=results[2]
  195.                     @@step_riser=results[3];@@rail_inset=results[4]
  196.                     self.put_defaults
  197.                     if @ladder_type == "Tube"
  198.                         ans=UI.inputbox(["Rail Diameter:","Rung Diameter:"],[1.5.inch,1.0.inch],"Tube rail Ladder Specs")
  199.                         if !ans then;return;end
  200.                         rail_dia=ans[0].to_l;@rail_rad=rail_dia/2;rung_dia=ans[1].to_l;@rung_rad=rung_dia/2
  201.                     elsif @ladder_type == "Rect"
  202.                         ans=UI.inputbox(["Rail Dimensions","Rung Dimensions"],['5",1"','4",1"'],"Rect rail Ladder Specs")
  203.                         if !ans then;return;end
  204.                         rail,rung=ans;w,d=rail.split(",");@rail_wid=w.to_l/2;@rail_dep=d.to_l/2
  205.                         w,d=rung.split(",");@rung_wid=w.to_l/2;@rung_dep=d.to_l/2
  206.                     else
  207.                         #centerlines only
  208.                     end
  209.             end
  210.         end
  211.  
  212.         def onMouseMove(flags, x, y, view)
  213.             self.set_current_point(x, y, view)
  214.             view.invalidate if @drawn
  215.         end
  216.        
  217.         def set_current_point(x, y, view)
  218.             if( !@ip.pick(view, x, y, @ip1) )
  219.                 return false
  220.             end
  221.             @ip1.copy! @ip
  222.             @ip0 = @ip.position
  223.             view.tooltip = @ip.tooltip    
  224.             Sketchup::set_status_text("Select location for #{@stair_type} stairs or Right Click to change stair type.  ESC to exit", SB_PROMPT)
  225.             Sketchup::set_status_text("Current XYZ=", SB_VCB_LABEL)
  226.             Sketchup::set_status_text("#{@ip0.x.to_l},#{@ip0.y.to_l},#{@ip0.z.to_l}", SB_VCB_VALUE)
  227.             view.invalidate
  228.         end
  229.        
  230.         def onLButtonDown(flags, x, y, view)
  231.             case @stair_type
  232.                 when "Normal" ; self.straight_run(@ip.position)
  233.                 when "Spiral" ; self.spiral_stair(@ip.position)
  234.                 when "Lshape" ; self.lshape_stair(@ip.position)
  235.                 when "Ushape" ; self.ushape_stair(@ip.position)
  236.                 when "Ladder" ; self.ladder(@ip.position)
  237.             end
  238.         end
  239.  
  240.         def draw(view)
  241.             @drawn = false
  242.             # Show the current input point
  243.             if( @ip.valid? && @ip.display? )
  244.                 @ip.draw(view)
  245.                 @drawn = true
  246.             end
  247.             view.draw_points @ip.position,10,3,'red'
  248.         end
  249.        
  250.         def onCancel(flag, view)
  251.             view.invalidate if @drawn
  252.             Sketchup.send_action "selectSelectionTool:"
  253.         end
  254.  
  255.         def onRButtonDown(flags,x,y,view)
  256.             self.reset
  257.         end
  258.        
  259.         def get_defaults
  260.                 f = File.open(@file, "r"); results = f.readlines; f.close
  261.                 @@step_width = results[0].strip.to_l
  262.                 @@step_tread = results[1].strip.to_l
  263.                 @@step_riser = results[2].strip.to_l
  264.                 @@step_count = results[3].strip.to_i
  265.                 @@step_depth = results[4].strip.to_l
  266.                 @@step_nturn = results[5].to_i
  267.                 @@step_trngp = results[6].strip.to_l
  268.                 @@rail_level = results[7].strip.to_l
  269.                 @@rail_inset = results[8].strip.to_l
  270.                 @@ss_width_max = results[9].strip.to_l
  271.                 @@ss_width_min = results[10].strip.to_l
  272.                 @@stair_hgt = results[11].strip.to_l
  273.                 @@ss_anginc = results[12].to_f
  274.         end
  275.        
  276.         def put_defaults
  277.                 results=[]
  278.                 results[0]=@@step_width.to_s; results[0].gsub!('.',',') if @separator==','
  279.                 results[1]=@@step_tread.to_s; results[1].gsub!('.',',') if @separator==','
  280.                 results[2]=@@step_riser.to_l.to_s; results[2].gsub!('.',',') if @separator==','
  281.                 results[3]=@@step_count
  282.                 results[4]=@@step_depth.to_s; results[4].gsub!('.',',') if @separator==','
  283.                 results[5]=@@step_nturn
  284.                 results[6]=@@step_trngp.to_s; results[6].gsub!('.',',') if @separator==','
  285.                 results[7]=@@rail_level.to_s; results[7].gsub!('.',',') if @separator==','
  286.                 results[8]=@@rail_inset.to_s; results[8].gsub!('.',',') if @separator==','
  287.                 results[9]=@@ss_width_max.to_s; results[9].gsub!('.',',') if @separator==','
  288.                 results[10]=@@ss_width_min.to_s; results[10].gsub!('.',',') if @separator==','
  289.                 results[11]=@@ss_height.to_s; results[11].gsub!('.',',') if @separator==','
  290.                 results[12]=@@ss_anginc.to_s; results[12].gsub!('.',',') if @separator==','
  291.                 f = File.open(@file, "w"); f.puts results; f.close
  292.         end
  293.     ###############################################################################################################################
  294.        
  295.         def straight_run(origin)
  296.        
  297.             @Step_Name="Step"+@@step_width.to_i.to_s+@@step_tread.to_i.to_s+@@step_depth.to_i.to_s
  298.             p0 = origin; rail_pts=[];pp_dist=@@step_depth;rv_gap=Geom::Vector3d.new(0,0,0.01.inch)
  299.             make_step_comp
  300.             mod=Sketchup.active_model;ent=mod.entities;sel=mod.selection;sel.clear
  301.             mod.start_operation "Straight Run"
  302.             steps=ent.add_group; sents=steps.entities; steps.name="Steps"
  303.             rails=ent.add_group; rents=rails.entities; rails.name="Rails"
  304.             for i in 1..@@step_count
  305.                 p1=p0.offset(Z_AXIS,@@step_riser)
  306.                 tr=Geom::Transformation.axes(p1,X_AXIS,Y_AXIS,Z_AXIS)
  307.                 sents.add_instance @step_comp,tr
  308.                 p0=p1.offset(Y_AXIS,@@step_tread)
  309.                 p5=p1.offset(X_AXIS,@@step_width-@@rail_inset)
  310.                 p6=p5.offset(Z_AXIS,@@rail_level)
  311.                 rents.add_line(p5,p6);rail_pts.push p6+rv_gap;
  312.             end
  313.             p5=p0.offset(X_AXIS,@@step_width-@@rail_inset)
  314.             p6=p5.offset(Z_AXIS,@@rail_level)
  315.             rents.add_line(p5,p6);rail_pts.push p6+rv_gap
  316.             rents.add_curve(rail_pts); #add railing
  317.             # @comp.erase!
  318.             mod.commit_operation
  319.             return
  320.         end
  321.        
  322.     ###############################################################################################################################
  323.  
  324.         def spiral_stair(origin)
  325.        
  326.             mod=Sketchup.active_model; ent=mod.entities; sel=mod.selection; sel.clear
  327.             pp_dist=@@step_depth;p0=p3=origin;rail_pts=[];rv_gap=Geom::Vector3d.new(0,0,0.01.inch)
  328.             xaxis=Geom::Vector3d.new(1,0,0); xaxis.length=@@ss_width_max+3.inch
  329.             yaxis=Geom::Vector3d.new(0,1,0); yaxis.length=@@ss_width_min+3.inch
  330.             mod.start_operation("Spiral Stair")
  331.             steps=ent.add_group; sents=steps.entities; steps.name="Spiral Stairs"
  332.             start_el = @@step_riser; angle = 0; angle_increment=@@ss_anginc
  333.             cosa = Math.cos(angle.degrees); sina = Math.sin(angle.degrees)
  334.             vec = Geom::Vector3d.linear_combination(cosa,xaxis,sina,yaxis)
  335.             start_el.step(@@stair_hgt,@@step_riser) do |el|
  336.                 p1=p0.offset(Z_AXIS,el);angle += @@ss_anginc; angle %= 360.0
  337.                 p2=p1.offset(vec); line=sents.add_line(p1,p2)
  338.                 p5=p2.offset(vec,-@@rail_inset);p6=p5.offset(Z_AXIS,@@rail_level);
  339.                 sents.add_line(p5,p6); rail_pts.push p6+rv_gap; #add railing point
  340.                 cosa = Math.cos(angle.degrees); sina = Math.sin(angle.degrees)
  341.                 vec = Geom::Vector3d.linear_combination(cosa,xaxis,sina,yaxis)
  342.                 p3=p1.offset(vec); face=sents.add_face(p1,p2,p3); face.pushpull -pp_dist
  343.             end
  344.             p5=p3.offset(vec,-@@rail_inset);p6=p5.offset(Z_AXIS,@@rail_level);
  345.             sents.add_line(p5,p6); rail_pts.push p6+rv_gap; #add railing point
  346.             curve=sents.add_curve(rail_pts); #add railing
  347.             p0=origin.offset(Z_AXIS,@@stair_hgt+@@ss_width_max)
  348.             cir=sents.add_circle(p0,Z_AXIS,3.inch,16)
  349.             face=sents.add_face(cir); face.pushpull -(@@stair_hgt+@@ss_width_max)
  350.             mod.commit_operation
  351.         end
  352.        
  353.     ###############################################################################################################################
  354.        
  355.         def lshape_stair(origin)
  356.        
  357.             mod=Sketchup.active_model;ent=mod.entities;sel=mod.selection;sel.clear
  358.             rail_pts=[];rs_pts=[];ls_pts=[];p0=origin;rv_gap=Geom::Vector3d.new(0,0,0.01.inch)
  359.             mod.start_operation "lshape stair"
  360.             steps=ent.add_group; sents=steps.entities
  361.             if @design == "Open"
  362.                 pp_dist = @@step_depth
  363.                 for i in 1..@@step_count
  364.                     p1=p0.offset(Z_AXIS,@@step_riser)
  365.                     tr=Geom::Transformation.axes(p1,X_AXIS,Y_AXIS,Z_AXIS)
  366.                     sents.add_instance @step_comp,tr
  367.                     p0=p1.offset(Y_AXIS,@@step_tread)
  368.                     p5=p1.offset(X_AXIS,@@step_width-@@rail_inset)
  369.                     p6=p5.offset(Z_AXIS,@@rail_level)
  370.                     sents.add_line(p5,p6);rail_pts.push p6+rv_gap;
  371.                 end
  372.                 p5=p0.offset(X_AXIS,@@step_width-@@rail_inset)
  373.                 p6=p5.offset(Z_AXIS,@@rail_level)
  374.                 sents.add_line(p5,p6);rail_pts.push p6+rv_gap;
  375.                 p5=p1.offset(Y_AXIS,@@step_tread)
  376.                 p3=p5.offset(X_AXIS,@@step_width)
  377.             else
  378.                 pp_dist=@@step_riser
  379.                 for i in 1..@@step_count
  380.                     p1=p0.offset(Z_AXIS,@@step_riser)
  381.                     p2=p1.offset(X_AXIS,@@step_width)
  382.                     p3=p0.offset(X_AXIS,@@step_width)
  383.                     face=sents.add_face(p0,p1,p2,p3);face.reverse! if i==1
  384.                     p3=p2.offset(Y_AXIS,@@step_tread)
  385.                     p4=p1.offset(Y_AXIS,@@step_tread)
  386.                     face=sents.add_face(p1,p2,p3,p4);
  387.                     p5=p2.offset(X_AXIS,-@@rail_inset)
  388.                     p6=p5.offset(Z_AXIS,@@rail_level)
  389.                     sents.add_line(p5,p6);rail_pts.push p6+rv_gap;
  390.                     ls_pts.push p0; ls_pts.push p1;  p0=p4
  391.                 end
  392.                 p5=p3.offset(X_AXIS,-@@rail_inset)
  393.                 p6=p5.offset(Z_AXIS,@@rail_level)
  394.                 sents.add_line(p5,p6);rail_pts.push p6+rv_gap;p5=p4
  395.                 p6=p4.offset(Z_AXIS,-@@step_riser);
  396.                 ls_pts.push p4;ls_pts.push p6;
  397.                 p7=p6.offset(Z_AXIS,-@@step_riser*(@@step_count-1)).offset(Y_AXIS,-@@step_tread*(@@step_count-1))
  398.                 ls_pts.push p7;
  399.                 for i in 0...ls_pts.length
  400.                     rs_pts[i]=ls_pts[i].offset(X_AXIS,@@step_width)
  401.                 end
  402.             end
  403.             rp_cnt = rail_pts.length;
  404.             xgap=0.0;zcpy=p1.z;zgap=0
  405.             scpy = steps.parent.entities.add_instance(steps.entities.parent, steps.transformation)
  406.             scpyents=scpy.entities
  407.             if @design !="Open"
  408.                 left_face = sents.add_face(ls_pts)
  409.                 right_face = sents.add_face(rs_pts)
  410.                 sents.add_face(rs_pts[0],ls_pts[0],ls_pts[-1],rs_pts[-1])
  411.                 sents.add_face(rs_pts[-1],ls_pts[-1],ls_pts[-2],rs_pts[-2])
  412.                 sents.add_face(rs_pts[-2],ls_pts[-2],ls_pts[-3],rs_pts[-3])
  413.                 ls_pts.push ls_pts[0].offset(Z_AXIS,-@@step_riser)
  414.                 rs_pts.push rs_pts[0].offset(Z_AXIS,-@@step_riser)
  415.                 scpyents.add_face(ls_pts)
  416.                 scpyents.add_face(rs_pts)
  417.                 scpyents.add_face(rs_pts[-1],ls_pts[-1],ls_pts[-3],rs_pts[-3])
  418.                 scpyents.add_face(rs_pts[-4],ls_pts[-4],ls_pts[-3],rs_pts[-3])
  419.             end
  420.             p1=p5
  421.             p2=p1.offset(Y_AXIS,@@step_width)
  422.             p3=p2.offset(X_AXIS,@@step_width+xgap)
  423.             p4=p1.offset(X_AXIS,@@step_width+xgap)
  424.             face=sents.add_face(p1,p2,p3,p4)
  425.             face.pushpull pp_dist if face
  426.             trn=Geom::Transformation.new(p3-origin)
  427.             scpy.transform! trn
  428.             trr=Geom::Transformation.rotation(scpy.bounds.corner(0),Z_AXIS,-90.degrees)
  429.             scpy.transform! trr;   
  430.             for i in 0...rp_cnt
  431.                 rp = rail_pts[i].transform(trn)
  432.                 rail_pts.push rp.transform(trr)
  433.             end
  434.             sents.add_curve(rail_pts);#add top railing
  435.             dump=steps.explode;dump.each{|e| sel.add e if e.is_a?(Sketchup::Edge)||e.is_a?(Sketchup::Face)||e.is_a?(Sketchup::ComponentInstance)}
  436.             dump=scpy.explode;dump.each{|e| sel.add e if e.is_a?(Sketchup::Edge)||e.is_a?(Sketchup::Face)||e.is_a?(Sketchup::ComponentInstance)}
  437.             grp=ent.add_group sel; grp.name="L-Shaped Stairs"; sel.clear;
  438.             mod.commit_operation
  439.        
  440.         end
  441.        
  442.     ###############################################################################################################################
  443.  
  444.         def ushape_stair(origin)
  445.        
  446.             mod=Sketchup.active_model;ent=mod.entities;sel=mod.selection;sel.clear
  447.             rail_pts=[];rs_pts=[];ls_pts=[];p0=origin;rv_gap=Geom::Vector3d.new(0,0,0.01.inch)
  448.             mod.start_operation "ushape stair"
  449.             steps=ent.add_group; sents=steps.entities
  450.             if @design == "Open"
  451.                 pp_dist = @@step_depth
  452.                 for i in 1..@@step_count
  453.                     p1=p0.offset(Z_AXIS,@@step_riser)
  454.                     tr=Geom::Transformation.axes(p1,X_AXIS,Y_AXIS,Z_AXIS)
  455.                     sents.add_instance @step_comp,tr
  456.                     p0=p1.offset(Y_AXIS,@@step_tread)
  457.                     p5=p1.offset(X_AXIS,@@step_width-@@rail_inset)
  458.                     p6=p5.offset(Z_AXIS,@@rail_level)
  459.                     sents.add_line(p5,p6);rail_pts.push p6+rv_gap;
  460.                 end
  461.                 p5=p0.offset(X_AXIS,@@step_width-@@rail_inset)
  462.                 p6=p5.offset(Z_AXIS,@@rail_level)
  463.                 sents.add_line(p5,p6);rail_pts.push p6+rv_gap;
  464.                 p5=p1.offset(Y_AXIS,@@step_tread)
  465.                 p3=p5.offset(X_AXIS,@@step_width)
  466.             else
  467.                 pp_dist=@@step_riser
  468.                 for i in 1..@@step_count
  469.                     p1=p0.offset(Z_AXIS,@@step_riser)
  470.                     p2=p1.offset(X_AXIS,@@step_width)
  471.                     p3=p0.offset(X_AXIS,@@step_width)
  472.                     face=sents.add_face(p0,p1,p2,p3);face.reverse! if i==1
  473.                     p3=p2.offset(Y_AXIS,@@step_tread)
  474.                     p4=p1.offset(Y_AXIS,@@step_tread)
  475.                     face=sents.add_face(p1,p2,p3,p4);
  476.                     p5=p2.offset(X_AXIS,-@@rail_inset)
  477.                     p6=p5.offset(Z_AXIS,@@rail_level)
  478.                     sents.add_line(p5,p6);rail_pts.push p6+rv_gap;
  479.                     ls_pts.push p0; ls_pts.push p1;  p0=p4
  480.                 end
  481.                 p5=p3.offset(X_AXIS,-@@rail_inset)
  482.                 p6=p5.offset(Z_AXIS,@@rail_level)
  483.                 sents.add_line(p5,p6);rail_pts.push p6+rv_gap;p5=p4
  484.                 p6=p4.offset(Z_AXIS,-@@step_riser);
  485.                 ls_pts.push p4;ls_pts.push p6;
  486.                 p7=p6.offset(Z_AXIS,-@@step_riser*(@@step_count-1)).offset(Y_AXIS,-@@step_tread*(@@step_count-1))
  487.                 ls_pts.push p7;
  488.                 for i in 0...ls_pts.length
  489.                     rs_pts[i]=ls_pts[i].offset(X_AXIS,@@step_width)
  490.                 end
  491.             end
  492.             rp_cnt = rail_pts.length;
  493.             xgap=@@step_trngp;zcpy=p1.z;zgap=0
  494.             xgap=@@step_tread*@@step_nturn if @@step_nturn > 0
  495.             zgap=@@step_riser*@@step_nturn if @@step_nturn > 0
  496.             trn=Geom::Transformation.new([@@step_width+xgap,0,zcpy+zgap-origin.z])
  497.             scpy = steps.parent.entities.add_instance(steps.entities.parent, steps.transformation)
  498.             scpyents=scpy.entities
  499.             if @design !="Open"
  500.                 left_face = sents.add_face(ls_pts)
  501.                 right_face = sents.add_face(rs_pts)
  502.                 sents.add_face(rs_pts[0],ls_pts[0],ls_pts[-1],rs_pts[-1])
  503.                 sents.add_face(rs_pts[-1],ls_pts[-1],ls_pts[-2],rs_pts[-2])
  504.                 sents.add_face(rs_pts[-2],ls_pts[-2],ls_pts[-3],rs_pts[-3])
  505.                 ls_pts.push ls_pts[0].offset(Z_AXIS,-@@step_riser)
  506.                 rs_pts.push rs_pts[0].offset(Z_AXIS,-@@step_riser)
  507.                 scpyents.add_face(ls_pts)
  508.                 scpyents.add_face(rs_pts)
  509.                 scpyents.add_face(rs_pts[-1],ls_pts[-1],ls_pts[-3],rs_pts[-3])
  510.                 scpyents.add_face(rs_pts[-4],ls_pts[-4],ls_pts[-3],rs_pts[-3])
  511.             end
  512.             scpy.transform! trn
  513.             trr=Geom::Transformation.rotation(scpy.bounds.center,Z_AXIS,180.degrees)
  514.             scpy.transform! trr
  515.             if @@step_nturn == 0
  516.                 p1=p5
  517.                 p2=p1.offset(Y_AXIS,@@step_width)
  518.                 p3=p2.offset(X_AXIS,@@step_width*2.0+xgap)
  519.                 p4=p1.offset(X_AXIS,@@step_width*2.0+xgap)
  520.                 face=sents.add_face(p1,p2,p3,p4)
  521.                 face.pushpull pp_dist if face
  522.             else
  523.                 p1=p5
  524.                 p2=p1.offset(Y_AXIS,@@step_width)
  525.                 p3=p2.offset(X_AXIS,@@step_width)
  526.                 p4=p1.offset(X_AXIS,@@step_width)
  527.                 face=sents.add_face(p1,p2,p3,p4)
  528.                 face.pushpull pp_dist if face
  529.                 for i in 1..@@step_nturn #add turn steps
  530.                     p1=p3.offset(Z_AXIS,@@step_riser)
  531.                     tr=Geom::Transformation.axes(p1,Y_AXIS.reverse,X_AXIS,Z_AXIS)
  532.                     sents.add_instance @step_comp,tr
  533.                     p3=p1.offset(X_AXIS,@@step_tread)
  534.                     p5=p1.offset(Y_AXIS,@@rail_inset-@@step_width)
  535.                     p6=p5.offset(Z_AXIS,@@rail_level)
  536.                     sents.add_line(p5,p6);rail_pts.push p6+rv_gap
  537.                 end
  538.                 p5=p3.offset(Y_AXIS,@@rail_inset-@@step_width)
  539.                 p6=p5.offset(Z_AXIS,@@rail_level)
  540.                 sents.add_line(p5,p6);rail_pts.push p6+rv_gap
  541.                 p2=p3.offset(X_AXIS,@@step_width)
  542.                 p4=p3.offset(Y_AXIS,-@@step_width)
  543.                 p1=p2.offset(Y_AXIS,-@@step_width)
  544.                 face=sents.add_face(p1,p2,p3,p4)
  545.                 face.pushpull -pp_dist if face
  546.             end
  547.             for i in 0...rp_cnt
  548.                 rp = rail_pts[i].transform(trn)
  549.                 rail_pts.push rp.transform(trr)
  550.             end
  551.             sents.add_curve(rail_pts);#add top railing
  552.             dump=steps.explode;dump.each{|e| sel.add e if e.is_a?(Sketchup::Edge)||e.is_a?(Sketchup::Face)||e.is_a?(Sketchup::ComponentInstance)}
  553.             dump=scpy.explode;dump.each{|e| sel.add e if e.is_a?(Sketchup::Edge)||e.is_a?(Sketchup::Face)||e.is_a?(Sketchup::ComponentInstance)}
  554.             grp=ent.add_group sel; grp.name="U-Shaped Stairs"; sel.clear;
  555.             mod.commit_operation
  556.         end
  557.        
  558.     ###############################################################################################################################
  559.  
  560.         def ladder(origin)
  561.             mod=Sketchup.active_model;ent=mod.entities;sel=mod.selection
  562.             mod.start_operation "ladder"; grp=ent.add_group;ge=grp.entities
  563.             push_pull=@@stair_hgt+@@step_riser/2
  564.             if @ladder_type == "Tube"
  565.                 p0=origin.offset(Y_AXIS,-(@@rail_inset+@rail_rad));p1=p0.offset(X_AXIS,@@step_width)
  566.                 cir=ge.add_circle(p0,Z_AXIS,@rail_rad)
  567.                 face=ge.add_face(cir);face.reverse! if face.normal.z < 0;face.pushpull push_pull
  568.                 cir=ge.add_circle(p1,Z_AXIS,@rail_rad)
  569.                 face=ge.add_face(cir);face.reverse! if face.normal.z < 0;face.pushpull push_pull
  570.                 @@step_riser.step(@@stair_hgt,@@step_riser) do |el|
  571.                     p1 = p0.offset(Z_AXIS,el)
  572.                     cir=ge.add_circle(p1,X_AXIS,@rung_rad)
  573.                     face=ge.add_face(cir);face.pushpull @@step_width
  574.                 end
  575.             elsif @ladder_type == "Rect"
  576.                 pt=p0=origin.offset(Y_AXIS,-(@@rail_inset+@rail_wid))
  577.                 p1=p0.offset(X_AXIS,@rail_dep).offset(Y_AXIS,@rail_wid)
  578.                 p2=p0.offset(X_AXIS,@rail_dep).offset(Y_AXIS,-@rail_wid)
  579.                 p3=p0.offset(X_AXIS,-@rail_dep).offset(Y_AXIS,-@rail_wid)
  580.                 p4=p0.offset(X_AXIS,-@rail_dep).offset(Y_AXIS,@rail_wid)
  581.                 face=ge.add_face(p1,p2,p3,p4);face.reverse! if face.normal.z < 0;face.pushpull push_pull
  582.                 vec=[@@step_width,0,0];p1+=vec;p2+=vec;p3+=vec;p4+=vec
  583.                 face=ge.add_face(p1,p2,p3,p4);face.reverse! if face.normal.z < 0;face.pushpull push_pull
  584.                 @@step_riser.step(@@stair_hgt,@@step_riser) do |el|
  585.                     p0 = pt.offset(Z_AXIS,el)
  586.                     p1=p0.offset(Z_AXIS,@rung_dep).offset(Y_AXIS,-@rung_wid)
  587.                     p2=p0.offset(Z_AXIS,@rung_dep).offset(Y_AXIS,@rung_wid)
  588.                     p3=p0.offset(Z_AXIS,-@rung_dep).offset(Y_AXIS,@rung_wid)
  589.                     p4=p0.offset(Z_AXIS,-@rung_dep).offset(Y_AXIS,-@rung_wid)
  590.                     face=ge.add_face(p1,p2,p3,p4);face.reverse! if face.normal.x < 0;face.pushpull @@step_width
  591.                 end
  592.             else
  593.                 p0=origin.offset(Y_AXIS,-@@rail_inset);p1=p0.offset(X_AXIS,@@step_width)
  594.                 pt=p0.offset(Z_AXIS,push_pull);ge.add_line(p0,pt)
  595.                 pt=p1.offset(Z_AXIS,push_pull);ge.add_line(p1,pt)
  596.                 @@step_riser.step(@@stair_hgt,@@step_riser) do |el|
  597.                     p1=p0.offset(Z_AXIS,el);p2=p1.offset(X_AXIS,@@step_width)
  598.                     ge.add_line(p1,p2)
  599.                 end
  600.             end
  601.             mod.commit_operation
  602.         end
  603.     ###############################################################################################################################
  604.  
  605.         def make_step_comp
  606.             mod=Sketchup.active_model;ent=mod.entities;sel=mod.selection
  607.             comp_defs=mod.definitions;@step_comp=nil
  608.             comp_defs.each{|d| @step_comp=d if d.name==@Step_Name}
  609.             if !@step_comp
  610.                 grp=ent.add_group; ge=grp.entities
  611.                 p0 = ORIGIN; p1=p0.offset(Y_AXIS,@@step_tread);p2=p1.offset(X_AXIS,@@step_width);p3=p0.offset(X_AXIS,@@step_width)
  612.                 face=ge.add_face(p0,p1,p2,p3); face.pushpull @@step_depth
  613.                 @comp=grp.to_component;@comp.definition.name=@Step_Name;@comp.hidden=true
  614.                 @step_comp=@comp.definition
  615.             end
  616.         end
  617.        
  618.     end#of class
  619.  
  620. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement