sketchucation logo sketchucation
    • 登入
    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!
    🔌 Smart Spline | Fluid way to handle splines for furniture design and complex structures. Download

    Texture from url?

    已排程 已置頂 已鎖定 已移動 Developers' Forum
    39 貼文 10 Posters 6.2k 瀏覽 10 Watching
    正在載入更多貼文
    • 從舊到新
    • 從新到舊
    • 最多點贊
    回覆
    • 在新貼文中回覆
    登入後回覆
    此主題已被刪除。只有擁有主題管理權限的使用者可以查看。
    • V 離線
      Viskiz
      最後由 編輯

      Is there a way to load texture image from given url? Creating new texture using Sketchup Materials dialog is possible to paste image URL. Sketchup downloads image and makes texture. Unfortunetally it does not in ruby script. I've tried using NET:Http, or Open-uri libraries. It's OK till ruby is installed, but it does not work on computers with no ruby installed. Can someone help please?

       
      model = Sketchup.active_model
       materials = model.materials
       m = materials.add "Joe"
      #this works
       m.texture = "c;\\Materials\\Carpet.jpg"      
      #but this does not
       m.texture = "http://code.google.com/images/code_logo.png"  
      
      
      1 條回覆 最後回覆 回覆 引用 0
      • thomthomT 離線
        thomthom
        最後由 編輯

        What is the plugin doing - as a whole?
        I'm wondering if you might be able to make use of webdialogs - using XMLHttpRequest with Javascript.

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

        1 條回覆 最後回覆 回覆 引用 0
        • V 離線
          Viskiz
          最後由 編輯

          I have materials in web server and this script is used to create and apply material from server, using WebDialog. Is there a vay to create texture using webdialog, XMLHttpRequest and Javascript?

          1 條回覆 最後回覆 回覆 引用 0
          • thomthomT 離線
            thomthom
            最後由 編輯

            Yes, you could use a webdialog to that runs a Javascript that downloads the texture and use that temp file to create the texture.

            All though, there could very well be some better way within SketchUp Ruby. Though I'm not immediate ware of it.
            Just throwing in some ideas.

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

            1 條回覆 最後回覆 回覆 引用 0
            • V 離線
              Viskiz
              最後由 編輯

              Yes, i had this idea, but how to know the name and location of that tmp?

              1 條回覆 最後回覆 回覆 引用 0
              • TIGT 離線
                TIG Moderator
                最後由 編輯

                API can use the texture image file from a temp folder.
                You need to download the image file to that folder from the url.
                See Ruby on Rails http://www.ruby-forum.com/topic/133981
                http://snippets.dzone.com/posts/show/3994
                or
                http://crunchlife.com/articles/2009/01/07/another-ruby-image-scraper

                or here's some java script to download an image in a webdialog http://www.codingforums.com/archive/index.php/t-34531.html

                TIG

                1 條回覆 最後回覆 回覆 引用 0
                • V 離線
                  Viskiz
                  最後由 編輯

                  @tig said:

                  API can use the texture image file from a temp folder.
                  You need to download the image file to that folder from the url.
                  See Ruby on Rails http://www.ruby-forum.com/topic/133981
                  http://snippets.dzone.com/posts/show/3994
                  or
                  http://crunchlife.com/articles/2009/01/07/another-ruby-image-scraper

                  These links requires additional ruby libraries that regular Sketchup users does not have and may find difficult themselves to install them. I'd like to find a way to do this without using Sketchup unsupported Ruby libraries.

                  @attachment_data = open(url) #throws exception "Invalid argument", cause it requires 'open-uri' that Sketchup does not have.
                  

                  @unknownuser said:

                  or here's some java script to download an image in a webdialog http://www.codingforums.com/archive/index.php/t-34531.html

                  I need to get the file without interrupting user with "Save as" or another yet additional dialog

                  1 條回覆 最後回覆 回覆 引用 0
                  • TIGT 離線
                    TIG Moderator
                    最後由 編輯

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

                    TIG

                    1 條回覆 最後回覆 回覆 引用 0
                    • V 離線
                      Viskiz
                      最後由 編輯

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

                      1 條回覆 最後回覆 回覆 引用 0
                      • thomthomT 離線
                        thomthom
                        最後由 編輯

                        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 條回覆 最後回覆 回覆 引用 0
                        • B 離線
                          ben.doherty
                          最後由 編輯

                          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 條回覆 最後回覆 回覆 引用 0
                          • N 離線
                            NatBridge
                            最後由 編輯

                            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 條回覆 最後回覆 回覆 引用 0
                            • B 離線
                              ben.doherty
                              最後由 編輯

                              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 條回覆 最後回覆 回覆 引用 0
                              • TIGT 離線
                                TIG Moderator
                                最後由 編輯

                                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 條回覆 最後回覆 回覆 引用 0
                                • J 離線
                                  Jim
                                  最後由 編輯

                                  @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 條回覆 最後回覆 回覆 引用 0
                                  • J 離線
                                    Jim
                                    最後由 編輯

                                    @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 條回覆 最後回覆 回覆 引用 0
                                    • TIGT 離線
                                      TIG Moderator
                                      最後由 編輯

                                      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 條回覆 最後回覆 回覆 引用 0
                                      • J 離線
                                        Jim
                                        最後由 編輯

                                        @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 條回覆 最後回覆 回覆 引用 0
                                        • TIGT 離線
                                          TIG Moderator
                                          最後由 編輯

                                          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 條回覆 最後回覆 回覆 引用 0
                                          • J 離線
                                            Jim
                                            最後由 編輯

                                            @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 條回覆 最後回覆 回覆 引用 0
                                            • 1
                                            • 2
                                            • 1 / 2
                                            • 第一個貼文
                                              最後的貼文
                                            Buy SketchPlus
                                            Buy SUbD
                                            Buy WrapR
                                            Buy eBook
                                            Buy Modelur
                                            Buy Vertex Tools
                                            Buy SketchCuisine
                                            Buy FormFonts

                                            Advertisement