# Copyright 2004, Rick Wilson # Permission to use, copy, modify, and distribute this software for # any purpose and without fee is hereby granted, provided that the above # copyright notice appear in all copies. # THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR # IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. # Name : helix.rb 1.0 # Description : Create a helix based on selected circle. # Author : Rick Wilson # Usage : 1. Install into the plugins directory or into the # Plugins/examples directory and manually load from the ruby console "load 'examples/helix.rb'" # 2. Select a face - any face! # 2. Run "Helix" from the Plugins menu. # Date : 29.Jul.2004 # Type : Tool # History: # 1.1 (30.Jul.2004) - added grouping option, fixed bug to draw final segment # 1.0 (29.Jul.2004) - first version # require 'sketchup.rb' def helix model=Sketchup.active_model ss=model.selection.first return nil if ss.class!=Sketchup::Face #Check selection, accept only a face @helix_grouping = "Yes" if not @helix_grouping @helix_height = 12.inch if not @helix_height @helix_turns = 10 if not @helix_turns helix_grouping_options = ["Yes","No"] prompts = ["Group", "Height", "Turns"] #Prompt the user for the Helix settings values = [@helix_grouping, @helix_height, @helix_turns] enums = [helix_grouping_options.join("|")] results = inputbox prompts, values, enums, "Helix Settings" return nil if not results @helix_grouping = results[0] @helix_height = results[1] @helix_turns = results[2].to_i model.start_operation "Helix" eV = ss.vertices eL = eV.length tH = @helix_height / @helix_turns eH = tH / eL pts = [] 0.upto(@helix_turns-1) do |turns| 0.upto(eL-1) do |verts| ht = (eH * verts) + (tH * turns) pos = eV[verts].position pts[pts.length] = [pos[0],pos[1],ht] end end # ADD THE FINAL POINT pts[pts.length] = [eV[0].position[0],eV[0].position[1],@helix_height] if @helix_grouping == "Yes" # DO THIS FOR GROUPING entities = model.active_entities group = entities.add_group entities = group.entities entities.add_curve(pts) else model.entities.add_curve(pts) # DO THIS FOR NON-GROUPING end model.commit_operation end if( not file_loaded?("helix.rb") ) # This will add a separator to the menu, but only once add_separator_to_menu("Plugins") # To add an item to a menu, you identify the menu, and then # provide a title to display and a block to execute. In this case, # the block just calls the create_box function UI.menu("Plugins").add_item("Helix") { helix } end #----------------------------------------------------------------------------- file_loaded("helix.rb")