sketchucation logo sketchucation
    • Login
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    🫛 Lightbeans Update | Metallic and Roughness auto-applied in SketchUp 2025+ Download

    How to close Sketchup

    Scheduled Pinned Locked Moved Developers' Forum
    13 Posts 4 Posters 1.2k 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.
    • honoluludesktopH Offline
      honoluludesktop
      last edited by

      Jim, thanks, I missed that post.

      1 Reply Last reply Reply Quote 0
      • honoluludesktopH Offline
        honoluludesktop
        last edited by

        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
        • thomthomT Offline
          thomthom
          last edited by

          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
          • Dan RathbunD Offline
            Dan Rathbun
            last edited by

            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
            • Dan RathbunD Offline
              Dan Rathbun
              last edited by

              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
              • honoluludesktopH Offline
                honoluludesktop
                last edited by

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

                1 Reply Last reply Reply Quote 0
                • honoluludesktopH Offline
                  honoluludesktop
                  last edited by

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

                  1 Reply Last reply Reply Quote 0
                  • Dan RathbunD Offline
                    Dan Rathbun
                    last edited by

                    @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
                    • Dan RathbunD Offline
                      Dan Rathbun
                      last edited by

                      @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
                      • honoluludesktopH Offline
                        honoluludesktop
                        last edited by

                        @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
                        • First post
                          Last post
                        Buy SketchPlus
                        Buy SUbD
                        Buy WrapR
                        Buy eBook
                        Buy Modelur
                        Buy Vertex Tools
                        Buy SketchCuisine
                        Buy FormFonts

                        Advertisement