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

    Download RBZ file

    Scheduled Pinned Locked Moved Developers' Forum
    30 Posts 8 Posters 39.3k Views 8 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.
    • Dan RathbunD Offline
      Dan Rathbun
      last edited by

      @honkinberry said:

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

      I did. πŸ˜›

      πŸ‘ 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.)

      I'm not here much anymore.

      1 Reply Last reply Reply Quote 0
      • danielbowringD Offline
        danielbowring
        last edited by

        @dan rathbun said:

        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`

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

          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...

          TIG

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

            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 ?

            I'm not here much anymore.

            1 Reply Last reply Reply Quote 0
            • H Offline
              honkinberry
              last edited by

              Thanks TIG for the clear direction!

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

              
              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

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

                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...

                TIG

                1 Reply Last reply Reply Quote 0
                • H Offline
                  honkinberry
                  last edited by

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

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

                  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:

                  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

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

                    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, "w**b**")
                    writes binary-data properly on all platforms ? ...

                    TIG

                    1 Reply Last reply Reply Quote 0
                    • H Offline
                      honkinberry
                      last edited by

                      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

                      1 Reply Last reply Reply Quote 0
                      • X Offline
                        xiseb
                        last edited by

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

                        1 Reply Last reply Reply Quote 0
                        • Dave RD Offline
                          Dave R
                          last edited by

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

                          Etaoin Shrdlu

                          %

                          (THERE'S NO PLACE LIKE)

                          G28 X0.0 Y0.0 Z0.0

                          M30

                          %

                          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