THANKS to all for your efforts!
Now it works!!! it's slower than before, but it runs and that's the main thing!
@Dan: Thank you, you're the best! ^^
Posts
-
RE: Mysterious Bug [followme related]
-
RE: Mysterious Bug [followme related]
Dan, i have to correct myself: It works, when i load the script from the Ruby Console = step forward! [Edit:] i just noticed, this is what thomthom meant. [/Edit]
But it doesn't work yet, when i want to load the script from the plugin-folder by starting SU normally and the script is located in the plugin-folder. -
RE: Mysterious Bug [followme related]
@Dan: Thank you. Now my code looks like:
require 'sketchup.rb' module Chris88 module LineA TIMER = nil def self.create_line() # delete lines 1-4 with loop # model = Sketchup.active_model entities = model.active_entities #-------------------------------------------------------------------------- # Add the group to the entities in the model group = entities.add_group # Get the entities within the group # alle Objekte die den entities2 zugeordnet werden, werden automatisch zu einer gemeinsamen Gruppe gemacht entities2 = group.entities begin model.start_operation( 'LineA' ) @width_small = 55 # 55 @depth_small = 45 # 45 @height_small = 30 # 30 @width_big = 70 # 70 @depth_big = 60 # 60 @height_big = 70 # 40 @height_line = (4/3) * @height_small @radius = 1 @arcradius = 3 #-------------------------------------------------------------------------- @mat_linie=model.materials.add("Material_Linie") @mat_linie.color=Sketchup;;Color.new(124,252,0) # => LawnGreen #-------------------------------------------------------------------------- @anzahl_arcs = ((@depth_small-6)/6).to_i @pts =[] @helpvar_depth = 3 @helpvar_pts = 1 @helpvar_baseline = 1 @helpvar_basearc = 1 #-------------------------------------------------------------------------- 1.upto(@anzahl_arcs) do |x| @helpvar2_pts = @helpvar_pts +1 #-------------------------------------------------------------------------- if (x%2 > 0) @pts[@helpvar_pts] = [((@width_big-@width_small)/2)+5.35, ((@depth_big-@depth_small)/2)+@helpvar_depth, @height_line] @pts[@helpvar_pts+1] = [@width_small+((@width_big-@width_small)/2)-5.3, ((@depth_big-@depth_small)/2)+@helpvar_depth, @height_line] # arc_point @pts[@helpvar_pts+2] = [@width_small+((@width_big-@width_small)/2)-5, ((@depth_big-@depth_small)/2)+(@helpvar_depth+3), @height_line] arc_circle_odd = entities2.add_circle @pts[@helpvar_pts+1], X_AXIS, @radius, 42 arc_circle_face_odd = entities2.add_face arc_circle_odd arc_circle_face_odd.material = @mat_linie arc_circle_face_odd.back_material = @mat_linie line_circle_odd = entities2.add_circle @pts[@helpvar_pts], X_AXIS, @radius, 42 line_circle_face_odd = entities2.add_face line_circle_odd line_circle_face_odd.material = @mat_linie line_circle_face_odd.back_material = @mat_linie @helpvar_baseline_odd = entities2.add_line @pts[@helpvar_pts], @pts[@helpvar_pts+1] @helpvar_basearc_odd = entities2.add_arc @pts[@helpvar_pts+2],[0,-1,0],[0,0,1],@arcradius,-5.degrees,185.degrees arc_circle_face_odd.followme @helpvar_basearc_odd line_circle_face_odd.followme @helpvar_baseline_odd #-------------------------------------------------------------------------- elsif (x%2 == 0) @pts[@helpvar2_pts-1] = [((@width_big-@width_small)/2)+5.3, ((@depth_big-@depth_small)/2)+@helpvar_depth, @height_line] @pts[@helpvar2_pts] = [@width_small+((@width_big-@width_small)/2)-5.35, ((@depth_big-@depth_small)/2)+@helpvar_depth, @height_line] # arc_point @pts[@helpvar2_pts+1] = [((@width_big-@width_small)/2)+5, ((@depth_big-@depth_small)/2)+(@helpvar_depth+3), @height_line] arc_circle_even = entities2.add_circle @pts[@helpvar2_pts-1], X_AXIS, @radius, 42 arc_circle_face_even = entities2.add_face arc_circle_even arc_circle_face_even.material = @mat_linie arc_circle_face_even.back_material = @mat_linie line_circle_even = entities2.add_circle @pts[@helpvar2_pts], X_AXIS, @radius, 42 line_circle_face_even = entities2.add_face line_circle_even line_circle_face_even.material = @mat_linie line_circle_face_even.back_material = @mat_linie @helpvar_baseline_even = entities2.add_line @pts[@helpvar2_pts], @pts[@helpvar2_pts-1] @helpvar_basearc_even = entities2.add_arc @pts[@helpvar2_pts+1],[0,1,0],[0,0,1],@arcradius,-5.degrees,185.degrees arc_circle_face_even.followme @helpvar_basearc_even line_circle_face_even.followme @helpvar_baseline_even end # if #-------------------------------------------------------------------------- if (x == @anzahl_arcs) @pts[@helpvar_pts] = [((@width_big-@width_small)/2)+5.35, ((@depth_big-@depth_small)/2)+(@helpvar_depth+6), @height_line] @pts[@helpvar_pts+1] = [@width_small+((@width_big-@width_small)/2)-5, ((@depth_big-@depth_small)/2)+(@helpvar_depth+6), @height_line] @helpvar_baseline_ende = entities2.add_line @pts[@helpvar_pts], @pts[@helpvar_pts+1] line_circle_odd = entities2.add_circle @pts[@helpvar_pts], X_AXIS, @radius, 42 line_circle_face_odd = entities2.add_face line_circle_odd line_circle_face_odd.material = @mat_linie line_circle_face_odd.back_material = @mat_linie line_circle_face_odd.followme @helpvar_baseline_ende end # if #-------------------------------------------------------------------------- @helpvar_depth = @helpvar_depth + 6 @helpvar_pts = @helpvar_pts + 3 #-------------------------------------------------------------------------- end # upto - do #-------------------------------------------------------------------------- rescue => e model.abort_operation puts("#{Module.nesting[0].name} Error #<#{e.class.name}; #{e.message}>") puts(e.backtrace) else model.commit_operation end end # def end # module LineA # run when file loads # if Sketchup.active_model && Sketchup.active_model.active_entities LineA.create_line else LineA;;TIMER = UI.start_timer(2.0, true){ if Sketchup.active_model && Sketchup.active_model.active_entities UI.stop_timer(LineA;;TIMER) LineA.create_line end #if } end end # module Chris88
Is this what do you mean?
However it doesn't solve the bug.@thomthom: Thanks, that could help me. I know this, what you wrote in your sidenode, but it didn't work: When i draw a circle and a path, which starts at the central point of the cricle, Sketchup draw only the lines, but not the curves. This is why i decided alternatively to draw the lines and the curves seperately. Do you think the gaps could be the reason for the bug?
-
RE: Mysterious Bug [followme related]
@thomthom: Correct. And yes, it crashes if it's located in the plugin-folder, too.
And it doesn't matter, if i load the script with the Ruby Console or if i start SU normally and the script is in the plugin-folder.@Dan: Thanks Dan! I will test it in a few minutes...
-
RE: Mysterious Bug [followme related]
The course of action of my program, which conduces to woodworking:
in C#:- read technical values out of xml-files
- generate a rubyscript for every object
(tool, wood, machining line,...) in .txt- format - replace the wildcards (i.e: width,height,depth of a wooden box)
- put all rubyscripts together an name the file xy.rb
- start Sketchup with the file xy.rb as argument
... and my code is all but finished, when i start SU with the file xy.rb it crashes and SU reports a "bug splat"
http://images.wikia.com/sketchyphysics/images/6/63/BugSplat.png -
RE: Mysterious Bug [followme related]
So because i'm almost at the end of coding my program, i actually don't want to modify the rubyscript, that it loads premade components.
-
RE: Mysterious Bug [followme related]
@thomthom: i can start successfully the script in SU per Ruby Code Editor or per Sketchup Bridge in RDE to test it. The error appears when i copy my script in the plugin-folder, load it from ruby console in SU or start SU per cmd and assign my script as parameter in the cmd.
@TIG: thanks for your corrected code and suggestion, but it doesn't solve the bug. And i don't 'understand' your first lines: "make a new template containing the desired stuff as the default" ... and it shouldn't be premade components (that's was my first attempt )
-
RE: Mysterious Bug [followme related]
the strange loop ist an advice of TIG... http://forums.sketchucation.com/viewtopic.php?f=180&t=41767,
it makes sure that all services of SU are loaded succesfully.
it runs also without this loop.And i have commenting out all loops and many lines, but i didn't found the failure.
It's strange that i can run the script succesfully in SU, this bug is only when loading the script out of the plugins or starting SU per cmd with the script as parameter.(P.S. i have SU 8 free version)
-
Mysterious Bug [followme related]
Hi all,
i have this code (i know it looks confusing, because i don't know
how to program the 'followme'-function, but it's not the problem)module LineA def LineA.create_line unless Sketchup.active_model; until Sketchup.active_model.active_entities end end model = Sketchup.active_model entities = model.active_entities #-------------------------------------------------------------------------- # Add the group to the entities in the model group = entities.add_group # Get the entities within the group entities2 = group.entities #-------------------------------------------------------------------------- @width_small = 55 # 55 @depth_small = 45 # 45 @height_small = 30 # 30 @width_big = 70 # 70 @depth_big = 60 # 60 @height_big = 70 # 40 @height_line = (4/3) * @height_small @radius = 1 @arcradius = 3 #-------------------------------------------------------------------------- @mat_linie=model.materials.add("Material_Linie") @mat_linie.color=Sketchup;;Color.new(124,252,0) # => LawnGreen #-------------------------------------------------------------------------- @anzahl_arcs = ((@depth_small-6)/6).to_i @pts =[] @helpvar_depth = 3 @helpvar_pts = 1 @helpvar_baseline = 1 @helpvar_basearc = 1 #-------------------------------------------------------------------------- 1.upto(@anzahl_arcs) do |x| @helpvar2_pts = @helpvar_pts +1 #-------------------------------------------------------------------------- if (x%2 > 0) @pts[@helpvar_pts] = [((@width_big-@width_small)/2)+5.35, ((@depth_big-@depth_small)/2)+@helpvar_depth, @height_line] @pts[@helpvar_pts+1] = [@width_small+((@width_big-@width_small)/2)-5.3, ((@depth_big-@depth_small)/2)+@helpvar_depth, @height_line] # arc_point @pts[@helpvar_pts+2] = [@width_small+((@width_big-@width_small)/2)-5, ((@depth_big-@depth_small)/2)+(@helpvar_depth+3), @height_line] arc_circle_odd = entities2.add_circle @pts[@helpvar_pts+1], X_AXIS, @radius, 42 arc_circle_face_odd = entities2.add_face arc_circle_odd arc_circle_face_odd.material = @mat_linie arc_circle_face_odd.back_material = @mat_linie line_circle_odd = entities2.add_circle @pts[@helpvar_pts], X_AXIS, @radius, 42 line_circle_face_odd = entities2.add_face line_circle_odd line_circle_face_odd.material = @mat_linie line_circle_face_odd.back_material = @mat_linie @helpvar_baseline_odd = entities2.add_line @pts[@helpvar_pts], @pts[@helpvar_pts+1] @helpvar_basearc_odd = entities2.add_arc @pts[@helpvar_pts+2],[0,-1,0],[0,0,1],@arcradius,-5.degrees,185.degrees arc_circle_face_odd.followme @helpvar_basearc_odd line_circle_face_odd.followme @helpvar_baseline_odd #-------------------------------------------------------------------------- elsif (x%2 == 0) @pts[@helpvar2_pts-1] = [((@width_big-@width_small)/2)+5.3, ((@depth_big-@depth_small)/2)+@helpvar_depth, @height_line] @pts[@helpvar2_pts] = [@width_small+((@width_big-@width_small)/2)-5.35, ((@depth_big-@depth_small)/2)+@helpvar_depth, @height_line] # arc_point @pts[@helpvar2_pts+1] = [((@width_big-@width_small)/2)+5, ((@depth_big-@depth_small)/2)+(@helpvar_depth+3), @height_line] arc_circle_even = entities2.add_circle @pts[@helpvar2_pts-1], X_AXIS, @radius, 42 arc_circle_face_even = entities2.add_face arc_circle_even arc_circle_face_even.material = @mat_linie arc_circle_face_even.back_material = @mat_linie line_circle_even = entities2.add_circle @pts[@helpvar2_pts], X_AXIS, @radius, 42 line_circle_face_even = entities2.add_face line_circle_even line_circle_face_even.material = @mat_linie line_circle_face_even.back_material = @mat_linie @helpvar_baseline_even = entities2.add_line @pts[@helpvar2_pts], @pts[@helpvar2_pts-1] @helpvar_basearc_even = entities2.add_arc @pts[@helpvar2_pts+1],[0,1,0],[0,0,1],@arcradius,-5.degrees,185.degrees arc_circle_face_even.followme @helpvar_basearc_even line_circle_face_even.followme @helpvar_baseline_even end # if #-------------------------------------------------------------------------- if (x == @anzahl_arcs) @pts[@helpvar_pts] = [((@width_big-@width_small)/2)+5.35, ((@depth_big-@depth_small)/2)+(@helpvar_depth+6), @height_line] @pts[@helpvar_pts+1] = [@width_small+((@width_big-@width_small)/2)-5, ((@depth_big-@depth_small)/2)+(@helpvar_depth+6), @height_line] @helpvar_baseline_ende = entities2.add_line @pts[@helpvar_pts], @pts[@helpvar_pts+1] line_circle_odd = entities2.add_circle @pts[@helpvar_pts], X_AXIS, @radius, 42 line_circle_face_odd = entities2.add_face line_circle_odd line_circle_face_odd.material = @mat_linie line_circle_face_odd.back_material = @mat_linie line_circle_face_odd.followme @helpvar_baseline_ende end # if #-------------------------------------------------------------------------- @helpvar_depth = @helpvar_depth + 6 @helpvar_pts = @helpvar_pts + 3 #-------------------------------------------------------------------------- end # upto - do #-------------------------------------------------------------------------- end # def end # module LineA.create_line
When i execute it in SU there's no error, but if i load it in the plugins of SU,
the hole SU break down and show me a 'Bug Splat', however no significant error message.
I hope you can help me.
Thanks -
RE: Error Message
I'm not sure what do you mean.
So it's better if i'll show you my code,
then you can teach me by reference to the code:` model = Sketchup.active_model
entities = model.active_entities
group = entities.add_group
entities = group.entities#-----------------------------------
Kettensaege kreiern
width_kettensaege = 40 depth_kettensaege = 1 height_kettensaege = 6 color_kettensaege = Sketchup::Color.new(169,169,169) pts = [] pts[0] = [0.5, 0.5, 0.5] pts[1] = [width_kettensaege+0.5, 0.5, 0.5] pts[2] = [width_kettensaege + 0.5, 0.5 + depth_kettensaege, 0.5] pts[3] = [0.5, 0.5 + depth_kettensaege, 0.5] base = entities.add_face pts
create material
mat_kettensaege=model.materials.add("Material_Kettensaege") mat_kettensaege.color=color_kettensaege area = base.area base.back_material = mat_kettensaege base.material = mat_kettensaege base.pushpull(height_kettensaege) kettensaege = my_definition = Sketchup.active_model.definitions[0]
to hide the original object
entities.each { |entity| entity.visible = false }
#----------------------------------
point = Geom::Point3d.new(0,0,0)
vector = [0,0,1]
angle = 1.57079
rotation = Geom::Transformation.rotation point, vector, angle
instance = entities.add_instance kettensaege, rotation # here is the error
#-----------------------------------` -
Error Message
Sorry guys, it's me again.
Can someone say something about this error message:
'add_instance': Insertion would result in recursive definition
It appears in a rotation command.Thanks
-
RE: Problem with color
Great!
Thank you, i like this forum more and more.Merry Christmas and happy holidays to all!
-
RE: Problem with color
This
unless Sketchup.active_model;until Sketchup.active_model.active_entities;end;end
and thisload 'myrubyfile.rb'
are the solutions for my problem, well it's really so,
that SU isn't ready to load the color.
Thanks again.Can anyone say how to make the material transparent, please?
-
RE: Problem with color
Sorry i wasn't online the last days.
First of all thanks for your suggestions.
I don't prefer the method with the timer, because i have to close and
open SU many times in a row. But i like the method "load rubyscript.rb"
i will test it.
And thanks to TIG, your help me a lot.
@Dan It's ok -
RE: Problem with color
@ Dan:
well unfortunately this doesn't help,
i have only one file with the aforementioned code.
And if i wrapped it in a namespace, the problem isn't fixed. The cuboid is drawn colorlessly. Only the sketchup-bridge in RDE draw it with color, but it should do that from the plungins folder. -
Problem with color
Hi all,
i need some help on a specific problem,
when i start sketchup with my code by loading my script from the plugin folder or with the command "-Rubystartup" in the cmd, the cuboid will be drawn, but not colored.
What i'm doing wrong?` require 'sketchup.rb'
def create_box
model = Sketchup.active_model model.start_operation $exStrings.GetString("Create Box") entities = model.active_entities group = entities.add_group entitites = group.entities
width = 70 # 70
depth = 60 # 60
height = 25 # 25
color = Sketchup::Color.new(255,240,187)pts = [] pts[0] = [0, 0, 0] pts[1] = [width, 0, 0] pts[2] = [width, depth, 0] pts[3] = [0, depth, 0] base = entities.add_face pts height = -height area = base.area base.material = color base.back_material = color base.pushpull(height) model.commit_operation
end
create_box`
Thanks for help.P.S. when i execute my script(the same code) in RDE with the Sketchup-Bridge, the color is drawn.
-
RE: Ruby Code Generator
ok, i think i need to explain it in more detail:
my C#-programm read a lot of XML-documents (which it could transform to TXT with XSLT), on the basis of these values my programm should generate many ruby-files, which will be executed in SketchUp.
If i code the ruby-files by hand, one ruby-file have ca. 2000-5000 lines (and i need many ruby-files), so it's more comfortable to generate the code. (it's a query, whether values exists in the XML/TXT or not -> a lot of if's)
-
Ruby Code Generator
Hey,
is there someone, who knows how to code a ruby-code-generator in C#?
Probably with ironruby in visual studio..Because i need a code generator in C#, which generate
ruby-code, which it can execute in sketchup.Thanks.