# Copyright 2004, David R. German (with generous support from others) # 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 : Cone Tool 1.0 (Beta) # Description : A tool to create cones. # Menu Item : Draw->Cone # Usage : 1. Specify base diameter and height of cone. # : 2. Click in model to select location of cone. (future version) # Date : 8/29/2004 # Type : Tool # ODM added create cone code 8/30/2004 #---------------------------------------------------------------------------- require 'sketchup.rb' #---------------------------------------------------------------------------- def create_cone model = Sketchup.active_model entities = model.active_entities model.start_operation "Create Cone" # Encapsulate a single UNDO operation. prompts = ["Base Diameter ", "Height"] # Define prompts in the input box values = [20.mm, 10.mm] # default values in the input box results = inputbox prompts, values, "Cone Dimensions" return if not results # This means that the user canceled the operation base, height = results #----------------------------------------------------------------------------- # input specified values for the cone center = [0,0,0] # Center of cone base vector = [0,0,1] # Normal Vector radius = base/2 # Radius of cone base segments = 24 # Default number of segments #----------------------------------------------------------------------------- # Draw circle for base of cone cone_base = entities.add_circle(center, vector, radius, segments) #----------------------------------------------------------------------------- # Find_faces of circle 'cone_base' and call it 'face' face = entities.add_face(cone_base) #----------------------------------------------------------------------------- # create cone vertices = face.vertices cone_height=[0,0,height] face1 = entities.add_face(center,cone_height,vertices[0]) face1.followme cone_base end #----------------------------------------------------------------------------- # Load 'Cone' into 'Draw' menu if( not file_loaded?("cone.rb") ) # This will add a separator to the menu, but only once add_separator_to_menu("Draw") # 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("Draw").add_item("Cone") { create_cone } end #----------------------------------------------------------------------------- file_loaded("cone.rb")