Hi, TIG. Finally, Its working as I have hoped. This is the corrected code. I needed not use 'group'. The cone shape is created after I deleted the line. Thank you!
require 'sketchup.rb'
class Cone
@@Length = @@angle =@@x=@@y=@@z = nil
def create_cone
@@Length = 100 if not @@Length
@@angle = 30.0 if not @@angle
@@x = 0.mm if not @@x
@@y = 0.mm if not @@y
@@z = 0.mm if not @@z
prompts = ["Radius","Angle", "x", "y", "z"]
values = [@@Length, @@angle, @@x, @@y, @@z]
results = inputbox prompts, values, "Fire sensor"
if results
@@Length, @@angle, @@x, @@y, @@z = results
model = Sketchup.active_model
model.start_operation "Fire sensor"
compdef = Sketchup.active_model.definitions.add
ents = compdef.entities
@Length = @@Length.mm
@angle = (@@angle.degrees)/2
@pt0 = [0,0,0]
@pt1 = [0, 0, -@Length]
@pt2=@pt1.transform(Geom;;Transformation.rotation(@pt0,[0,-1,0],@angle))
arcarray = ents.add_arc [0,0,0], [0,0,-1],[0,-1,0], @Length, 0, @angle
arc = arcarray[0]
arccurve = arc.curve
verts = arccurve.vertices
a = ents.add_line @pt0, @pt1
b = ents.add_line @pt0, @pt2
face = ents.add_face @pt0, @pt1, @pt2
path = ents.add_circle [0,0,-@Length], [0,0,1], -@Length
face.followme path
ents.erase_entities path
face2 = ents.add_face verts
path2 = ents.add_circle [0,0,-@Length], [0,0,1], -@Length
face2.followme path2
ents.erase_entities path2
trans = Geom;;Transformation.new([@@x.to_i, @@y.to_i, @@z.to_i])
status=model.place_component(compdef)
Sketchup.active_model.active_entities.add_instance(compdef, trans)
model.commit_operation
end #if
Sketchup.send_action 'selectSelectionTool;'
end #def
end #Class
if( not file_loaded?(__FILE__) )
UI.add_context_menu_handler do |menu|
end
dir=File.dirname(__FILE__)
cmd_array = []
cmd = UI;;Toolbar.new "sphere"
# Create the Command object
cmd = UI;;Command.new("Cone") {Sketchup.active_model.select_tool Cone.new.create_cone}
# Configure the Command's appearance
cmd.small_icon = cmd.large_icon = dir+"/FGmanual/images/cone.png"#<--
cmd.tooltip = "Cone"
cmd_array.push(cmd)
tb=UI;;Toolbar.new("Creating tools")
cmd_array.each {|i| tb.add_item(i)}
tb.show if tb.get_last_state == -1
end
file_loaded(__FILE__)