sketchucation logo sketchucation
    • Login
    πŸ›£οΈ Road Profile Builder | Generate roads, curbs and pavements easily Download

    Open URL on local disk

    scheduled pinned locked moved Developers' Forum
    20 Posts 5 Posters 6.9k Views 5 Watching
    loading-more-posts
    • oldest-to-newest
    • newest-to-oldest
    • most-votes
    reply
    • reply-as-topic
    guest-login-reply
    deleted-message
    • M Offline
      MartinRinehart
      last edited by

      @cjthompson said:

      ...do you have a code example?

      Hmmm. What's going on?

      
      # /r2/open_st_help.rb
      
      require 'sketchup'
      
      help = "/r2/sketch_talk.html"
      file = File.new( help, 'r' )
      arr = file.readlines()
      file.close()
      puts arr[0]
      
      puts UI.openURL( help )
      
      

      The file reads correctly. (Eliminate typos in address constant.) But doesn't open:

      lineYes_urlNo.jpg

      Author, Edges to Rubies - The Complete SketchUp Tutorial at http://www.MartinRinehart.com/models/tutorial.

      one-reply-to-this-post last-reply-time reply quote 0
      • TIGT Offline
        TIG Moderator
        last edited by

        A URL 'file' needs a full file-path, as used in a browser etc you need to add the Plugins folder path to the start of the rest of the path it uses ? Base Ruby manages without it ?

        TIG

        one-reply-to-this-post last-reply-time reply quote 0
        • M Offline
          MartinRinehart
          last edited by

          @tig said:

          you need to add the Plugins folder path to the start of the rest of the path it uses ?

          That file isn't in Plugins. It's in C:/r2/. Oddly, when I add "C:" to the location, UI.openURL() reports true, but an open file in my default browser doesn't happen.

          Author, Edges to Rubies - The Complete SketchUp Tutorial at http://www.MartinRinehart.com/models/tutorial.

          one-reply-to-this-post last-reply-time reply quote 0
          • M Offline
            MartinRinehart
            last edited by

            Anyone?

            Author, Edges to Rubies - The Complete SketchUp Tutorial at http://www.MartinRinehart.com/models/tutorial.

            one-reply-to-this-post last-reply-time reply quote 0
            • TIGT Offline
              TIG Moderator
              last edited by

              UI.openURL()
              Works fine for me with web-pages e.g. UI.openURL("http://www.google.com")
              and with folders/files giving the absolute path UI.openURL("C:/Program Files/Google/Google SketchUp 7/Plugins"), add /myruby.rb to open that file.
              I think you have to pass it a string for the path that is a full-path with drive etc...
              I have occasionally heard of similar problems, but sorry, I don't have a solution 😞
              Which of the above examples work for you ?

              TIG

              one-reply-to-this-post last-reply-time reply quote 0
              • thomthomT Offline
                thomthom
                last edited by

                Sounds like it expects an URL - not a file path. Have you tried prefixing with file:// ?
                http://en.wikipedia.org/wiki/File_URI_scheme

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

                one-reply-to-this-post last-reply-time reply quote 0
                • TIGT Offline
                  TIG Moderator
                  last edited by

                  @thomthom said:

                  Sounds like it expects an URL - not a file path. Have you tried prefixing with file:// ?
                  http://en.wikipedia.org/wiki/File_URI_scheme

                  It will take a URL or absolute file path - you can then open folders, files and even applications...
                  Try UI.openURL("C:/Windows/System32/notepad.exe")
                  ???
                  πŸ˜•

                  TIG

                  one-reply-to-this-post last-reply-time reply quote 0
                  • C Offline
                    cjthompson
                    last edited by

                    @tig said:

                    Try UI.openURL("C:/Windows/System32/notepad.exe")

                    UI.openURL("notepad.exe") or even just UI.openURL("notepad") will also work.

                    one-reply-to-this-post last-reply-time reply quote 0
                    • M Offline
                      MartinRinehart
                      last edited by

                      @cjthompson said:

                      even just UI.openURL("notepad") will also work.

                      You never know when one little factoid will solve a problem.

                      I tried notepad (it works), then notepad++ (also works) and then an HTML file. It opened the HTML, but it opened it in Notepad++.

                      Now if only I can figure out how to specify both program and file ...

                      Author, Edges to Rubies - The Complete SketchUp Tutorial at http://www.MartinRinehart.com/models/tutorial.

                      one-reply-to-this-post last-reply-time reply quote 0
                      • TIGT Offline
                        TIG Moderator
                        last edited by

                        What is your default html opening program ? Notepad++.exe ?

                        TIG

                        one-reply-to-this-post last-reply-time reply quote 0
                        • Dan RathbunD Offline
                          Dan Rathbun
                          last edited by

                          @martinrinehart said:

                          It opened the HTML, but it opened it in Notepad++.

                          This a problem specific to your machine Martin, because you have overridden the HTML &Open file association to open in Notepad++ instead of leaving it pointing to your default browser (IExpore).

                          You should have instead had the &Edit association pointing to Notepad++, and left the &Open as it was.

                          So it is not a problem for your users... it's personal problem. 🀣

                          To 'fix' it, open Windows Explorer, any folder (doesn't matter.)

                          • On Menu: Tools > Folder Options...* In "Folder Options" dialog, choose "File Types" tab.* [Windows will take a few mins to build the list]* In list, (with 1st item selected,) click the "H" key to scroll down to the H extensions.* scroll a bit more to show HTM and HTML extensions* highlight each in turn, click the "Advanced" button* In "Edit File Type" dialog, highlight "Open"* If it's NOT set to default, the "Set Default" button will be enabled, so click it to restore normal htm/html broswer open.* If it's set to default, the "Set Default" button will be greyed (disabled,) and it's properly set.I'm not sure if you will need to log off, and back on to see changes reflected.

                          I'm not here much anymore.

                          one-reply-to-this-post last-reply-time reply quote 0
                          • M Offline
                            MartinRinehart
                            last edited by

                            @dan rathbun said:

                            You should have instead had the &Edit association pointing to Notepad++

                            Folder Options has disabled what I need:

                            folder_options.jpg

                            I gave the user admin privileges, but that didn't help. I right-clicked in Explorer, Properties, and was able to change the default Open to a browser, getting openURL() working but that doesn't allow setting the Edit default.

                            Can I go back to KDE now?

                            Author, Edges to Rubies - The Complete SketchUp Tutorial at http://www.MartinRinehart.com/models/tutorial.

                            one-reply-to-this-post last-reply-time reply quote 0
                            • C Offline
                              cjthompson
                              last edited by

                              Just to make sure we aren't all going insane: what happens when you double click a .htm file?

                              one-reply-to-this-post last-reply-time reply quote 0
                              • M Offline
                                MartinRinehart
                                last edited by

                                I've set single click to open. An HTM opens in Chrome.

                                Author, Edges to Rubies - The Complete SketchUp Tutorial at http://www.MartinRinehart.com/models/tutorial.

                                one-reply-to-this-post last-reply-time reply quote 0
                                • Dan RathbunD Offline
                                  Dan Rathbun
                                  last edited by

                                  @martinrinehart said:

                                  Folder Options has disabled what I need:
                                  I gave the user admin privileges, but that didn't help.

                                  You can try going to Control Panel and right-click "Folder Options" and choose "Run As...", then pick an Administrative account to run this one applet as. (This is called running with "Elevated Privileges" in 'MS MicroSpeak'; and is more secure than having a user account always running with Administrative rights. Those slimeballs who write Trojans love people who always run with Administrative rights, especially when when connected to the Internet.)

                                  Also there is a wizard for controlling browser setings called "Set Program Access and Defaults", if you can find it on the Start Menu, you can also right-click it's icon and "Run As..."
                                  (It's actually a sub-routine of "Add/Remove Programs" and appears as the bottom button in it's left toolcolumn.) The program to run, if you have to actually right-click the file, in order to "Run As...", is:
                                  %SystemRoot%\system32\appwiz.cpl
                                  The shortcut command (in case you can't find it in your menus, and want to make a shourtcut,) is:
                                  %SystemRoot%\system32\control.exe appwiz.cpl,,3

                                  I'm not here much anymore.

                                  one-reply-to-this-post last-reply-time reply quote 0
                                  • Dan RathbunD Offline
                                    Dan Rathbun
                                    last edited by

                                    @martinrinehart said:

                                    Now if only I can figure out how to specify both program and file ...

                                    Something like this (needs work for Mac, and can be wrapped in a method.)

                                    filename='somefile.html'
                                    path='C;/dir/dir'
                                    filepath=File.join(path,filename)
                                    
                                    if RUBY_PLATFORM.include?('mswin')
                                    #
                                    if Kernel.test(?d,"#{ENV['SystemRoot']}/ie9")
                                      browser="#{ENV['SystemRoot']}/ie9/iexplore.exe")
                                    elsif Kernel.test(?d,"#{ENV['SystemRoot']}/ie8")
                                      browser="#{ENV['SystemRoot']}/ie8/iexplore.exe")
                                    elsif Kernel.test(?d,"#{ENV['SystemRoot']}/ie7")
                                      browser="#{ENV['SystemRoot']}/ie7/iexplore.exe")
                                    elsif Kernel.test(?d,"#{ENV['SystemRoot']}/ie6")
                                      browser="#{ENV['SystemRoot']}/ie6/iexplore.exe")
                                    elsif Kernel.test(?d,"#{ENV['SystemRoot']}/ie5")
                                      browser="#{ENV['SystemRoot']}/ie5/iexplore.exe")
                                    else
                                      raise(Errno;;ENOENT,filepath)
                                    end
                                    #
                                    else # Mac
                                      # browser = ???
                                    end
                                    
                                    # open specific file in broswer
                                    f = IO.popen("#{browser} #{filepath}")
                                    

                                    EDIT: It looks like the PC browser location (for all versions) can be simplified to:
                                    browser = "#{ENV['ProgramFiles']}"<<'/Internet Explorer/iexplore.exe'
                                    It may be that the hidden system folder "Windows/ieX" is a install folder.

                                    I'm not here much anymore.

                                    one-reply-to-this-post last-reply-time reply quote 0
                                    • Dan RathbunD Offline
                                      Dan Rathbun
                                      last edited by

                                      @martinrinehart said:

                                      I've set single click to open. An HTM opens in Chrome.

                                      Hey Martin, what's the fullpath to the Chrome executable on your PC ??

                                      I'm not here much anymore.

                                      one-reply-to-this-post last-reply-time 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