• Login
sketchucation logo sketchucation
  • Login
🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

How to close Sketchup

Scheduled Pinned Locked Moved Developers' Forum
13 Posts 4 Posters 1.1k Views 4 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    honoluludesktop
    last edited by 27 Dec 2010, 14:02

    Found this . However, not elegant or documented.

    1 Reply Last reply Reply Quote 0
    • J Offline
      Jim
      last edited by 27 Dec 2010, 14:12

      Here's Dan's code:

      http://forums.sketchucation.com/viewtopic.php?f=180&t=29162&hilit=safe+shut+down

      Hi

      1 Reply Last reply Reply Quote 0
      • H Offline
        honoluludesktop
        last edited by 27 Dec 2010, 14:53

        Jim, thanks, I missed that post.

        1 Reply Last reply Reply Quote 0
        • H Offline
          honoluludesktop
          last edited by 27 Dec 2010, 16:22

          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.

          1 Reply Last reply Reply Quote 0
          • T Offline
            thomthom
            last edited by 27 Dec 2010, 17:18

            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>
            

            Thomas Thomassen — SketchUp Monkey & Coding addict
            List of my plugins and link to the CookieWare fund

            1 Reply Last reply Reply Quote 0
            • D Offline
              Dan Rathbun
              last edited by 27 Dec 2010, 18:43

              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.

              I'm not here much anymore.

              1 Reply Last reply Reply Quote 0
              • D Offline
                Dan Rathbun
                last edited by 27 Dec 2010, 21:49

                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>
                

                I'm not here much anymore.

                1 Reply Last reply Reply Quote 0
                • H Offline
                  honoluludesktop
                  last edited by 27 Dec 2010, 22:00

                  Thanks, guys. Now I have to go look up, and learn what self.stuff means :-)

                  1 Reply Last reply Reply Quote 0
                  • H Offline
                    honoluludesktop
                    last edited by 27 Dec 2010, 22:27

                    Is it possible to close one instance of sketchup from another?

                    1 Reply Last reply Reply Quote 0
                    • D Offline
                      Dan Rathbun
                      last edited by 27 Dec 2010, 23:28

                      @honoluludesktop said:

                      Thanks, guys. Now I have to go look up, and learn what self.stuff means

                      self 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

                      I'm not here much anymore.

                      1 Reply Last reply Reply Quote 0
                      • D Offline
                        Dan Rathbun
                        last edited by 27 Dec 2010, 23:36

                        @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.

                        I'm not here much anymore.

                        1 Reply Last reply Reply Quote 0
                        • H Offline
                          honoluludesktop
                          last edited by 28 Dec 2010, 00:04

                          @dan rathbun said:

                          ...........refers to the module namespace that you are defining the method within.........

                          OK, I get that. Thanks.

                          1 Reply Last reply Reply Quote 0
                          • 1 / 1
                          1 / 1
                          • First post
                            11/13
                            Last post
                          Buy SketchPlus
                          Buy SUbD
                          Buy WrapR
                          Buy eBook
                          Buy Modelur
                          Buy Vertex Tools
                          Buy SketchCuisine
                          Buy FormFonts

                          Advertisement