Sketchup and open-uri
-
I am interested in using open-uri to read models directly from the internet and then import them into sketchup. I followed the instructions on this forum about swapping the ruby dll in the sketchup folder and I installed Dan's loadpaths.rb and can require 'open-uri' and the rest of ruby core/libraries. However as soon as I make use of it Sketchup crashes. I have tried ruby 187 and 186, with binary and ascii with no luck, does this happen for everyone else?
<span class="syntaxdefault"></span><span class="syntaxkeyword">require </span><span class="syntaxstring">'sketchup'<br /></span><span class="syntaxkeyword">require </span><span class="syntaxstring">'open-uri'<br /><br /></span><span class="syntaxdefault">open</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"http://www.ruby-lang.org/"</span><span class="syntaxkeyword">) {|</span><span class="syntaxdefault">f</span><span class="syntaxkeyword">|<br /> </span><span class="syntaxdefault">f</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">each_line </span><span class="syntaxkeyword">{|</span><span class="syntaxdefault">line</span><span class="syntaxkeyword">| </span><span class="syntaxdefault">p line</span><span class="syntaxkeyword">}<br /> } </span><span class="syntaxdefault"></span>
-
Try to protect Sketchup with a
begin
..rescue
..end
block ??You should run your code within an Author namespace.
You might try a Thread.. they are much better than they were in old v1.8.0 under SketchUp before v8.
But basically, if the file is large, you may be causing a Stack Overflow.
-
Oh and there is an Sketchup::Importer class in the API that can help things.
Also there is the
LoadHandler
class, that you use with Sketchup::DefinitionList#load_from_urlI'd suggest the latter..
a) bring the remote model into SU as a component
b) then place an instance
c) explode the instance if needed
d) save the definition as a local skp (if desired)
e) remove the definition from the DefinitionList (if it will no longer be needed.) -
Sorry for the late reply.
So basicly what I want to do is upload files to and from a restful api using multipart/form data that are not in sketchup format.
ie, export obj file > upload to server > delete obj file
or
download stl file > import to sketchup > delete stl fileafter giving up on net stuff through ruby which all seemed to crash sketchup I started looking into accomplishing this through the web dialog with ajax. While it works for communicating with the api in other ways and solves a lot of my problems. It is still not possible to upload or download a file with out the file dialog (and for good reason) but I want something more seamless. So far the closest thing I have found is
GitHub - danawoodman/google-sketchup-file-downloader: [NOT MAINTAINED] A generic and reusable SketchUp Ruby C extension file downloading utility to be used within SketchUp plugins.
[NOT MAINTAINED] A generic and reusable SketchUp Ruby C extension file downloading utility to be used within SketchUp plugins. - danawoodman/google-sketchup-file-downloader
GitHub (github.com)
but it isn't working. Thanks for your help, I will keep at it and appreciate any more help
Thanks!
Advertisement