Suspend/Resume methods

154 views
Skip to first unread message

Chiefwoodworker

unread,
Sep 13, 2011, 12:42:19 PM9/13/11
to Google SketchUp Developers - SketchUp Ruby API
I am looking for examples of the use of suspend/resume in a tool
script. I have searched the forums and the example codes and found
none. Does someone have a script using suspend/resume they are willing
to share? Thanks,
Joe....

Dan Rathbun

unread,
Sep 13, 2011, 8:45:33 PM9/13/11
to Google SketchUp Developers - SketchUp Ruby API
Hmmm... check the code for some of ThomThom's or TIG's tools at SCF

http://forums.sketchucation.com/viewtopic.php?f=323&t=28782

Chiefwoodworker

unread,
Sep 14, 2011, 12:41:54 PM9/14/11
to Google SketchUp Developers - SketchUp Ruby API
I followed Dan's advice and searched ThomThom's and TIG's tool but
didn't find any examples of suspend/resume implementations.
Interestingly bezierspline.rb does seem to implement it but it doesn't
work. If anyone knows how to use these methods I would appreciate a
short tutorial. Thanks,

Joe....

Dan Rathbun

unread,
Sep 14, 2011, 2:06:09 PM9/14/11
to Google SketchUp Developers - SketchUp Ruby API
Well Joe..

Basically suspend() might call view.invalidate() to get rid of any
graphics you've drawn on the view, and possibly be sure to save the
state of the tool, temporary points, etc.

When resume() is called, you put the tool back into the state it was
when it was suspended. Say the user had picked a point that is stored
in @pt1, and your @state var == 1 (0 when the tool is first activated,
and before the user picks the start point.)
You then need to redraw the view line again (usually by manually
calling the onMouseMove callback and passing the @pt1 as an argument.)
Or perhaps you have defined a private method that advances the tool
through each state, then you just call that on resume()

def resume(view)
set_state(@state,view)
end

private

def set_state(state,view)
if state==0
# do stuff
@state = @state.next
elsif state==1
# do stuff
@state = @state.next
elsif state==2
# do stuff
@state = @state.next
else
# do final stuff
# now reset tool which should set @state to 0
reset()
end
end

I am surprised that the Google "linetool.rb" example did not show
these callbacks. The example should be updated.

JohnMcC

unread,
Dec 7, 2012, 7:35:17 PM12/7/12
to sketch...@googlegroups.com
I find myself in the same position as Joe was - trying to find a working example of suspend/resume in a Tool. This is the ONLY useful result from a google search for 'sketchup ruby suspend resume tool' other than the extremely basic example in the Ruby API documentation.

I understand the general principles of what Dan describes, and am trying to modify Jim Foltz's CLineTool to draw lengths of timber of selected cross section and orientation.

I get as far in my tool so far as creating a face in the correct size and orientatiion at one end of the timber, then at the moment, just hand over to the native SU PushPull tool to push the face to a picked (or VCB typed) length.

But I'd like instead to suspend my tool while PushPull is working, then get back control to 'do some final stuff' including recording what length the user has selected.

The LineTool example in SU8 still doesn't have suspend/resume implemented, though re-reading the code which subclasses the LineTool to generate a basic CylinderTool has given me an idea that might work instead, though without the full power of the built-in PushPull tool.

Joe, did you ever find or create an example that worked?

I'd be most grateful if you did and would be willing to share it.

Thanks if you can help.

John McC

TIG

unread,
Dec 9, 2012, 9:40:39 AM12/9/12
to sketch...@googlegroups.com
Within a Tool there are several built-in methods:
The method
   resume(view)
is used to reset your Tool's 'display' as it was before it was paused by a 'suspend'.
Typically this is after the user moves the mouse off screen or uses the view tool, and thereby things the status-bar message etc have been lost.
So in this method you add code to redo the @msg etc, VCB display and so on...
You might also use
   view_invalidate
   self.draw()
etc.
I often use 'resume()', but rarely [if ever] use suspend...

The related Tool method is
   suspend(view)
- this is called by SketchUp when your Tool temporarily becomes inactive because another tool has been activated.
This typically happens when a viewing tool is activated, such as when orbit is active due to the middle mouse button.
Often you need to do nothing on the 'suspend()' but want to restore things with the resume(view) method from already saved/valid data;
however, if there's stuff you'd like to 'remember' for use later that isn't currently getting stored in @ references etc then the suspend(view) method is where to do it...


JohnMcC

unread,
Dec 12, 2012, 6:44:01 PM12/12/12
to sketch...@googlegroups.com

Many thanks, TIG.

When I get a few other bugs ironed out (a Class variable is getting unset when I cancel a dialogue box, and I can't yet see where or how), I'll give this a try.

John McC

Ruben de Gelder

unread,
Jul 20, 2016, 9:59:00 AM7/20/16
to SketchUp Ruby API
Interesting this discussion about suspend and resume methods.
I discovered that when suspend and resume are not implemented in my tools, i run into frequent bugsplats after using zoom or orbit while my tool is active.
When they are implemented, as totaly empty methods!, i don't get bugsplats anymore.
Does anyone have any insight or views or ideas on this matter?
Thanks, Ruben
Reply all
Reply to author
Forward
0 new messages