How do you make Ruby Scripts Pause
-
Sorry if this has been discussed before..
I am trying to simulate "animation" by using the transform! method on a group, to show the group moving. It works fine (I think) but happens too fast. I tried adding a "sleep .1" line in the Ruby code but then each transform! doesnt show up, only the last one, however, it does seem to take about the right amount of time. Is there a better way to make the code pause or wait? Or is there a way to make that "transformed" group actually visible. Any ideas or examples on how to show a group moving?? -
Hi Mark, welcome to the forum.
I would recommend instead of simulating an animation, you make it an actual Animation.
This example uses the SketchUp timer to create an animation - also a good technique:
Animate Yo' Cheese
Posted by Scott Lininger, SketchUp Engineer Drawing foodstuffs in SketchUp is fantastically cool, but at the end of the day you wind up wit...
(sketchupapi.blogspot.com)
However, to actually answer your question... you can call view.refresh to force an update of the view before you pause.
Although I think you'll find using sleep won't work as you expect as it pauses all of SketchUp, not just the Ruby part.
-
Has anyone figured out how to use threads fluidly, so that ruby and regular sketchup will work at the same time?
-
@jim said:
Hi Mark, welcome to the forum.
I would recommend instead of simulating an animation, you make it an actual Animation.
Amen.
@jim said:
This example uses the SketchUp timer to create an animation - also a good technique:
Animate Yo' Cheese
Posted by Scott Lininger, SketchUp Engineer Drawing foodstuffs in SketchUp is fantastically cool, but at the end of the day you wind up wit...
(sketchupapi.blogspot.com)
I'd not be going there. If memory serves, the timer really wants an integer, so any time less than a second is no time at all.
@jim said:
Although I think you'll find using sleep won't work as you expect as it pauses all of SketchUp, not just the Ruby part.
Right. I made several attempts to go down that road. Some were failures. The others were miserable failures.
The right way to do it is to create a class that implements the Animation interface.
I recommend Chapter 16 of my tutorial. It explains how to use the Animation interface and provides classes that you can call to move, scale and rotate things without ever needing the transformation matrix.
When you look at the sample code in the Animation interface doc, you'll see it calls
view.show_frame
. You want yours to callview.show_frame( delay_time )
. A time of1.0/30.0
would run at 30 frames per second if yournextFrame()
method took no time at all. That would be a good place to start if you really want about 24 fps.Scarpino has a chapter on animation in Automatic SketchUp, also. That's the way to go if you want to do an animated human.
-
@cjthompson said:
Has anyone figured out how to use threads fluidly, so that ruby and regular sketchup will work at the same time?
I tried. Miserable failures all.
-
@cjthompson said:
Has anyone figured out how to use threads fluidly, so that ruby and regular sketchup will work at the same time?
All attempts to use threads I've heard about had failed. Apparently it is a no-go.
Advertisement