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