Refresh and stop inside a long routine
-
Hello to all.
Who can help me to insert commands to "refresh" and "stop" during the calculation in a routine that generates a drawing with hundreds of faces?
I tried to use the method "invalidate" and "onCancel", but with poor results.
For example, given the following simple procedure for calculation:
def test_cancel_refresh @my_model = Sketchup.active_model @my_entities = @my_model.entities @step = 10 @n_tot = @step*@step*@step for @z in 1..@step for @y in 1..@step for @x in 1..@step @x0 = @x-1 @y0 = @y-1 @z0 = @z-1 @x1 = @x0+0.5 @y1 = @y0+0.5 @z1 = @z0+0.5 @pt0 = Geom::Point3d.new(@x0,@y0,@z0) @pt1 = Geom::Point3d.new(@x1,@y0,@z0) @pt2 = Geom::Point3d.new(@x1,@y1,@z0) @pt3 = Geom::Point3d.new(@x0,@y1,@z0) @pt4 = Geom::Point3d.new(@x0,@y0,@z1) @pt5 = Geom::Point3d.new(@x1,@y0,@z1) @pt6 = Geom::Point3d.new(@x1,@y1,@z1) @pt7 = Geom::Point3d.new(@x0,@y1,@z1) @my_entities.add_face(@pt0,@pt1,@pt2,@pt3) @my_entities.add_face(@pt4,@pt5,@pt6,@pt7) @my_entities.add_face(@pt0,@pt4,@pt5,@pt1) @my_entities.add_face(@pt3,@pt7,@pt6,@pt2) @my_entities.add_face(@pt0,@pt4,@pt7,@pt3) @my_entities.add_face(@pt1,@pt5,@pt6,@pt2) @prog = @x + (@y-1)*@step + (@z-1)*@step*@step @msg = @prog.to_s Sketchup.status_text = "Status: " + @prog.to_s + "/" + @n_tot.to_s end end end end
The status message (where I write the progression) is visible since about 50% and after stop, the screen becomes blank and everything freezes until the end of the routine, when finally happens the screen regeneration.
Rather, I would always see the progression and sometimes even regenerate the screen.
It should also be possible to stop at any time of the calculation by pressing the ESC key.How can I effectively incorporate these controls in my script?
I did not find examples of this. -
@trottolino said:
Hello to all.
Who can help me to insert commands to "refresh" and "stop" during the calculation in a routine that generates a drawing with hundreds of faces?
I tried to use the method "invalidate" and "onCancel", but with poor results.
For example, given the following simple procedure for calculation:
**def test_cancel_refresh @my_model = Sketchup.active_model @my_entities = @my_model.entities @step = 10 @n_tot = @step*@step*@step for @z in 1..@step for @y in 1..@step for @x in 1..@step @x0 = @x-1 @y0 = @y-1 @z0 = @z-1 @x1 = @x0+0.5 @y1 = @y0+0.5 @z1 = @z0+0.5 @pt0 = Geom::Point3d.new(@x0,@y0,@z0) @pt1 = Geom::Point3d.new(@x1,@y0,@z0) @pt2 = Geom::Point3d.new(@x1,@y1,@z0) @pt3 = Geom::Point3d.new(@x0,@y1,@z0) @pt4 = Geom::Point3d.new(@x0,@y0,@z1) @pt5 = Geom::Point3d.new(@x1,@y0,@z1) @pt6 = Geom::Point3d.new(@x1,@y1,@z1) @pt7 = Geom::Point3d.new(@x0,@y1,@z1) @my_entities.add_face(@pt0,@pt1,@pt2,@pt3) @my_entities.add_face(@pt4,@pt5,@pt6,@pt7) @my_entities.add_face(@pt0,@pt4,@pt5,@pt1) @my_entities.add_face(@pt3,@pt7,@pt6,@pt2) @my_entities.add_face(@pt0,@pt4,@pt7,@pt3) @my_entities.add_face(@pt1,@pt5,@pt6,@pt2) @prog = @x + (@y-1)*@step + (@z-1)*@step*@step @msg = @prog.to_s Sketchup.status_text = "Status: " + @prog.to_s + "/" + @n_tot.to_s end end end end**
The status message (where I write the progression) is visible since about 50% and after stop, the screen becomes blank and everything freezes until the end of the routine, when finally happens the screen regeneration.
Rather, I would always see the progression and sometimes even regenerate the screen.
It should also be possible to stop at any time of the calculation by pressing the ESC key.How can I effectively incorporate these controls in my script?
I did not find examples of this.Did I asked a too simple question or no one knows the solution?
-
I have not found any good solution for this kind of thing. If anyone can come up with an answer I'd love to hear it too. I've always had the impression this is just a limitation of Ruby, or at least it's incorporation in SU.
-
As soon as you figure it out, let us know!
Kidding aside, to my knowledge it is not possible to suspend the execution using the methods in the API. There may be a way to do it outside of SketchUp.
The one strategy I have thought of is partitioning the operations into smaller sets. Maybe there is a way to check for user input between the smaller sets? I have never tried it.
-
Maybe using a timer to break the execution after so many seconds?
However, it seems like SU is queuing the stuff up, and once queued, you can't get out of it. As if Ruby can submit operations faster than SU can add geometry. This pure speculation, though.
Is adding geometry to a ComponentDefinition faster because you are not adding stuff to actually draw right now, but to the Definition which gets added later?
-
@tig said:
model.commit_operation with your clac's might help but it will mean multiple undo's ?
In version 7, you have a choice to make the operation transparent: start_operation.
-
Jim's idea of sub-setting works to an extent. See my Roof.rb - it asks for details, makes the roof's form, then displays it with default materials and then asks for materials in a dialog and redisplays it with the materials. It is the user input that causes the pause and the screen to refresh. Using model.start_operation ... model.commit_operation with your clac's might help but it could mean multiple undo's ?
Advertisement