Download RBZ file

Download RBZ file

Postby honkinberry » Sat Jan 26, 2013 11:06 pm

I'm so close to a really incredible idea here, could really use some help, especially if what I'm doing is futile.

Problem: No way for my plugin to automatically install updates.

Solution: Distribute RBZ file converted to an image file.

It would go something like this:
1. Rename .RBZ file to .RAW file
2. Convert .RAW file to .PNG (it will look like static at this point)
3. Import .PNG as Image
4. Save file as .SKP
5. Client downloads .SKP using definitions.load_from_url
6. Client saves out .PNG texture using TextureWriter
7. Saved .PNG converted back to .RAW
8. .RAW file renamed to .RBZ
9. Updated plugin installed with Sketchup.install_from_archive

Right now I am at step 7. (!!!)
The image file output by the TextureWriter is indeed the exact same file originally put in. (!!!!!)
Only now, I can't find a way to convert the PNG back to a RAW file.
I've been fiddling with different formats, BMP, TIFF, but can't find a good single resource for true lossless conversion in both directions. To proceed with this any further, it seems time to integrate something like libpng. TIFF also seems very promising, but again, I can't find a solid way to convert a TIFF back to a RAW.
But interestingly!!!! -- The TIFF is clearly very close to to the RAW format, you can actually see the PK header and folder names right there in the file.

So now it's looking like the next step is to port libpng to Ruby (or find a working one somewhere), and develop a Packager and Extractor.
But good time to pause and see what you all think!

Cheers,

--J
1

honkinberry 
 

Re: Download RBZ file

Postby Dan Rathbun » Sun Jan 27, 2013 3:01 pm

That is just plain crazy.

Example downloading and installing Aerilius' Texture Resizer:

(1) UI.openURL('http://sketchucation.com/forums/download/file.php?id=99653')

(2) Wait for file to be downloaded. (A loop is needed here too see when the filesize stops getting larger.)

