I will message you. please check inbox
Posts
-
RE: Error message : 'reference to deleted Entities'
-
Error message : 'reference to deleted Entities'
Hi,
I have a problem with the error message 'reference to deleted Entities' when i run the code i made.
My work was to indicate my code in another way.
At first, the structure of code was
` toolbar = UI::Toolbar.new "Name"
....
toolbar.showdef Name2
model = Sketchup.active_model
entities = model.active_entities
...
inputbox
...
entities.add_face
....
selection = model.selection
...
end`That is a simple code to make a inputbox. And now, I am trying to make webdialog(Actually, I refered to other posts on this site for making my own codes, Im very thankful to all users here) and the code is shown below
` def Name3
@model = Sketchup.active_model
@entities = @model.active_entities
...
HTML
...
@entities.add_face
...
end
Name3`This is the simplest code to make a webdialog. The result of running both codes above is same. I just tried to change 'inputbox' way to 'webdialog' way. Since I know the structure of both codes very well, it looked like it has no problem. But, I could see the error message and it was started since the line
@entities.add_face
which can be seen above(Error: #'reference to deleted Entities' C:/Users/name/AppData/Roaming/SketchUp/SketchUp 2015/SketchUp/Plugins/practice.rb:112:in `add_face').What Im wondering is the webdialog was run very well for other codes. Only one code isn't working with the error message 'reference to deleted Entities'.
Is there someone who knows the error message? Please help me solve the problem.
-
Strayed coordinates
Hi. I'm facing to an unexpected problem. The problem is simple.
I made a plugin which creates cone shape and it can be placed after inputting coordinates in input box. Here, I inputted (1000.mm, 1000.mm, 1000.mm), but the cone was placed at '991.mm, 991.mm, 991.mm). Why did it happen??
FYI, I used 'class' method and
a = Geom::Transformation.new([@@x.to_i, @@y.to_i, @@z.to_i])
. Is the problem related with what i have coded?
-
RE: Generating coordinates with Ruby
Thank you, sdmitch and TIG. I could partly understand how i have to fix the codes, but not perfect because I showed you code roughly. Maybe, it would be better i show you what i'm doing now. I'm trying to add bezier curve to draw one simple shape. The equation for the quadratic bezier curve represents as shown below
B(t) = (1-t)(1-t)P0+2(1-t)P1+(t)(t)P2
With the equation, I tried to generate coordinates which are from the equation and wanted to use 'For loop'. hmmm It looked like i can make the codes by myself, but didn't work well
ents = Sketchup.active_model.entities Length = 1000 angle = (60)/2 angle2 = (45)/2 pt0 = [0,0,0] pt1 = [Length.mm, 0, 0] aa = 80*0.01 pt2 = pt1.transform(Geom;;Transformation.rotation(pt0,[0,-1,0],angle.degrees)) pt3 = pt1.transform(Geom;;Transformation.rotation(pt0,[0,-1,0],angle2.degrees)) pt4 = [Length.mm*aa, 0, 0] pt5 = pt4.transform(Geom;;Transformation.rotation(pt0,[0,-1,0],angle.degrees)) arcarray = ents.add_arc [0,0,0], [1,0,0],[0,-1,0], Length.mm, 0, angle2.degrees arc = arcarray[0] arccurve = arc.curve verts = arccurve.vertices t1=0 x6 = (1-(t1))*(1-(t1))*pt5.x+2*(1-(t1))*(t1)*pt2.x+(t1)*(t1)*pt3.x y6 = (1-(t1))*(1-(t1))*pt5.y+2*(1-(t1))*(t1)*pt2.y+(t1)*(t1)*pt3.y z6 = (1-(t1))*(1-(t1))*pt5.z+2*(1-(t1))*(t1)*pt2.z+(t1)*(t1)*pt3.z pt6 = Geom;;Point3d.new(x6, y6, z6) t2=0.2 x7 = (1-(t2))*(1-(t2))*pt5.x+2*(1-(t2))*(t2)*pt2.x+(t2)*(t2)*pt3.x y7 = (1-(t2))*(1-(t2))*pt5.y+2*(1-(t2))*(t2)*pt2.y+(t2)*(t2)*pt3.y z7 = (1-(t2))*(1-(t2))*pt5.z+2*(1-(t2))*(t2)*pt2.z+(t2)*(t2)*pt3.z pt7 = Geom;;Point3d.new(x7, y7, z7) t3=0.4 x8 = (1-(t3))*(1-(t3))*pt5.x+2*(1-(t3))*(t3)*pt2.x+(t3)*(t3)*pt3.x y8 = (1-(t3))*(1-(t3))*pt5.y+2*(1-(t3))*(t3)*pt2.y+(t3)*(t3)*pt3.y z8 = (1-(t3))*(1-(t3))*pt5.z+2*(1-(t3))*(t3)*pt2.z+(t3)*(t3)*pt3.z pt8 = Geom;;Point3d.new(x8, y8, z8) t4=0.6 x9 = (1-(t4))*(1-(t4))*pt5.x+2*(1-(t4))*(t4)*pt2.x+(t4)*(t4)*pt3.x y9 = (1-(t4))*(1-(t4))*pt5.y+2*(1-(t4))*(t4)*pt2.y+(t4)*(t4)*pt3.y z9 = (1-(t4))*(1-(t4))*pt5.z+2*(1-(t4))*(t4)*pt2.z+(t4)*(t4)*pt3.z pt9 = Geom;;Point3d.new(x9, y9, z9) t5=0.8 x10 = (1-(t5))*(1-(t5))*pt5.x+2*(1-(t5))*(t5)*pt2.x+(t5)*(t5)*pt3.x y10 = (1-(t5))*(1-(t5))*pt5.y+2*(1-(t5))*(t5)*pt2.y+(t5)*(t5)*pt3.y z10 = (1-(t5))*(1-(t5))*pt5.z+2*(1-(t5))*(t5)*pt2.z+(t5)*(t5)*pt3.z pt10 = Geom;;Point3d.new(x10, y10, z10) t6=1 x11 = (1-(t6))*(1-(t6))*pt5.x+2*(1-(t6))*(t6)*pt2.x+(t6)*(t6)*pt3.x y11 = (1-(t6))*(1-(t6))*pt5.y+2*(1-(t6))*(t6)*pt2.y+(t6)*(t6)*pt3.y z11 = (1-(t6))*(1-(t6))*pt5.z+2*(1-(t6))*(t6)*pt2.z+(t6)*(t6)*pt3.z pt11 = Geom;;Point3d.new(x11, y11, z11) a = ents.add_line pt0, pt1 b = ents.add_line pt0, pt5 c = ents.add_curve pt0, pt6, pt7, pt8, pt9, pt10, pt11, pt1 face = ents.add_face pt6, pt7, pt8, pt9, pt10, pt11, pt1, pt0 path = ents.add_circle [Length,0,0], [-1,0,0], -Length face.followme path ents.erase_entities path face2 = ents.add_face verts path2 = ents.add_circle [Length,0,0], [-1,0,0], -Length face2.followme path2 ents.erase_entities path2 group=ents.add_group ents.to_a
-
Generating coordinates with Ruby
Hi, I'm looking for how to generates coordinate with an equation and connect the coordinates adding line or curve with ruby.
My idea was
ents = Sketchup.active_model.entities pt0 = [a,b,c] pt1 = [d,e,f] pt2 = [g,h,i] for k in 0...20 x = eq*pt0.x + eq*pt1.x + eq*pt2.x y = eq*pt0.y + eq*pt1.y + eq*pt2.y z = eq*pt0.z + eq*pt1.z + eq*pt2.z pt3 = Geom;;Point3d.new(x, y, z) end ents.add_line pt3
pt0, pt1, pt2 are basic coordinates. 'eq' means random equation. We can add any equation with a variable 'k'
I know there are some errors, but don't know how to fix it. I wish 21 different coordinates are generated from the 'for loop' and they connect each other to draw a line. Can you help me?
-
RE: Code correction
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__)
-
RE: Code correction
Thanks you for a kind comment, TIG, but it's not still working now. There is no problem until adding numbers in the inputbox. The problem is nothing shows up after clicking 'ok'.
-
RE: Code correction
Thanks you, slbaumgartner. Now its working well
However, this is the first step for drawing cone. The main goal is to draw cone freely.
I'm trying to add inputbox with the corrected code you gave, and have already made codes that can draw various shape with inputbox, but it didn't work again. In my view, there is no problem. Could you please look over it again?require 'sketchup.rb' class Cone @@Length = @@angle = nil def create_cone @@Length = 0.mm if not @@Length @@angle = 0.degrees if not @@angle prompts = ["Radius","Angle"] values = [@@Length, @@angle] results = inputbox prompts, values, "Fire sensor" if results @@Length, @@angle = results model = Sketchup.active_model model.start_operation "Fire sensor" compdef = Sketchup.active_model.definition.add ents = compdef.entities @Length = @@Length @angle = (@@angle)/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 group=ents.add_group ents.to_a trans = Geom;;Transformation.new 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__)
-
Code correction
Hello, I'm practicing making code by myself and got stuck on error. I can connect arc with a line from 0,0,0. but can't add one more line that connects between 0,0,0 and the other side of arc. I wish one icecream cone shape will show up after executing codes.
ents = Sketchup.active_model.entities pt0 = [0,0,0] pt1 = [0, 0, -5.cm] pt2=pt1.transform(Geom::Transformation.rotation(pt0,[0,0,1],30.degrees)) arc = ents.add_arc [0,0,0], [0,0,-1],[0,-1,0], 5.cm, 0, 30.degrees g=ents.add_group() ge=g.entities ge.add_cpoint(pt0) ge.add_cpoint(pt1) ge.add_cpoint(pt2) ents.add_line pt0, pt1 ents.add_line pt0, pt2 face = ents.add_face pt0, pt1, pt2 path = ents.add_circle [0,0,-5.cm], [0,0,1], -5.cm face.followme path ents.erase_entities path
-
RE: Correction of codes
Thanks, sdmitch and slbaumgartner. Now It works well
However, I'm planning to create some shapes more with this way and actually made few shapes. I'm worrying about increase of icons in Sketchup, and am making ideas how to simplify tools.
-
Making dialog box
I saw some free tools which 'inputbox' is added together. If the shapes can be individually selected in inputbox, I need not add icons anymore, but don't know how to make it. I know basic codes for creating inputbox, and would like to apply the basic code to what I want(choosing each shapes individually in inputbox). Additionally, Is it possible to add shapes which are saved in .skp file(I know how to load shapes saved in .skp file by using 'Class' method and how to place it on Sketchup space clicking) into inputbox too? -
Using webdialog
If i create webdialog box and add all icons into the webdialog by making tables(categorization), This way may look good as well. I'm trying to use
dlg.add_action_callback("") {|d, p|Sketchup.send_action ""}
Can i utilize this command for making icons in webdialog? I mean, the command looked like only basic tools(Undo, Redo, New, Cut, PushPull) can be used with the command. For example
dlg.add_action_callback("Undo") {|d, p|Sketchup.send_action "editUndo:"}
dlg.add_action_callback("Redo") {|d, p|Sketchup.send_action "editRedo:"}
dlg.add_action_callback("New") {|d, p|Sketchup.send_action 57600}
dlg.add_action_callback("Open") {|d, p|Sketchup.send_action 57601}
dlg.add_action_callback("Save") {|d, p|Sketchup.send_action 57603}As you know, these actions are used in HTML and '<scrip> </script>' connects between ruby codes and HTML codes for indicating icons in webdialog. How can I make my own Sketchup.send_action? If it is possible, I will add the icons into webdialog.
-
-
Correction of codes
Hello, I have a problem in making box. I would like to add box on space by adding an icon, but it didn't work well. is there anybody who can fix the code?
` Class Box
def create_box1@lenght1 = 0.feet if not @lenght1 # along Green Y axis @width1 = 0.feet if not @width1 # along Red X axis @height1 = 0.feet if not @height1 # along Blue Z axis @R = 0 if not @R @G = 0 if not @G @B = 0 if not @B prompts = ["Lenght", "Width", "Height", "R(0~255)", "G(0~255)", "B(0~255)"] values = [@lenght1, @width1, @height1, @R, @G, @B] results = inputbox prompts, values, "Box Red" return if not results @lenght1, @width1, @height1, @R, @G, @B = results model = Sketchup.active_model model.start_operation "Create Box"
#-----------------------------------------------------------------------------
new_comp_def = Sketchup.active_model.definitions.add@pt0 = [0, 0, 0] @pt1 = [0, @lenght1, 0] @pt2 = [0, @lenght1, @height1] @pt3 = [0, 0, @height1] newface = new_comp_def.entities.add_face(@pt0, @pt1, @pt2, @pt3) newface.material=Sketchup::Color.new(@R, @G, @B) #color red newface.material.alpha = 0.4 newface.pushpull @width1 status=model.place_component(new_comp_def) Sketchup.active_model.active_entities.add_instance(new_comp_def, trans)
model.commit_operation
end
endCreate the Command object
box_cmd = UI::Command.new("Box") {
Sketchup.active_model.select_tool Box.new
}Configure the Command's appearance
box_cmd.small_icon = box_cmd.large_icon = dir+"/box.png"
box_cmd.tooltip = "Box"Create and configure the Toolbar
box_toolbar = UI::Toolbar.new "box"
box_toolbar.add_item box_cmd
box_toolbar.show` -
RE: Ray casting
For better understanding, I attached two images more. I got a example of ray casting on google and wanna express it into second picture. As you can see, This is just combination of cone and cylinder. If ray casting is added, invisible area behind cylinder should be occurred. In other word, all parts of cone shape behind cylinder automatically have to be deleted. I would like to apply ray casting into usual shapes
-
Ray casting
Hello. I've ever posted this question once, but there were no replies.
I wanna get idea for expressing ray casting effect in sketchup. An attached picture is what i want. Is there anybody who can give me ideas or can share tools? I'm waiting your kind replies
-
Possibility of partly removal of overlapped solid figure
I am looking for idea we can draw 3D figures partly removed by consideration of existence of obstacle, shade and so on. The ultimate purpose of this work is expressing camera coverage with cone figure like below picture. Unfortunately I didn't have any idea how to develop this work. You know, it is not simple placement of figures. I would like to automatically remove part behind obstacle in given space. Is there anybody can help me?
-
RE: Making submenu
Ok, Thanks, Dan
I will be able to fix it by myself )
Thank you!!
-
Drawing Sphere with ruby
Hello. I've ever downloaded a ruby creates box automatically on this site. With this ruby, I would like to develop coding to create sphere shape too. I guessed adding radius was all task but didn't work. please fix 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,= resultsmodel = Sketchup.active_model
model.start_operation "Sphere"
ents = Sketchup.active_model.definition.addcenter = [0, 0, 0]
radius = @radius
circle = ents.entities.add_circle center, [0, 0, 1], radius
circle_face = ents.add_face circlepath = ents.add_circle center, [0, 1, 0], radius + 1
circle_face.followme path
ents.erase_entities path
circle_face.material=Sketchup::Color.new(@R, @G, @B)
circle_face.material.alpha = 0.3status=model.place_component(ents)
Sketchup.active_model.active_entities.add_instance(ents, 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")` -
RE: Making submenu
I tried to fix some lines, but It still didn't work except that submenu is created. Nothing shown up on space once I clicked the submenu. Is it right the name of folder in plugins has to be 'KMK'?
` require 'sketchup.rb'
module KMK
module FGclass FGdrawing
def initialize(comp)
FGsystem.reset_global_variables
@ip1 = nil
@ip1 = nil
@drawn=false
@compname=comp
model=Sketchup.active_model
status=model.start_operation(" ")
model.commit_operation
enddef activate
@ip = Sketchup::InputPoint.new
@ip1 = Sketchup::InputPoint.new
@ip2 = Sketchup::InputPoint.new
FGsystem::status_bar(" ")
self.reset(nil)
enddef deactivate(view)
view.invalidate
enddef onMouseMove(flags, x, y, view)
if @state==0
@ip.pick view, x, y
if( @ip != @ip1 )
view.invalidate if( @ip.display? or @ip1.display? )
@ip1.copy! @ip
view.tooltip = @ip1.tooltip if( @ip1.valid? )
end
else
@ip2.pick view, x, y, @ip1
view.tooltip = @ip2.tooltip if( @ip2.valid? )
view.invalidate
end
enddef onLButtonDown(flags, x, y, view)
if (@state==0)
@ip1.pick view, x, y
if( @ip1.valid? )
Sketchup::set_status_text "Select none's range", SB_PROMPT if (@compname=="none.skp")
Sketchup::set_status_text "Select 30m90d's target", SB_PROMPT if (@compname=="30m_90degree.skp")
Sketchup::set_status_text "Select 50m60d's target", SB_PROMPT if (@compname=="50m_60degree.skp")
@state=1
end
elsif (@state==1)
if(@ip2.valid?)
self.create_light(view)
self.reset(view)
@state=0
end
end
enddef draw(view)
if( @ip1.valid? ) if( @ip1.display? ) @ip1.draw(view) @drawn = true end end if( @ip2.valid? ) @ip2.draw(view) if( @ip2.display?) length = (@ip1.position.distance(@ip2.position)).to_m self.draw_geometry(@ip1.position, @ip2.position, view) @drawn = true end
end
def onCancel(flag, view)
mod=Sketchup.active_model
mod.select_tool nil if @state==0
self.reset(view)
enddef reset(view)
@state = 0
FGsystem::status_bar(" ")
@ip.clear
@ip1.clear
@ip2.clear
if( view )
view.tooltip = nil
view.invalidate
end
@drawn = false
enddef draw_geometry(pt1,pt2,view)
view.set_color_from_line(pt1,pt2)
view.line_stipple="-.-"
view.line_width = 1
view.draw(GL_LINE_STRIP, pt1, pt2)
enddef deactivate(view)
view.invalidate if @drawn
enddef create_light(view)
pt1=@ip1.position
pt2=@ip2.position
model=Sketchup.active_model
definitions=model.definitions
path=Sketchup.find_support_file(@compname,"Plugins/KMK/FG")
definition=definitions.load(path.to_s)
model.start_operation("Insert Light")
light=model.active_entities.add_instance(definition, @ip1.position)
vector=pt1 - pt2
vector2=vector.clone
vector2.length=1
pt1=pt1-vector2
vector2=vector
vector2=Geom::Vector3d.new(0,0,1) if @compname=="none.skp"
trans=Geom::Transformation.new(pt1,vector2)
light.transformation=trans
dist=vector.length.to_m
FGsystem.set_none_params(light,dist) if @compname=="none.skp"
FGsystem.set_30m90d_params(light,dist) if @compname=="30m_90degree.skp"
FGsystem.set_50m60d_params(light,dist) if @compname=="50m_60degree.skp"
model.commit_operationend
end
class FGsystemdef FGsystem::reset_global_variables
@status_prefix=""
end
def FGsystem::set_none_params(e,dist)
FGsystem.set_default_(e,dist) dict_name="FGsystem" dict_key_attenuation = e.get_attribute(dict_name, " ")
end
def FGsystem::set_30m90d_params(e,dist)
FGsystem.set_default_30m90d(e,dist) dict_name="FGsystem" dict_key_attenuation = " " if dict_key_attenuation==nil dict_key_radius =@spothot if@spothot!=nil dict_key_falloff = @spotoff if @spotoff!=nil
end
def FGsystem::set_50m60d_params(e,dist)
FGsystem.set_default_50m60d(e,dist) dict_name="FGsystem" dict_key_attenuation = " " if dict_key_attenuation==nil dict_key_radius =@spothot if@spothot!=nil dict_key_falloff = @spotoff if @spotoff!=nil
end
def FGsystem::set_default_none(e,dist)
dict_name="FGsystem" if !e.attribute_dictionary dict_name dict_key_animate = " " dict_key_attenuation = " " end
end
def FGsystem::set_default_30m90d(e,dist)
dict_name="FGsystem" if !e.attribute_dictionary dict_name dict_key_animate = " " dict_key_attenuation = " " end
end
def FGsystem::set_default_50m60d(e,dist)
dict_name="FGsystem" if !e.attribute_dictionary dict_name dict_key_animate = " " dict_key_attenuation = " " end
end
def FGsystem::status_bar(stat_text)
statbar = Sketchup.set_status_text(@status_prefix + stat_text)
enddef FGsystem::instert_none
Sketchup.active_model.select_tool FGdrawing.new("none.skp")
enddef FGsystem::insert_30m90d
Sketchup.active_model.select_tool FGdrawing.new("30m_90degree.skp")
enddef FGsystem::insert_50m60d
Sketchup.active_model.select_tool FGdrawing.new("50m_60degree.skp")
end
endunless file_loaded?(__FILE__) dir= File.dirname(__FILE__) cmd_array = [] menu_text = "FGDetector" item_text = "30m90d" cmd = UI::Command.new(item_text) { FGSystem.insert_30m90d } cmd.large_icon = cmd.small_icon = dir + "/KMK/FG/kt_spot.png" cmd.status_bar_text = cmd.tooltip = item_text cmd.set_validation_proc { MF_ENABLED } cmd_array.push(cmd) item_text = "50m60d" cmd = UI::Command.new(item_text) { FGSystem.insert_50m60d } cmd.large_icon = cmd.small_icon = dir + "/KMK/FG/kt_scene.png" cmd.status_bar_text = cmd.tooltip = item_text cmd.set_validation_proc { MF_ENABLED } cmd_array.push(cmd) tb = UI::Toolbar.new(menu_text) submenu = UI.menu("Plugins").add_submenu(menu_text) # [a] The context menu is built EACH time the user clicks the right-mouse button. UI.add_context_menu_handler do |pop| # You can wrap the following lines within # a conditional expression, to control # if your popup context menu is shown. subpop = pop.add_submenu(menu_text) cmd_array.each {|i| subpop.add_item(i) } end # [b] So the normal menu and toolbars must be registered separately! cmd_array.each do |i| tb.add_item(i) submenu.add_item(i) end tb.show if tb.get_last_state == -1 end # unless loaded file_loaded(__FILE__)
end # module plugin FG
end # module toplevel KMK`
-
Making submenu
I am a beginner in learning Sketchup with Ruby. Now, I am practicing coding from existing .rb files. Below code is one of examples. You will be able to place the figures in .skp on cartesian space if you run this script(you need .skp files, images for making icons).
I would like to run this script in another way, submenu. I hope all figures are placed wherever i want after selection in input box, not clicking icons. It will be my pleasure if you give advices.
` require 'sketchup.rb'
class FGsystemdef FGsystem::reset_global_variables
@status_prefix=""
end
def FGsystem::set_none_params(e,dist)
FGsystem.set_default_(e,dist) dict_name="FGsystem" dict_key_attenuation = e.get_attribute(dict_name, " ")
end
def FGsystem::set_30m90d_params(e,dist)
FGsystem.set_default_30m90d(e,dist) dict_name="FGsystem" dict_key_attenuation = " " if dict_key_attenuation==nil dict_key_radius =@spothot if@spothot!=nil dict_key_falloff = @spotoff if @spotoff!=nil
end
def FGsystem::set_50m60d_params(e,dist)
FGsystem.set_default_50m60d(e,dist) dict_name="FGsystem" dict_key_attenuation = " " if dict_key_attenuation==nil dict_key_radius =@spothot if@spothot!=nil dict_key_falloff = @spotoff if @spotoff!=nil
end
def FGsystem::set_default_none(e,dist)
dict_name="FGsystem" if !e.attribute_dictionary dict_name dict_key_animate = " " dict_key_attenuation = " " end
end
def FGsystem::set_default_30m90d(e,dist)
dict_name="FGsystem" if !e.attribute_dictionary dict_name dict_key_animate = " " dict_key_attenuation = " " end
end
def FGsystem::set_default_50m60d(e,dist)
dict_name="FGsystem" if !e.attribute_dictionary dict_name dict_key_animate = " " dict_key_attenuation = " " end
end
def FGsystem::status_bar(stat_text)
statbar = Sketchup.set_status_text(@status_prefix + stat_text)
enddef FGsystem::instert_none
Sketchup.active_model.select_tool FGdrawing.new("none.skp")
enddef FGsystem::insert_30m90d
Sketchup.active_model.select_tool FGdrawing.new("30m_90degree.skp")
enddef FGsystem::insert_50m60d
Sketchup.active_model.select_tool FGdrawing.new("50m_60degree.skp")
end
endclass FGdrawing
def initialize(comp)
FGsystem.reset_global_variables
@ip1 = nil
@ip1 = nil
@drawn=false
@compname=comp
model=Sketchup.active_model
status=model.start_operation(" ")
model.commit_operation
enddef activate
@ip = Sketchup::InputPoint.new
@ip1 = Sketchup::InputPoint.new
@ip2 = Sketchup::InputPoint.new
FGsystem::status_bar(" ")
self.reset(nil)
enddef deactivate(view)
view.invalidate
enddef onMouseMove(flags, x, y, view)
if @state==0
@ip.pick view, x, y
if( @ip != @ip1 )
view.invalidate if( @ip.display? or @ip1.display? )
@ip1.copy! @ip
view.tooltip = @ip1.tooltip if( @ip1.valid? )
end
else
@ip2.pick view, x, y, @ip1
view.tooltip = @ip2.tooltip if( @ip2.valid? )
view.invalidate
end
enddef onLButtonDown(flags, x, y, view)
if (@state==0)
@ip1.pick view, x, y
if( @ip1.valid? )
Sketchup::set_status_text "Select none's range", SB_PROMPT if (@compname=="none.skp")
Sketchup::set_status_text "Select 30m90d's target", SB_PROMPT if (@compname=="30m_90degree.skp")
Sketchup::set_status_text "Select 50m60d's target", SB_PROMPT if (@compname=="50m_60degree.skp")
@state=1
end
elsif (@state==1)
if(@ip2.valid?)
self.create_light(view)
self.reset(view)
@state=0
end
end
enddef draw(view)
if( @ip1.valid? ) if( @ip1.display? ) @ip1.draw(view) @drawn = true end end if( @ip2.valid? ) @ip2.draw(view) if( @ip2.display?) length = (@ip1.position.distance(@ip2.position)).to_m self.draw_geometry(@ip1.position, @ip2.position, view) @drawn = true end
end
def onCancel(flag, view)
mod=Sketchup.active_model
mod.select_tool nil if @state==0
self.reset(view)
enddef reset(view)
@state = 0
FGsystem::status_bar(" ")
@ip.clear
@ip1.clear
@ip2.clear
if( view )
view.tooltip = nil
view.invalidate
end
@drawn = false
enddef draw_geometry(pt1,pt2,view)
view.set_color_from_line(pt1,pt2)
view.line_stipple="-.-"
view.line_width = 1
view.draw(GL_LINE_STRIP, pt1, pt2)
enddef deactivate(view)
view.invalidate if @drawn
enddef create_light(view)
pt1=@ip1.position
pt2=@ip2.position
model=Sketchup.active_model
definitions=model.definitions
path=Sketchup.find_support_file(@compname,"Plugins/FGsystem")
definition=definitions.load(path.to_s)
model.start_operation("Insert Light")
light=model.active_entities.add_instance(definition, @ip1.position)
vector=pt1 - pt2
vector2=vector.clone
vector2.length=1
pt1=pt1-vector2
vector2=vector
vector2=Geom::Vector3d.new(0,0,1) if @compname=="none.skp"
trans=Geom::Transformation.new(pt1,vector2)
light.transformation=trans
dist=vector.length.to_m
FGsystem.set_none_params(light,dist) if @compname=="none.skp"
FGsystem.set_30m90d_params(light,dist) if @compname=="30m_90degree.skp"
FGsystem.set_50m60d_params(light,dist) if @compname=="50m_60degree.skp"
model.commit_operationend
endif( not file_loaded?(FILE) )
UI.add_context_menu_handler do |menu| end dir= File.dirname(__FILE__) cmd_array = [] cmd = UI::Command.new(" ") {FGsystem.insert_30m90d} cmd.large_icon = cmd.small_icon = dir+"/FGsystem/kt_spot.png" cmd.status_bar_text = cmd.tooltip = "30m90d" cmd_array.push(cmd) cmd = UI::Command.new(" ") {FGsystem.insert_50m60d} cmd.large_icon = cmd.small_icon = dir+"/FGsystem/kt_scene.png" cmd.status_bar_text = cmd.tooltip = "50m60d" cmd_array.push(cmd) tb = UI::Toolbar.new("FGDetector") cmd_array.each {|i| tb.add_item(i)} tb.show if tb.get_last_state == -1
end
file_loaded(FILE)`