I will message you. please check inbox
Latest posts made by kmk111890
-
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.
-