(3) Windows XP:
Sketchup.install_from_archive(File.join(ENV['USERPROFILE'],'My Documents/Downloads/ae_TextureResizer_1_4_6.rbz'))
0
    I'm not here much anymore. But a PM will fire email notifications.
    User avatar
    Dan Rathbun 
    PluginStore Author
    PluginStore Author
     

    Re: Download RBZ file

    Postby Jim » Sun Jan 27, 2013 3:17 pm

    Seems like Dana's downloader is a better solution.

    https://github.com/danawoodman/google-s ... downloader

    I see thomthom has contributed - is it ready for general use?
    0
    Hi

    Jim 
    Global Moderator
     

    Re: Download RBZ file

    Postby TIG » Sun Jan 27, 2013 3:55 pm

    Dana's project seems to have completely stalled - if not died altogether...
    There are some other ideas in embryo...
    So we'll just have to wait and see where it all ends up...
    0
    TIG
    User avatar
    TIG 
    Global Moderator
     

    Re: Download RBZ file

    Postby Dan Rathbun » Sun Jan 27, 2013 6:39 pm

    TBD also made a change, and requested a pull, but Dana never did do the merge.
    0
      I'm not here much anymore. But a PM will fire email notifications.
      User avatar
      Dan Rathbun 
      PluginStore Author
      PluginStore Author
       

      Re: Download RBZ file

      Postby honkinberry » Mon Jan 28, 2013 5:14 am

      just plain crazy? wow, there's some strong words.

      Dan's solution, like usual, doesn't work on a Mac.
      It looks like ENV['HOME']/"Downloads" would be a starting point there, but I just don't like the sketchy looping until "filesize stops getting larger." (let alone the giant web browser window that pops up)

      And Dana's wildly complicated and non-working solution? What's there to say?

      Meanwhile, it's looking like the BMP file will work best for my purposes, as it should have minimal modification in creating/removing the header.

      So anyway, I guess I'll just keep this one to myself for now.
      Cheers,

      --J
      0

      honkinberry 
       

      Re: Download RBZ file

      Postby Dan Rathbun » Mon Jan 28, 2013 8:22 pm

      honkinberry wrote:just plain crazy? wow, there's some strong words.

      It was not meant as an insult. Just that your image solution seems rather convoluted, to me.

      honkinberry wrote:Dan's solution, like usual, doesn't work on a Mac.
      It looks like ENV['HOME']/"Downloads" would be a starting point there,...

      One way I use to create a PC HOME environment variable is:
      ENV['HOME']= ENV['USERPROFILE'] unless RUBY_PLATFORM =~ /(darwin)/i || ENV['HOME']
      That way path expansion using "~" and Ruby's File.expand_path() can work on the PC.

      One sticking point on the PC, under MS Windows: The name of the "Documents" or "My Documents" directory is language localized.

      This raises one of the peeves in the SketchUp API. Standard and User configurable path variables which I'd like as module constants within the UI module.
      Example:
      UI::DOWNLOAD_DIR
      .. or perhaps a UI::PATH sub-module with methods to get and set certain paths.

      honkinberry wrote:... but I just don't like the sketchy looping until "filesize stops getting larger."

      Granted... perhaps we need a better way to determine when the file is done downloading.

      honkinberry wrote:... (let alone the giant web browser window that pops up)

      I wonder if we could write a SketchUp WebDialog that could serve as a downloader?

      honkinberry wrote:And Dana's wildly complicated and non-working solution? What's there to say?

      Well on the Mac... is the cURL executable provided "out-of-the-box" ?
      (Dana's utility was firstly meant as a PC solution where the cURL DLL is not provided.)

      But, IMHO, what's the difference in having the user just go download and install the actual cURL lib, and a utility that uses a subset of it's code?

      I'd rather install [and I have,] the actual library. And then find or modify a Ruby binding for the actual cURL library.

      My preference at this time is for the CURB gem (which relies upon the URI Standard Ruby Library.)

      :idea:
      0
        I'm not here much anymore. But a PM will fire email notifications.
        User avatar
        Dan Rathbun 
        PluginStore Author
        PluginStore Author
         

        Re: Download RBZ file

        Postby honkinberry » Tue Jan 29, 2013 3:36 am

        My preference at this time is for the CURB gem (which relies upon the URI Standard Ruby Library.)
        :idea:


        Understood, and I would agree. But as that is not complete, I'm offering my solution as something that can get up and running quite quickly.

        I did find this:
        https://github.com/tario/imageruby

        From which I am in the process of extracting just the BMP writing and reading.
        Which reduces down the complexity of my solution to just this:
        use built-in File.Binary read and write capability, convert each byte to an integer, store integer as RGB bytes in a BMP file. And then of course reverse that after extraction.
        Which is looking to be no more than a couple hundred lines of code.

        So yes, not an ideal solution, but with very minimal coding I'll have RBZtoBMP and BMPtoRBZ.

        --J
        0

        honkinberry 
         

        Re: Download RBZ file

        Postby TIG » Tue Jan 29, 2013 10:55 am

        I still can't to see why you need to jump through all of these extra hoops :?
        Could you just download the RBZ [it's only a renamed ZIP] and then extract/install its contents with the built-in tools anyway...

        You really need to have something for the user to confirm - the whole of the raison d'être for javascript/java etc is to stop secretive invasive data transfer in/out www<>computer... In any case it's good manners... the user should feel in control, your tool advises about update availability, but they choose to update ?
        You could use a tiny webdialog located 'off-screen', so there is no need for a massive web-page... the trick is by-passing the main browser's checker dialog...
        This auto-opens a download prompt from an 'off-screen' web-dialog...
        Code: Select all
        <html><head></head><body><script type="text/javascript">
        window.onload = function(){document.location = 'http://sketchucation.com/forums/download/file.php?id=99653';}
        </script></body></html>
        I haven't tried this... But you could also think about definitions.load_from_url(url) with a 'LoadHandler', this will fail because the file type isn't a skp... BUT it might leave the downloaded RBZ file intact in the user's TEMP folder [easily found]... EDIT: I've now tried it it only works with components skp files, other file types stop it before it starts downloading ! Plan B...
        0
        TIG
        User avatar
        TIG 
        Global Moderator
         

        Re: Download RBZ file

        Postby driven » Tue Jan 29, 2013 12:36 pm

        @Tig,
        I have tested that in the past, and on a mac it works if you have a second/alternate download manager, it won't use safari's unless you use open_url, but that's not in the background (not a bad thing).
        When you do have a downloader available, the javascript function, never closes and SU runs at 96%, doing nothing until you quit the process. Not ideal.

        @ honkinberry I personally think you will encounter lots of issues with macs built in security,
        The extension name is primarily for applying the right file decoration, unix checks if the contents is valid, [especially since the hacker managed to bury a shell script in a PNG, posted on a forum, with "hey guys, has anyone seen this new iPhone secret pic, I won't download it because it looks suspicious".
        Loads of people went ahead and downloaded it, and it sent itself to every contact book address and they opened it and... etc...]

        If your an admin on your mac, you can do all sorts of masking, hiding, moving, on your mac. But that won't mean it will work on anyone else's, some might some won't ever... unless there is a user request to allows it.

        I think Fredo's method is the best for user plugins at the moment, or just pop an options box asking if the user wants the download.

        I use 'Little Snitch' and I get notifications for every attempted download from the system, I remove software that hasn't asked me if it can do that.

        I don't know what's possible on Windows but you can have SU automatically install any .rbz that's download to a mac.
        i.e. download a .rbz (programatically or manually), SU opens on Prefs Dialog, then opens on the download, then installs the download. You just need to set up an Automator Service to do that, and call it from your ruby. System may pop a notice or not depending on the receiving Users security prefs...

        john
        0
        learn from the mistakes of others, you may not live long enough to make them all yourself...

        driven 
        PluginStore Author
        PluginStore Author
         

        Re: Download RBZ file

        Postby honkinberry » Tue Jan 29, 2013 8:19 pm

        I think there's still some confusion on what I am proposing, so let me try this again.

        Again, Problem -- no ability for a WebDialog (on a Mac) to say, "Hey, trusted user, there is an updated version of this plugin available, would you like to install it now?" (okay, yes, I can open up another giant browser window to my download page, and then the user can click the downloaded file, and might then have to choose to open it with Sketchup, or wade through Preferences.... omg! I just want an easy updater, right???)

        So, Solution -- I encode the RBZ as a BMP file -- this is simple process, that doesn't need to be done with Sketchup Ruby, but might as well. The Binary File functions are used to read in the file, and then store each byte as an integer, into a valid BMP file.
        (This is technically a form of Steganography. It will defeat any security system, as it is a *legitimate* BMP -- it will just look like static to the eye. One could technically go a level further and embed the binary file within an *actual* image, being a level of Steganography used by spy agencies and terrorists and such, but I'm not proposing going that far.)
        Now a BMP file, it is easy to import into a blank SKP file.
        And as an SKP file, I can download it in the background with load_from_url (heck, even with a progress bar and full error control!).
        Once that file is downloaded, I can write out the image using TextureWriter. Again, there is no security issues, as this is a legitimate BMP file.
        Lastly, a little Ruby routine again uses the binary File reader to read in the binary data, and then write it back, this time as a RBZ file.
        Alas, now a local RBZ file, it can be passed off to install_from_archive.

        And most importantly, I'm certainly not saying this is ideal!
        The last thing I want is to write a couple thousand lines of code, only to have SU9 come out with http support in the install_from_archive function.
        I'm merely proposing that in only writing a simple binary BMP reader/writer, I can be up and running with a *workable* background plugin updater, cross-platform.

        But hey, it's cool if you don't like the idea. You certainly don't have to use it to distribute updates to your own plugins. But you have confirmed for me that there is not a workable alternative, so at least I'm not completely chasing windmills.

        Cheers,

        --J
        0

        honkinberry 
         

        Re: Download RBZ file

        Postby TIG » Wed Jan 30, 2013 11:10 am

        This approach requires you to make special version of every RBZ archive as an 'image' and then use special 'unpacking' code at the Ruby end... :?

        There are alternatives that can use just SketchUp's basic Ruby and OS tools on an RBZ file itself... At the download Ruby end you have your code write a short temporary 'script' to download the RBZ in the background and install it:-

        On a PC - write a temporary VBS script that you then execute with UI.operURL() to download the RBZ, this is straightforward provided the html path ends with the 'filename.rbz' and it isn't redirected by ..?id=123456 etc. The downloaded file can go into the user's Temp folder [to check it's completed before installing it you can add a temp 'done' file maker after the main VBS code and Ruby can then wait until that exists in the Temp folder, then it can delete it and continue with the installation - trap for failure etc so it doesn't lock up], then you can complete the installation of it from using the RBZ archive installing code in the v8 API. Here's an example:
        Code: Select all
        Call DownloadFile("http://..../abc.rbz")
        ' The Ruby side adjusts this first line to suit the actual url.
        ' The Ruby only runs if url it has only ends in say .rbz !
        ' the function will then download that file to the user's usual temp folder.
        Function DownloadFile(DownloadUrl)
           'Get name of file from url (whatever follows the final forwardslash "/")
           Dim arURL, outputArray, x, FileName, FileSaveLocation
           arURL = Split(DownloadUrl,"/",-1,1)
           If arURL(UBound(arURL)) = "" Then 'if there is a trailing forwardslash
              FileName = arURL(UBound(arURL) -1)
           Else
                        ' in case there's a redirect, but with a file-name "file=abc.rbz" etc
              outputArray = Split(arURL(UBound(arURL)), "=")
              for each x in outputArray
                FileName = x
              next
           End If
           'Get temp folder location
           Dim oFS, TempDir
           Set oFS = CreateObject("Scripting.FileSystemObject")
           Set TempDir = oFS.getSpecialFolder(2)
           FileSaveLocation = TempDir & "\" & FileName
           ' Wscript.Echo FileSaveLocation ' unrem this line to test to see temp file path
           ' Fetch the file
           Dim oXMLHTTP, oADOStream
           Set oXMLHTTP = CreateObject("MSXML2.XMLHTTP")
           oXMLHTTP.open "GET", DownloadUrl, false
           oXMLHTTP.send()
           If oXMLHTTP.Status = 200 Then
              Set oADOStream = CreateObject("ADODB.Stream")
              oADOStream.Open
              oADOStream.Type = 1 'adTypeBinary
              oADOStream.Write oXMLHTTP.ResponseBody
              oADOStream.Position = 0 'Set the stream position to the start
           If oFS.Fileexists(FileSaveLocation) Then oFS.DeleteFile FileSaveLocation
              Set oFS = Nothing
              oADOStream.SaveToFile FileSaveLocation
              oADOStream.Close
              Set oADOStream = Nothing
           End if
           Set oXMLHTTP = Nothing
        End Function

        On a MAC - you do much the same as the PC, but now you'll need to execute a temporary Applescript to do the silent download. Ruby first compiles the 'reference' details [URL/TempFile] and makes a line of code... MAC users can advise best on this [driven?] - something like:
        tell application "URL Access Scripting" to download "#{theURL}" to "#{theTempFile}" which I think can be run on a MAC Ruby as something like system `...` ?
        0
        TIG
        User avatar
        TIG 
        Global Moderator
         

        Re: Download RBZ file

        Postby honkinberry » Wed Jan 30, 2013 7:00 pm

        I'm well aware of how to download a file use ADO Data Streams.
        Would you like to run our Tech Support for a day, and deal with the myriad of people who have Security issues with it? It's the oADOStream.SaveToFile that most commonly gets snagged, and just doesn't have the ability to save to where I'd like it to. Then you end up using VBS File objects to move it around, or CIM.... oh, and wait, then you have the File object locked down, or the Domains where VBS is just not responding at all. In the mood to do a remote session with a machine in China or Dubai, where their internet is *really* locked down, and you have to use a Start menu in a foreign language? Trust me, it's not fun, and ADO is a security nightmare waiting to happen.

        I've just spent the last couple weeks re-engineering our Component delivery system to *not* use ADO anymore, and oh my gosh is it a better system. ***Loving*** load_from_url, such a more elegant solution.

        Anyway, I'll have some code for y'all within about a week or so, and you can judge then whether it's more or less bulletproof than any of these other solutions.

        --J
        0

        honkinberry 
         

        Re: Download RBZ file

        Postby Dan Rathbun » Wed Jan 30, 2013 7:39 pm

        honkinberry wrote: ***Loving*** load_from_url, such a more elegant solution.

        We'll if I was tasked with using a component via load_from_url(), to d/l and install a plugin... I would not convert Ruby to BMP or any other image.

        Ruby scripts are text.. even scrambled rbs files.

        I would TRY saving the plugin information (folder & file names etc.,) and the script text blocks themselves, into an attribute dictionary, and write out a "plugin" component definition, that has only this attribute dictionary.

        Then download it via load_from_url using a custom LoadHandler class.
        The onSuccess() callback would just use standard Ruby Dir and File classes to create the directories, and write out the script text files, using the fields of the attributes attached to the component definition.

        If the definition contained images (within it's entities, or textured materials,) ... I would assume them to be toolbar button images etc., and they would be written out as images (using a custom TextureWriter class.)

        When done, the definition is deleted, and the user is asked if they wish to load the plugin at that time.

        :idea:

        ADD: I suppose an entire RBZ file could be written as one attribute value... it's worth a try.
        0
          I'm not here much anymore. But a PM will fire email notifications.
          User avatar
          Dan Rathbun 
          PluginStore Author
          PluginStore Author
           

          Re: Download RBZ file

          Postby TIG » Wed Jan 30, 2013 7:59 pm

          The definitions.load_from_url works just fine - for components - I've used it a lot... BUT you can't get it to do much else...
          The download will fail if the .skp isn't 'valid' and the downloaded file is auto-deleted !

          Having an effectively 'empty' skp, with an attribute-dictionary containing the data might work, but isn't there a data size limit ?
          BUT assuming that the RBZ file's data is of an acceptable size [or it is spread across several attributes which get recombined later]... then the 'Dan' trick might just work... :o
          0
          TIG
          User avatar
          TIG 
          Global Moderator
           

          Re: Download RBZ file

          Postby honkinberry » Thu Jan 31, 2013 3:01 am

          So rather than encode a single RBZ file as a BMP, and allow SU's built in install_from_archive,
          Dan is proposing I maintain a file schema of the... (at last count 100+) files involved in my plugin, write them all out to the correct location.... agh, that sounds frustrating. How are you proposing I maintain the file manifest? I suppose another unusual trick, like storing it as Text objects in the Model?

          I'll get you guys to come around to my idea... eventually.... :)

          --J
          0

          honkinberry 
           

          Re: Download RBZ file

          Postby Dan Rathbun » Thu Jan 31, 2013 7:30 pm

          honkinberry wrote: I suppose another unusual trick, like storing it as Text objects in the Model?

          It is quite normal to store text data in an AttributeDictionary

          The approach I am thinking about, does not actually add entities into the model's entities collection.

          AND... this is this first we are hearing that you have 100+ files.

          We are just brain-storming here.

          Do what you wish.. have fun.
          0
            I'm not here much anymore. But a PM will fire email notifications.
            User avatar
            Dan Rathbun 
            PluginStore Author
            PluginStore Author
             

            Re: Download RBZ file

            Postby TIG » Sat Feb 02, 2013 7:17 pm

            Out of interest I tried writing some methods that to my surprise worked effectively.
            One that encodes the RBZ file as hex strings in a number of attribute keys in a dictionary attached to a SKP - it's an all but empty file otherwise [a guide-point is need so it's not seem as empty by the loader].
            The others are as some connected methods used in any SKP later on - one that uses load_from_url to add a temporary-definition of the remote SKP into the current model.definitions without need for further user interaction [after a callback action from a webdialog button], the definitions attributes are got and recombined into the needed data, and the definition is deleted from the model.
            The data is written out into a RBZ in the user's Temp folder and then auto-installed from that archive...
            So to recap, you make a SKP containing the RBZ's data as a attribute key values, you temporarily load that SKP from a url and extract the RBZ's data, recombining it into a local file in a Temp folder, from where it can be auto-installed into Plugins...
            The only downside I can see is that the SKP is considerably bigger than the RBZ as the data is 'hexed' ~3.7x, but a 2Mb RBZ would be quite unusual ?
            0
            TIG
            User avatar
            TIG 
            Global Moderator
             

            Re: Download RBZ file

            Postby honkinberry » Wed Feb 06, 2013 4:52 am

            Tig, that's brilliant, I wouldn't have thought of that.
            That's very much the same approach, just a bit cleaner.
            Yes of course there's a bit of loss in file file size, but it's all about the capability gain here.
            Having an integrated update solution gives a much more professional and complete experience to the user.
            Very nice. Would you care to share some of your code?

            --J
            0

            honkinberry 
             

            Re: Download RBZ file

            Postby Dan Rathbun » Wed Feb 06, 2013 5:41 am

            honkinberry wrote:Tig, that's brilliant, I wouldn't have thought of that.

            I did. :P

            :thumb: to TIG for proving the concept.

            @TIG: Do you need to hex encode it?

            Would it help you, if you had Zip / Unzip methods in Ruby ? (I can PM them to you.)
            0
              I'm not here much anymore. But a PM will fire email notifications.
              User avatar
              Dan Rathbun 
              PluginStore Author
              PluginStore Author
               

              Re: Download RBZ file

              Postby danielbowring » Wed Feb 06, 2013 7:45 am

              Dan Rathbun wrote:Do you need to hex encode it?


              Unless you're sure there is no null character, you'll have to hex encode it or Sketchup will only store up to the first null character. Binary files will probably have plenty of nulls in them.

              Here's a sample of how SketchUp deals with the situation:
              nullstr = 'My Test ' + 0.chr + ' String'
              puts nullstr.inspect
              # => "My Test \000 String"
              puts nullstr.length
              # => 16
              Sketchup.active_model.set_attribute('test', 'nullstr', nullstr)
              nullstr2 = Sketchup.active_model.get_attribute('test', 'nullstr')
              puts nullstr2.inspect
              # => "My Test "
              puts nullstr2.length
              # => 8
              puts 'My Test '.length
              # => 8
              0
              User avatar
              danielbowring 
               

              Re: Download RBZ file

              Postby TIG » Wed Feb 06, 2013 10:55 am

              I already tested it, and I used:
              data = open(path,"rb"){|io|io.read}.unpack('H*').to_s
              The 'path' is the file path to the RBZ file.
              Although an attribute value can be an array it is made into a string because it could need splitting into 'chunks', because there's an attribute value size limit [I use ~20,000 chars] - you will get Bugsplats if it's much bigger [test it to see] - these 'chunks' are written into sequentially named attribute keys/values attached to the current model...

              Later after the 'attributed' model's SKP has been added to a new model's definition using the API's load_from_url() methods accessed via awebdialog etc. It's then easy to extract the sequentially named 'chunks' from that new definition's attribute keys/values, recombining those into a single string, here named 'data', and then to remake the binary code 'string' using:
              datab = [data].pack('H*')
              This 'string' is then written into a new temp RBZ file...
              Finally the temp definition can be deleted, and the RBZ file auto-installed using the API methods added in v8M2, before it too is deleted from the user's Temp folder...

              The only downside to this is that the 'empty' SKP that has been 'attributed' is ~3.7x bigger than the original RBZ file, simply because of the unpack of its data into hex... BUT on the upside you can use it to encrypt, download and install an RBZ [masquerading as a SKP] from a URL without any user dialogs intervening etc; simply from a single user button-click in a webdialog running a callback to do the load_from_url(), or less secure when the page opens and no user involvement at all...
              0
              TIG
              User avatar
              TIG 
              Global Moderator
               

              Re: Download RBZ file

              Postby Dan Rathbun » Wed Feb 06, 2013 11:52 pm

              I guess my question should be more specific.

              Can the file's data be escaped rather than hex encoded ?
              Could the printable characters could remain as they are... but the non-printables (including null,) could be escaped ?
              0
                I'm not here much anymore. But a PM will fire email notifications.
                User avatar
                Dan Rathbun 
                PluginStore Author
                PluginStore Author
                 

                Re: Download RBZ file

                Postby honkinberry » Tue Feb 12, 2013 7:43 pm

                Thanks TIG for the clear direction!

                It absolutely does work, with my quick and dirty (no error handling yet) version like so:

                Code: Select all
                def encoderbz ()
                   chunksize = 2**14 # attrib data doesn't like more than ~20kb, so we limit each chunk to 16k

                   if ( file = UI.openpanel "Select RBZ file to encode" )
                      data = open(file) {|io|io.read}.unpack('H*').to_s # hex encode, converted to string
                      model = Sketchup.active_model
                      i = 0
                      while data and data != ""
                         i = i + 1 # counter
                         d = "d" + i.to_s # name of attribute
                         chunk = data[0,chunksize] # chunk of data
                         data = data[chunksize..-1] # trim master data
                         model.set_attribute 'rbz',d,chunk
                      end # while
                      # and set the next one to nil in case user is updating with a smaller rbz
                      i = i + 1
                      d = "d" + i.to_s
                      model.set_attribute 'rbz',d,nil

                      UI.messagebox "The selected RBZ file has been successfully encoded into the current model."
                   end # if
                end # encoderbz

                def decoderbz ()
                   model = Sketchup.active_model
                   i = 1 # counter
                   d = "d" + i.to_s # name of attribute
                   data = "" # to assemble the chunks
                   while dx = model.get_attribute('rbz',d)
                      data = data + dx

                      i = i + 1
                      d = "d" + i.to_s # name of attribute
                   end # while

                   if ( data != "" )
                      datab = [data].pack('H*')
                      if ( filename = UI.savepanel "Save RBZ As...","","*.rbz" )
                         file = File.open(filename, "w")
                         file.write(datab)
                         file.close
                         
                         UI.messagebox "The enclosed RBZ has been successfully saved out as an RBZ file."
                      end # if
                   end # if
                end # decoderbz



                Yes, there is a size overhead of about 4x, but the hex encoding does feel a very bulletproof way of doing this.
                Certainly a bit easier than my initial thought of encoding as an image, but same basic idea.

                Thanks all for the help and patience! This definitely raises the quality of the plug-in to a more professional level.

                --J
                0

                honkinberry 
                 

                Re: Download RBZ file

                Postby TIG » Tue Feb 12, 2013 7:54 pm

                Since my last ideas I think the better way to ensure an 'empty' SKP.
                It'll work in any SKP too...
                In code...
                Inside a model_start/commit block...
                Make a new definition.
                Set its name to RBZ.basename + '.skp'
                Add a cpoint to definition.entities.
                Add the attributes to the definition.
                Do a 'save_as' on definition into the same folder as the RBZ file.
                The new SKP has the RBZ attached as attribute key[s]...
                Do a definition.entities.clear! so it's removed from the Browser...

                Done.

                The import is much as you outlined...
                0
                TIG
                User avatar
                TIG 
                Global Moderator
                 

                Re: Download RBZ file

                Postby honkinberry » Fri Mar 29, 2013 3:01 am

                Well, snap, not working on the PC side.
                Mac side is flawless.

                Given my 106k RBZ file, and this line of code:

                Code: Select all
                data = open(file) {|io|io.read}.unpack('H*').to_s


                On the Mac, data.length is 207954
                While on the PC, data.length is 18216

                And then there's issue on the other end too.
                I'll have to assume it's here:

                Code: Select all
                datab = [data].pack('H*')


                It's adding a bunch of 0D's in there, good ol' Chr(13), carriage returns.
                At least it seems it is there, I suppose it could be in the actual file.write(datab) ?
                But it's adding about 352 of them in that 106k file.

                Soooooooooo close!
                Any brilliant ideas?

                (And in case you're wondering how it is on the Mac side where it works? Um, it's amazing, in a word.)

                --J
                0

                honkinberry 
                 

                Re: Download RBZ file

                Postby TIG » Fri Mar 29, 2013 1:15 pm

                Hint:
                File.open(filename, "w")
                writes binary OR strings on MAC/Unix BUT only strings on PC [messing up any binary-data]
                BUT
                File.open(filename, "wb")
                writes binary-data properly on all platforms ? ...
                0
                TIG
                User avatar
                TIG 
                Global Moderator
                 

                Re: Download RBZ file

                Postby honkinberry » Fri Mar 29, 2013 6:26 pm

                That did it!
                You're a genius!

                It's probably a similar problem on the encoding side, but I'm okay with keeping the development station as a Mac.

                Thanks as always.

                --J
                0

                honkinberry 
                 

                Re: Download RBZ file

                Postby xiseb » Mon Nov 04, 2019 6:08 pm

                Good day pple i downloaded plugins for sketchup 2016 but they came as .skp files how do i install them on wondows
                0

                xiseb 
                 

                Re: Download RBZ file

                Postby Dave R » Mon Nov 04, 2019 8:29 pm

                What plugins did you download? Plugins won't download as .skp files. That would indicate you've downloaded SketchUp models/components.
                0
                Etaoin Shrdlu


                %

                (THERE'S NO PLACE LIKE)

                G28 X0.0 Y0.0 Z0.0

                M30

                %
                User avatar
                Dave R 
                Global Moderator
                 

                SketchUcation One-Liner Adverts

                by Ad Machine » 5 minutes ago



                Ad Machine 
                Robot
                 



                 

                Return to Developers' Forum

                Who is online

                Users browsing this forum: No registered users and 7 guests

                Visit our sponsors: