my menu file
require 'sketchup'
# require 'extensions'
# require 'Icosahedron'
require_relative 'Icosahedron'
#require_relative 'Test'
module BHL
module Polyhedrons
def self.create_icosahedron
if not @frequency
@frequency = 1
end
prompts = ["Frequency"]
values = [@frequency]
list = ["1|2|3|4|5|6", @frequency]
results = UI.inputbox(prompts, values, list, "Frequency")
return if not results
@frequency = results[0]
if @frequency == 1
icosahedron_CIV1
elsif @frequency == 2
icosahedron_CIV2
elsif @frequency == 3
icosahedron_CIV3
end
end # self.create_icosahedron
def self.octahedron
UI.messagebox "Octa coming later"
end # self.create_octahedron
unless file_loaded?(__FILE__)
menu_Poly = UI.menu('Extensions').add_submenu('Polyhedrons')
menu_Icosa = menu_Poly.add_submenu('Icosahedron')
menu_Icosa.add_item('Icosa Class I') {self.create_icosahedron}
menu_Poly.add_item('Octahedron') {self.octahedron}
# menu_Poly.add_separator
# menu_Poly = UI.menu('Extensions').add_submenu('Test')
# menu_Poly.add_item('Test Output Box') {self.test_output}
file_loaded(__FILE__)
end # unless file_loaded?(__FILE__)
end # module Polyhedrons
end # module BHL
worker file
module BHL
module Polyhedrons
def get_icosa_vtxs(radius)
# phi = (Math::sqrt(5) + 1) / 2
# atanPhi = Math::atan(Phi)
pi = Math::PI
atan_2 = Math::atan(2)
vtx_X_1 = radius * Math::sin(atan_2) * Math::sin(0.4 * pi) # e
vtx_X_2 = radius * Math::sin(atan_2 / 2) # s
vtx_Y_1 = radius * Math::sin(atan_2) # b
vtx_Y_2 = radius * Math::sin(atan_2) * Math::cos(0.4 * pi) # f
vtx_Y_3 = radius * Math::sin(atan_2) * Math::sin(0.3 * pi) # c
vtx_Z_1 = radius * Math::sin(atan_2) / (2 * Math::sin(0.3 * pi)) # d
arr_Vtxs = Array.new(12)
arr_Vtxs[ 0] = Geom::Point3d.new( 0.0, 0.0, radius.m) # 0, 0, r
arr_Vtxs[ 1] = Geom::Point3d.new( 0.0, - vtx_Y_1.m, (1 - vtx_Z_1).m) # 0, -b, r - d
arr_Vtxs[ 2] = Geom::Point3d.new( vtx_X_1.m, - vtx_Y_2.m, (1 - vtx_Z_1).m) # e, -f, r - d
arr_Vtxs[ 3] = Geom::Point3d.new( vtx_X_2.m, vtx_Y_3.m, (1 - vtx_Z_1).m) # s, c, r - d
arr_Vtxs[ 4] = Geom::Point3d.new( - vtx_X_2.m, vtx_Y_3.m, (1 - vtx_Z_1).m) # -s, c, r - d
arr_Vtxs[ 5] = Geom::Point3d.new( - vtx_X_1.m, - vtx_Y_2.m, (1 - vtx_Z_1).m) # -e, -f, r - d
arr_Vtxs[ 6] = Geom::Point3d.new( vtx_X_2.m, - vtx_Y_3.m, (vtx_Z_1 - 1).m) # s, c, d - r
arr_Vtxs[ 7] = Geom::Point3d.new( vtx_X_1.m, vtx_Y_2.m, (vtx_Z_1 - 1).m) # e, f, d - r
arr_Vtxs[ 8] = Geom::Point3d.new( 0.0, vtx_Y_1.m, (vtx_Z_1 - 1).m) # 0, b, d - r
arr_Vtxs[ 9] = Geom::Point3d.new( - vtx_X_1.m, vtx_Y_2.m, (vtx_Z_1 - 1).m) # -e, f, d - r
arr_Vtxs[10] = Geom::Point3d.new( - vtx_X_2.m, - vtx_Y_3.m, (vtx_Z_1 - 1).m) # -s, -c, d - r
arr_Vtxs[11] = Geom::Point3d.new( 0.0, 0.0, - radius.m) # 0, 0, -r
arr_Vtxs
end # get_icosa_vtxs(radius)
def icosahedron_CIV1
# This method creates an icosahedron within a component in the model.
arr_Face_Map = [[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 1, 5],
[1, 2, 6], [2, 6, 7], [2, 3, 7], [3, 7, 8], [3, 4, 8],
[4, 8, 9], [4, 5, 9], [5, 9, 10], [1, 5, 10], [1, 6, 10],
[6, 7, 11], [7, 8, 11], [8, 9, 11], [9, 10, 11], [6, 10, 11]]
radius = 1.0
arr_Icosa_Vtxs = get_icosa_vtxs(radius)
Sketchup.file_new
model = Sketchup.active_model
model.start_operation('Create Icosahedron', true)
component = model.definitions.add
component.name = "Icosahedron"
entities = component.entities
# add faces
arr_Face_Map.each do |face|
component.entities.add_face(arr_Icosa_Vtxs[face[0]], arr_Icosa_Vtxs[face[1]], arr_Icosa_Vtxs[face[2]])
end
transform = Geom::Transformation.new([0, 0, 0]) # an empty, default transformation.
model.active_entities.add_instance(component, transform)
model.commit_operation
end # icosahedron_CIV1
def icosahedron_CIV2
UI.messagebox "Icosa V2 + coming later"
end # icosahedron_CIV2
def icosahedron_CIV3
UI.messagebox "Icosa V3 + coming later"
end # icosahedron_CIV3
end # module Polyhedrons
end # module BHL