sketchucation logo sketchucation
    • Login
    šŸ¤‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    How can I store binary data in an attribute

    Scheduled Pinned Locked Moved Developers' Forum
    7 Posts 4 Posters 887 Views 4 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.
    • Al HartA Offline
      Al Hart
      last edited by

      I would like to store a "binary" String (which use all values 0-255 for each character) in a SketchUp attribute.

      SketchUp seems to truncate String attributes which contain a 0, and also seems to convert strings to multi-byte format when they are in extended ansi format.

      We currently are converting our "binary" strings to hex strings - but this involves a 2 to 1 increase in size.

      I have tried "unpacking" the string into an array of FixNums using L* and N* format, which should have created FixNum's - but "unpack" created some BigNum's which SketchUp won't process.

      Has anyone found a way to store binary data in an attribute without having to hex encode it?

      Al Hart

      http:wiki.renderplus.comimageseefRender_plus_colored30x30%29.PNG
      IRender nXt from Render Plus

      1 Reply Last reply Reply Quote 0
      • fredo6F Offline
        fredo6
        last edited by

        I had the same problem with binary strings, because Sketchup stops the decoding at first \0 character.

        But if you just wish to store an array of fixnum, why don't you store it 'naturally'. Sketchup entity attributes does it well, back and forth. I used this for my bezierspline.rb macro, where I do store arrays of 3D-points in this way.

        1 Reply Last reply Reply Quote 0
        • T Offline
          todd burch
          last edited by

          You can convert to hex, or use #pack('m') when storing and unpack('m') on the way back out.

          You might could also Marshal the data.

          Todd

          ps Fred, if you are saving 3D points as attributes - what happens when a user moves the spline?

          1 Reply Last reply Reply Quote 0
          • C Offline
            CPhillips
            last edited by

            I have stored successfully binary data in attributes. Specifically a matrix.

            I did find a bug in get/set_attribute() that would cause the character 0x0d ('\n') to be replaced with 0x0d 0x0a. I got around it by replacing '\n' with 'I_AM_0D' in the string before packing. And of course reversing it after unpacking.

            Hope that helps.
            Chris

            1 Reply Last reply Reply Quote 0
            • fredo6F Offline
              fredo6
              last edited by

              @unknownuser said:

              ps Fred, if you are saving 3D points as attributes - what happens when a user moves the spline?

              Very interesting question, that I did not ask myself (actually, I just inherited the method from the previous bezier.rbscript by @Last). But magically, it seems to work fine, whether you move, scale or rotate the curve.

              There must be a trick!

              But this macro is full of surprise, for instance with an undocumented method "curve.move_vertices", which allows moving the vertices of a curve without having to recreate one.

              1 Reply Last reply Reply Quote 0
              • Al HartA Offline
                Al Hart
                last edited by

                I am trying to store a raster image on a material to use as a bump map when rendering.

                Since raster images (.jpg or .png files) can be large, I am trying to store it without making it too much bigger.

                We are currently converting it to a hex string, which makes it twice as large.

                You cannot store 4 binary bytes in a ruby fixnum because ruby only stores 31 bits in a Fixnum, before it switched to a bignum, which is longer than 1 word. And you cannot store a Bignum as a SketchUp attribute.

                Try:

                
                model = Sketchup.active_model
                i1 = 0xaabbccdd # 32 bit integer, which cannot be stored in a Fixnum
                puts i1.class
                # returns 'Bignum'
                model.set_attribute('test','bignum',i1)
                # returns Error; #<RangeError; bignum too big to convert into `int'>
                
                

                Al Hart

                http:wiki.renderplus.comimageseefRender_plus_colored30x30%29.PNG
                IRender nXt from Render Plus

                1 Reply Last reply Reply Quote 0
                • T Offline
                  todd burch
                  last edited by

                  Sounds like a case for a new requirement of the API to be able to handle a BLOB (binary large object). Perhaps a new flavor of an attribute. I'll forward your plea.

                  Todd

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

                  Advertisement