How to close Sketchup
-
Is there a way to shut down the current instance of Sketchup from a plugin?
-
Found this. However, not elegant or documented.
-
-
Jim, thanks, I missed that post.
-
Thanks to everyone, Taking a bit from both, however yet untested on a Mac:
begin #or 57602 pc only Sketchup.send_action 57665 rescue #mac only Sketchup.send_action('terminate;') end
If the pc version fails, must be Mac. Hope the command is OK.
-
Instead of try and rescue you can detect the OS:
<span class="syntaxdefault"><br /> </span><span class="syntaxcomment"># @return [Boolean]<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment"># @since 2.4.0<br /></span><span class="syntaxdefault"> def self</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">is_osx</span><span class="syntaxkeyword">?<br /></span><span class="syntaxdefault"> </span><span class="syntaxkeyword">(</span><span class="syntaxdefault">Object</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">RUBY_PLATFORM </span><span class="syntaxkeyword">=~</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">/</span><span class="syntaxdefault">darwin</span><span class="syntaxkeyword">/</span><span class="syntaxdefault">i</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">?</span><span class="syntaxdefault"> true </span><span class="syntaxkeyword">;</span><span class="syntaxdefault"> false<br /> end<br /> <br /> </span><span class="syntaxcomment"># @return [Boolean]<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment"># @since 2.5.0<br /></span><span class="syntaxdefault"> def self</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">is_windows</span><span class="syntaxkeyword">?<br /></span><span class="syntaxdefault"> </span><span class="syntaxkeyword">!</span><span class="syntaxdefault">self</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">is_osx</span><span class="syntaxkeyword">?<br /></span><span class="syntaxdefault"> end<br /><br /> def self</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">close_sketchup<br /> if self</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">is_osx</span><span class="syntaxkeyword">?<br /></span><span class="syntaxdefault"> Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">send_action</span><span class="syntaxkeyword">(</span><span class="syntaxstring">'terminate;'</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> else<br /> Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">send_action</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">57665</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> end<br /> end<br /></span>
-
sending action 57602 does a "dirty" terminate of Sketchup (similar to using the Task Manager to shut down an app. You really should NOT use it, unless of last resort.)
I'll modify my [code] post title and remove the "(beta)" as it's proven now.
-
Actually a general way of defining platform variant methods that execute faster.
(This method may not be the best example as it would only run once per session.)<span class="syntaxdefault"><br /> if self</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">is_osx</span><span class="syntaxkeyword">?<br /></span><span class="syntaxdefault"> def self</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">close_sketchup<br /> Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">send_action</span><span class="syntaxkeyword">(</span><span class="syntaxstring">'terminate;'</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> end<br /> else<br /> def self</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">close_sketchup<br /> Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">send_action</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">57665</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> end<br /> end<br /></span>
-
Thanks, guys. Now I have to go look up, and learn what
self.stuff
means:-)
-
Is it possible to close one instance of sketchup from another?
-
@honoluludesktop said:
Thanks, guys. Now I have to go look up, and learn what
self.stuff
meansself refers to the module namespace that you are defining the method within.
You could also def the module method like so:
module Hawaii def Hawaii.gizmo(arg) puts( arg.to_s ) end end # module
but if you have many module methods in the module, and you later decide to change the module name, you would have to either manually edit each method definition name, or do a search and replace (if your editor has that feature.)
Instead, def your module methods like so:
module Hawaii def self.gizmo(arg) puts( arg.to_s ) end end # module
and that way, if you change the module name, you only need edit 1 line of code.
However, if you instead use my extension method to the Sketchup module, you won't need, to define one within your own module. The drawback is that any user of your plugin must also go and download my extension.
- I did log a API Feature Request that my method be added to the Sketchup module on the C side of the Google code, which is why I included a unless method_defined?(:app_safe_shutdown) block around the declaration. If it gets added in a future release, my script will do nothing.
You may also wish to go readup on my [info] post on using Ruby modules.
[info] Using Ruby Modules
to discuss:
[talk] Using Ruby Modules -
@honoluludesktop said:
Is it possible to close one instance of sketchup from another?
Probably via a named pipe, but you (and your users,) must either use a standard Ruby pipe library, or a specific platform library like Daniel Berger's win32 utility libraries.
-
@dan rathbun said:
...........refers to the module namespace that you are defining the method within.........
OK, I get that. Thanks.
Advertisement