Is it possible to initiate the termination of SketchUp from the Ruby script?

68 views
Skip to first unread message

JJ

unread,
Feb 2, 2010, 9:58:10 AM2/2/10
to Google SketchUp Developers - SketchUp Ruby API
Can anyone suggest a way to close SketchUp from Ruby on Windows OS?

TIG

unread,
Feb 2, 2010, 11:02:49 AM2/2/10
to Google SketchUp Developers - SketchUp Ruby API
A simple way for PC only...

Use Ruby to make a temporary file called say

C:\Temp\taskkillSUP.bat

Use puts to add a string into it

taskkill /fi "Windowtitle eq ModelNsme - SketchUp*"

Then run it using

UI.openURL("C:\Temp\taskkillSUP.bat")

The current SketchUp window with that title will be closed without
saving
- although of course you could have checked if the model has been
saved and if not save it before doing this ?

You need to assemble the string thus

"taskkill /fi \"Windowtitle eq " + Sketchup.active_model.title + " -
SketchUp*\"\n"

The wildcard * is to cover free and pro window-title differences ?
The 2 escaped " [\"] are needed too...

You can also delete the temp bat file to tidy up by adding a second
line to itself to self-delete...

del "C:\Temp\taskkillSUP.bat"

The puts string is formed thus

"del \"C:\Temp\taskkillSUP.bat\"\n"


Hope this helps ???

Jim Johnson

unread,
Feb 2, 2010, 11:03:01 AM2/2/10
to Google SketchUp Developers - SketchUp Ruby API
I discovered this oddity - an infinite loop will close SU.

Loading this script will close SU.
 
  def loopLock
   loopLock
  end

  loopLock

It's not clear to me why SU shutdown or who/what did it.   Is it a safety net from the SU dev team?

Dose anybody think this is this a reliable shutdown method?

Thanks - JJ
- SU 7.1.6087 on  Windows XP SP3



On Tue, Feb 2, 2010 at 9:58 AM, JJ <jimv...@gmail.com> wrote:
Can anyone suggest a way to close SketchUp from Ruby on Windows OS?

--
You received this message because you are subscribed to the Google Groups "SketchUp Ruby API" group.
To post to this group, send email to sketch...@googlegroups.com.
To unsubscribe from this group, send email to sketchupruby...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sketchupruby?hl=en.


Jim Johnson

unread,
Feb 2, 2010, 11:07:48 AM2/2/10
to sketch...@googlegroups.com
Thx - I'll try it - seems more proper than the infinite loop  - JJ

JJ

unread,
Feb 2, 2010, 11:10:43 PM2/2/10
to Google SketchUp Developers - SketchUp Ruby API
Yep that works well after doing the normal Slashdance and adusting for
these points:

- Invoking active_model.save writes the .skp file but doen't set
active_model.title.
- Save file by manulaly using the SU menu bar works in a way; It sets
the active_model.tittle and writes the .skp file, BUT when retrieved,
active_model.title does not contain the file extension.

Thanks - May fortune find you healthy - JJ

> > sketchupruby...@googlegroups.com<sketchupruby%2Bunsu...@googlegroups.com>

Dan Rathbun

unread,
Feb 3, 2010, 4:48:08 AM2/3/10
to Google SketchUp Developers - SketchUp Ruby API
On Feb 2, 11:10 pm, JJ wrote:
> BUT when retrieved,
> active_model.title does not contain the file extension.

It's not supposed to. It's a Title not a filename.
The API says, "The title method retrieves the name of the model. If
the model is saved on disk, returns the file name **without
extension.** Otherwise returns an empty string."
http://code.google.com/apis/sketchup/docs/ourdoc/model.html#title

Thw safest way would be to make a system call, and send the SU window
a WM_CLOSE message (basically simulating a ALT+F4 keystroke.)
Hafta look into that. (User would need Win32API.so in the search
paths.)

ChrisJT

unread,
Feb 3, 2010, 8:42:20 AM2/3/10
to Google SketchUp Developers - SketchUp Ruby API
I don't know if this is what you are talking about, but you can use:
Process.kill("KILL",Process.pid) to kill Sketchup.

Jim Johnson

unread,
Feb 3, 2010, 10:03:11 AM2/3/10
to sketch...@googlegroups.com
That works too.  I was under the impression that Ruby process and thread calls were not functional in the SU API, but that one works well. 

Thanks - JJ

--
You received this message because you are subscribed to the Google Groups "SketchUp Ruby API" group.
To post to this group, send email to sketch...@googlegroups.com.
To unsubscribe from this group, send email to sketchupruby...@googlegroups.com.

Dan Rathbun

unread,
Feb 3, 2010, 11:17:08 AM2/3/10
to Google SketchUp Developers - SketchUp Ruby API
On Feb 3, 10:03 am, Jim Johnson <jimvj...@gmail.com> wrote:
> That works too.  I was under the impression that Ruby process and thread
> calls were not functional in the SU API, but that one works well.

> On Wed, Feb 3, 2010 at 8:42 AM, ChrisJT <cjthomp...@aagard.com> wrote:
> > I don't know if this is what you are talking about, but you can use:
> > Process.kill("KILL",Process.pid) to kill Sketchup.

That's not all that safe... no chance to save work, etc.

But for an emergency... sure.

Reply all
Reply to author
Forward
0 new messages