See comments regarding various errors:
` require 'sketchup.rb'
def create_sphere
@radius = 0.feet if not @radius # along Green Y axis
prompts = ["radius", "R", "G", "B"]
values = [@radius, @R, @G, @B]
results = inputbox prompts, values, "Sphere"
return if not results
@radius, @R, @G, @B,= results
model = Sketchup.active_model # why keep switching between model and
Sketchup.active_model?
model.start_operation "Sphere"
compdef = Sketchup.active_model.definitions.add # needed 's'
multiple places show confusion between an Entity and its Entities collection
ents = compdef.entities
center = [0, 0, 0]
radius = @radius
circle = ents.add_circle center, [0, 0, 1], radius
circle_face = ents.add_face circle
assign these right away - the followme will destroy the original circle_face
Color.new needs integers not strings
circle_face.material=Sketchup::Color.new(@R.to_i, @G.to_i, @B.to_i)
circle_face.material.alpha = 0.3
path = ents.add_circle center, [0, 1, 0], radius + 1
circle_face.followme path
ents.erase_entities path
place_component activates the Tool to manually place a
ComponentInstance via GUI
add_instance explicitly places one via Ruby
You probably don't want to do both?
#status=model.place_component(compdef)
need to create trans before you can use it! This creates an identity,
which adds the instance at the model origin
trans=Geom::Transformation.new
Sketchup.active_model.active_entities.add_instance(compdef, trans)
model.commit_operation
end
if( not file_loaded?("Sphere.rb") )
utilities_menu = UI.menu("Plugins").add_submenu("Sphere")
utilities_menu.add_item("Sphere") { create_sphere }
end
#-----------------------------------------------------------------------------
file_loaded("Sphere.rb")`
Also, you should isolate your code in a module so that the method does not go into the global namespace.