sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Launch an Application in RUBY

    Scheduled Pinned Locked Moved Developers' Forum
    14 Posts 3 Posters 1.8k Views 3 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.
    • thomthomT Offline
      thomthom
      last edited by

      Have you tried with absolute path? Your relative path might be referring to the wrong place.
      Do you get any errors? Or does it silently fail?

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

      1 Reply Last reply Reply Quote 0
      • TIGT Offline
        TIG Moderator
        last edited by

        The API's UI.openURL() will open any 'location' using its default application - it doesn't need to be a web 'url' like
        UI.openURL("http://forums.sketchucation.com/")
        it can be the path to a file on your PC - say a .txt file, that then opens with Notepad.exe.
        UI.openURL("C:/Users/TIG/Desktop/My Text.txt")
        If the filepath is an .exe file it opens the application
        UI.openURL("C:/Windows/System32/notepad.exe")
        On a PC at least you can even just specify the exe with no path and it'll open
        UI.openURL("Notepad.exe")
        You can't give an .exe 'arguments' with 'openURL', so if you want to open a particular file with an application that isn't its default OR open a file with its app' but with arguments, on a PC you first make a temporary .cmd file [.command files on Mac], then add a line opening the application desired and the argument, use UI.openURL to 'open' the cmd file - it'll run it and then open the file with the non-default application. To tidy up you should delete the temporary cmd file at the end...

        
        tmp_cmd="My_tmp_file_"+Time.now.to_i.to_s+".cmd"
        ### safest to make a uniquely named temp file
        cmd_path="C;/Temp/"+tmp_cmd
        cmd_line="\"C;/Program Files/Notepad++/Notepad++.exe\" \"C;/Users/TIG/Desktop/My Text.txt\"\nexit"
        ### note escape \" around paths with spaces in
        ### the exit line ensures it closes afterwards...
        ### you could add '@echo off\n' etc at the start to run non-verbosely in the terminal window.
        cmd=File.new(cmd_path, "w")
        cmd.puts(cmd_line)
        cmd.close
        UI.openURL(cmd_path)
        ### the txt file now opens with Notepad++.exe NOT it's default Notepad.exe
        sleep(1)
        File.delete(cmd_path)
        ### we erase tmp_cmd file after waiting a second for it to run 
        ### omit this line to see the file that's made in C;/Temp/
        
        

        You can adapt this method to open any application needing arguments

        TIG

        1 Reply Last reply Reply Quote 0
        • S Offline
          simonstaton
          last edited by

          Thanks for the reply guys,

          it silently fails using my way.

          Tig I tryed your way however the location of the file needing to be run wont always be in the same place however it will be in the same folder of the program everytime so I cannot use the full path will this still working using "../../program.exe"?

          1 Reply Last reply Reply Quote 0
          • TIGT Offline
            TIG Moderator
            last edited by

            Can you clarify ? πŸ˜•
            If you know where this file is can't you use the full path ?
            mdir=File.dirname(model.path) gives you a folder then File.join(mdir, myfilename)
            gives the file's path ??
            If it's not the model's folder you are referring to then you might have it coded somewhere so you can use that ?

            TIG

            1 Reply Last reply Reply Quote 0
            • thomthomT Offline
              thomthom
              last edited by

              @simonstaton said:

              Tig I tryed your way however the location of the file needing to be run wont always be in the same place however it will be in the same folder of the program everytime so I cannot use the full path will this still working using "../../program.exe"?

              But you should try with the full path to ensure that the method work. Because if it does, then you know it is your relative path is incorrect. It might be that the working directory is not the one you assume it is.

              You could try File.expand_path() on your relative path and see what absolute path it translates to.

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

              1 Reply Last reply Reply Quote 0
              • S Offline
                simonstaton
                last edited by

                Hi Tig,

                sorry im a bit of a newb when it comes to this stuff πŸ˜„

                I will try and explain from the sketchup folder where you have components etc the file I want to launch is "client/googleearth.exe" however the plugin that is calling it is client "Plugins/Utilities/Toolbar.rb" from the sketchup folder. So what command would I use to call the googleearth.exe from toolbar.rb

                1 Reply Last reply Reply Quote 0
                • S Offline
                  simonstaton
                  last edited by

                  @thomthom said:

                  @simonstaton said:

                  Tig I tryed your way however the location of the file needing to be run wont always be in the same place however it will be in the same folder of the program everytime so I cannot use the full path will this still working using "../../program.exe"?

                  But you should try with the full path to ensure that the method work. Because if it does, then you know it is your relative path is incorrect. It might be that the working directory is not the one you assume it is.

                  You could try File.expand_path() on your relative path and see what absolute path it translates to.

                  ohh I see now ok I will give that a go.

                  1 Reply Last reply Reply Quote 0
                  • S Offline
                    simonstaton
                    last edited by

                    ok using the full path didnt work

                    1 Reply Last reply Reply Quote 0
                    • TIGT Offline
                      TIG Moderator
                      last edited by

                      ge=UI.openURL("C:\\Program Files\\Google\\Google Earth\\client\\googleearth.exe")
                      or
                      ge=UI.openURL("C:/Program Files/Google/Google Earth/client/googleearth.exe")
                      works and opens googleearth
                      ge=UI.openURL('googleearth.exe')
                      doesn't work as it's not been registered to open without a full path [on PC]
                      Note how ' ge' will return true if it succeeds, and false if fails - so if not ge popup a warning message and then run UI.openpanel() for the user to point your tool to googleearth ?

                      TIG

                      1 Reply Last reply Reply Quote 0
                      • S Offline
                        simonstaton
                        last edited by

                        ok that works with the full path however, google earth is not installed on the clients machine it will be inside sketchup in a way so when they install sketchup it will be inside the sketchup folder and where the sketchup folder is depends on where they have installed it on there machine. our clients are not pc friendly at all so keeping it to the basics is probably best

                        1 Reply Last reply Reply Quote 0
                        • TIGT Offline
                          TIG Moderator
                          last edited by

                          @simonstaton said:

                          ok that works with the full path however, google earth is not installed on the clients machine it will be inside sketchup in a way so when they install sketchup it will be inside the sketchup folder and where the sketchup folder is depends on where they have installed it on there machine. our clients are not pc friendly at all so keeping it to the basics is probably best

                          You can find where Sketchup is installed using
                          Sketchup.find_support_file('')
                          which returns something like
                          C:/Program Files/Google/Google SketchUp 7
                          πŸ€“

                          TIG

                          1 Reply Last reply Reply Quote 0
                          • S Offline
                            simonstaton
                            last edited by

                            ah there we go solved, now how would I merge the two? this dosnt seem to be working:

                            ge=UI.openURL(Sketchup.find_support_file('')"/client/googleearth.exe")

                            1 Reply Last reply Reply Quote 0
                            • S Offline
                              simonstaton
                              last edited by

                              dont worry i needed to put a "+" between to two solved! thanks tig

                              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