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

    Texture from url?

    Scheduled Pinned Locked Moved Developers' Forum
    39 Posts 10 Posters 5.6k Views 10 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.
    • TIGT Offline
      TIG Moderator
      last edited by

      The javascript version 'executes' 'save_as' you could look for a 'save' equivalent ?

      TIG

      1 Reply Last reply Reply Quote 0
      • V Offline
        Viskiz
        last edited by

        I could not find such function, that save file without interruption. I don't think it's possible.

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

          How about:

          • Download the image using HTTPRequest
          • Put the data into a hidden input field. (possibly base64 encoded? - since you are dealing with binary data)
          • Use WebDialog.get_element_value to fetch the data
          • Save to a temp file with the Ruby File class

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

          1 Reply Last reply Reply Quote 0
          • B Offline
            ben.doherty
            last edited by

            Hi, I'm trying to do something similar.
            I'm not too fussed about using non sketchup ruby libraries, so I just want to do it in the most elegant way possible.

            I tried adding:
            $LOAD_PATH << "C:/Ruby186/lib/ruby/1.8/net"
            $LOAD_PATH << "C:/Ruby186/lib/ruby/1.8/i386-mingw32"
            to my load paths as a way to crunch through the error messages that I got (couldn't find socket etc.)

            Is there an easy way to do this that is nice and easy and clean?

            1 Reply Last reply Reply Quote 0
            • N Offline
              NatBridge
              last edited by

              Maybe you could just open the webdialog to the image url and screenshot it? (If it isn't bigger than the screen.)

              http://code.google.com/apis/sketchup/docs/ourdoc/webdialog.html#write_image

              1 Reply Last reply Reply Quote 0
              • B Offline
                ben.doherty
                last edited by

                That would probably work, but wouldn't win any prizes for elegance.
                Given that ruby can access things on the internet as part of it's core library does anyone have any idea how to point it at those standard libraries?

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

                  Here's a discreet way of downloading an image file from a url on Windows only - using vbs...

                  strFileURL = "http://www.it1.net/images/it1_logo2.jpg"
                  strHDLocation = "C;\Temp\it1_logo2.jpg"
                  Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP")
                  objXMLHTTP.open "GET", strFileURL, false
                  objXMLHTTP.send()
                  If objXMLHTTP.Status = 200 Then
                    Set objADOStream = CreateObject("ADODB.Stream")
                    objADOStream.Open
                    objADOStream.Type = 1 'adTypeBinary
                    objADOStream.Write objXMLHTTP.ResponseBody
                    objADOStream.Position = 0    'Set the stream position to the start
                    Set objFSO = Createobject("Scripting.FileSystemObject")
                  If objFSO.Fileexists(strHDLocation) Then objFSO.DeleteFile strHDLocation
                    Set objFSO = Nothing
                    objADOStream.SaveToFile strHDLocation
                    objADOStream.Close
                    Set objADOStream = Nothing
                  End if
                  Set objXMLHTTP = Nothing
                  

                  Make a copy of this text in a file that's called say
                  C:\Temp\urldownloader.vbs
                  or another Temp folder etc...
                  Change the first two lines of the text to be the url [I've used a known image_file simply to show that it works] and the folder+filepath to save that file to - in this example I put it into C:\Temp\ too using the same file_name...
                  Now run it from within Ruby
                  UI.openURL("C:\\Temp\\urldownloader.vbs")
                  In Ruby wait till the file arrives - timeout after a while ?
                  To tidy up you can delete the temp file...
                  It works - I have run it successfully...

                  TIG

                  1 Reply Last reply Reply Quote 0
                  • J Offline
                    Jim
                    last edited by

                    @ben.doherty said:

                    Is there an easy way to do this that is nice and easy and clean?

                    Nothing is easy. πŸ˜†

                    You have the right idea, but I think you may need to add more locations to make it complete. If you check the $LOAD_PATH of your installed Ruby, you'll find it has more locations than just those you listed. See Dan's post on the subject. We should have more success using the installed Ruby since we now have 1.8.6 in SketchUp and an installable 1.8.6

                    Hi

                    1 Reply Last reply Reply Quote 0
                    • J Offline
                      Jim
                      last edited by

                      @tig said:

                      Here's a discreet way of downloading an image file from a url on Windows only - using vbs...

                      VBScript will run in the WebDialog, so you could eliminate the external file. But I would still try to follow Thom's advice, use JavaScript, and pass the data to the Ruby plugin to save it on disk.

                      Hi

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

                        My 'vbs' method means you don't actually need a web-dialog running at all.
                        You can download images from a url with it [on PC] irrespective of what the Ruby script is doing or has as an interface... πŸ˜•

                        TIG

                        1 Reply Last reply Reply Quote 0
                        • J Offline
                          Jim
                          last edited by

                          @tig said:

                          [on PC]

                          Exactly.

                          The most beneficial result from this thread would be a cross-platform download library which could be used for images or anything, really.

                          Hi

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

                            But the original inquiry was 'for PC' ?
                            A pure Javascript version can't work [?] - because of security issues there is no plain 'save' - only 'save_as', to you ensure you know what's going on with downloading things off the www onto your PC...
                            The 'vbs' method will work for PC - there's probably an equivalent AppleScript [type] method for the MAC... but I can't see how a 'cross-platform' version might work πŸ˜•
                            Java is inherently 'limited' as I said...

                            TIG

                            1 Reply Last reply Reply Quote 0
                            • J Offline
                              Jim
                              last edited by

                              @tig said:

                              A pure Javascript version can't work [?]

                              I think it can. There is no save or save as in JavaScript. You can save to disk using JavaScript, but there isn't a cross-platform solution. On Windows, you would use a FileSystem activex object. The same scripting host that rtuns the .vbs can run .js also.

                              But, the XHR is available on all (important) browser platforms. So a cross-platform solution is to use a WebDialog, fetch the file using the XHR, then pass it to the ruby plugin for saving to disk.

                              This small library is a good example of using a XHR cross-platform:
                              http://code.google.com/p/microajax/

                              
                              if (window.ActiveXObject)
                              return new ActiveXObject('Microsoft.XMLHTTP');
                              else if (window.XMLHttpRequest)
                              return new XMLHttpRequest();
                              return false;
                              
                              

                              Hi

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

                                What's this then ?
                                <a href="java script&#058;void(0);" onclick="document.execCommand('SaveAs',true,'http://fileden.com/somefolder/some file.mp3');">download</a>
                                There's just not a 'Save' version ???

                                TIG

                                1 Reply Last reply Reply Quote 0
                                • J Offline
                                  Jim
                                  last edited by

                                  I've never heard of "execCommand" before, but I'd be surprised if it were cross-platform. If it existed, we probably wouldn't be having this discussion.

                                  Hi

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

                                    Perhaps a MAC users could confirm...

                                    TIG

                                    1 Reply Last reply Reply Quote 0
                                    • B Offline
                                      ben.doherty
                                      last edited by

                                      While the JS debate rages, I've been playing with what can be done with ruby (being single-minded/stubborn/lazy)

                                      I've updated my !loadpaths file to match dan's latest http://forums.sketchucation.com/viewtopic.php?f=180&t=29412&hilit=load+path#p257058
                                      and when I try a couple of things I get this response:
                                      require 'net/http' Error: #<LoadError: C:/ruby186/lib/ruby/1.8/net/protocol.rb:21:inrequire': No such file to load -- socket>
                                      C:/ruby186/lib/ruby/1.8/net/protocol.rb:21
                                      require 'date/format'
                                      true`

                                      Any ideas on why net/http fails, but date/format works?

                                      I'm sure it will take some clever file management, and refresh cycle control etc, but it'd be cool to be able to specify a url to get a texture from. That'd open up a load of opportunities for data vis etc.

                                      1 Reply Last reply Reply Quote 0
                                      • J Offline
                                        Jim
                                        last edited by

                                        That means it couldn't find the file (socket.so) in the load path.

                                        For a short-term solution, you could try to copy socket.so to the Plugins folder.

                                        Hi

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

                                          @jim said:

                                          I've never heard of "execCommand" before, but I'd be surprised if it were cross-platform. If it existed, we probably wouldn't be having this discussion.

                                          It's HTML 5 me thinks. And seems Microsoft may have added a bunch of standard CommandIDs without getting them approved by the web community (as usual.) The spec implies browser specific IDs should have a prefix like "IE-", but MS has been doing this 'arm-twisting' for years.

                                          See: http://www.w3.org/TR/html5/author/dom.html#execCommand

                                          MSDN: http://msdn.microsoft.com/en-us/library/ms536419(v=VS.85).aspx
                                          and MS' command IDS: http://msdn.microsoft.com/en-us/library/ms533049(v=VS.85).aspx
                                          ~

                                          I'm not here much anymore.

                                          1 Reply Last reply Reply Quote 0
                                          • B Offline
                                            Ben_M
                                            last edited by

                                            Hello!

                                            Has anyone made any progress on a simple, cross platform solution to this in the past few months?

                                            Thanks,

                                            Ben

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

                                            Advertisement