sketchucation logo sketchucation
    • Login
    1. Home
    2. honkinberry
    3. Posts
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info
    H
    Offline
    • Profile
    • Following 0
    • Followers 0
    • Topics 7
    • Posts 57
    • Groups 1

    Posts

    Recent Best Controversial
    • RE: Download RBZ file

      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

      posted in Developers' Forum
      H
      honkinberry
    • RE: Using mysql in plugin sketchup

      @unknownuser said:

      I want acceded to a mysql database in a plugin.

      I have found that it is not worth the hassle. We instead access all such data through a WebDialog and data located remotely.

      --J

      posted in Developers' Forum
      H
      honkinberry
    • RE: WebDialogs, "skp:", and Windows 8/IE 10?

      My understanding is that Windows is not "using" IE7 for WebDialogs, that is just one unusual nature of the user agent string. MSDN says to trust the Trident setting as being more accurate:
      http://msdn.microsoft.com/en-us/library/ms537503(v=vs.85.aspx

      As such, Trident/6.0 = IE10.

      --J

      posted in Developers' Forum
      H
      honkinberry
    • RE: Download RBZ file

      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

      posted in Developers' Forum
      H
      honkinberry
    • RE: Download RBZ file

      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

      posted in Developers' Forum
      H
      honkinberry
    • RE: Download RBZ file

      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

      posted in Developers' Forum
      H
      honkinberry
    • RE: New API doc - typos and questions

      I finally tracked down a bug that popped up with 7.1, but not sure if this is the best place to note it.

      But for Transformation.scaling, both (scale) and (pt, scale) have a bug.
      One instead needs to use (xscale, yscale, zscale), even though all 3 parameters will be the same.

      posted in Developers' Forum
      H
      honkinberry
    • RE: Download RBZ file

      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

      posted in Developers' Forum
      H
      honkinberry
    • RE: Download RBZ file

      @unknownuser said:

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

      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

      posted in Developers' Forum
      H
      honkinberry
    • RE: Download RBZ file

      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

      posted in Developers' Forum
      H
      honkinberry
    • Download RBZ file

      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

      posted in Developers' Forum
      H
      honkinberry
    • Webdialog on Mac

      Before I completely go insane here, I just want to confirm what I have read in other posts and tutorials and such.

      That is, when I call a WebDialog.show_modal on Mac, it is not modal at all, correct? But totally and completely modeless, right?
      I ask as, I'm getting to a few of my helper functions, and I need to confirm this before going crazy.
      Is there any tricks or tips you guys have amassed?

      In particular, as an example, I have functions named newProject() and selectProject(), allowing a user to create or select a project. And they tend to be embedded in code like so:
      if (!$project_number)
      selectProject()
      end # if
      ...other stuff ....

      Now if the web dialog that selectProject is displaying is completely modeless, that throws everything off.
      This is catastrophically nonsense as far as I'm concerned, and as impossible to work with as if calling UI.inputbox were modeless -- I need to be able to have a function to collect user input, and yes, maybe using a dialog box to do so, and rest assured that the procedure is done inline and synchronously.
      Right? Am I just missing something? Please?

      Many thanks again for all your help.

      --J

      posted in Developers' Forum
      H
      honkinberry
    • RE: ENV['COMPUTERNAME'] for Mac?

      Oh, both of these last pasts, bammo, thank you guys!!!!
      the ioreg is interesting for sure -- the board-id seems valuable for my purposes.

      But Jim is correct!
      hostname does indeed work.
      So for me at least, it's as easy as:
      machinename = ENV['COMPUTERNAME']
      if (!machinename) then machinename = hostname # must be a Mac

      Thanks all!!!

      posted in Developers' Forum
      H
      honkinberry
    • RE: ENV['COMPUTERNAME'] for Mac?

      driven is correct, no such filename.
      I was incorrect, I did a "cd /etc" and then typed "hostname", like an idiot. Sorry.

      the ioreg is interesting, but when I try that from Ruby console I get undefined local variable or method.

      I appreciate everybody's help.
      To emphasize, I was looking for something quick and easy, along the lines of the ENV vars.
      If SU doesn't have that on the Mac side, I can add a config.rb faster than any other solution.
      It sure would be nice to have, hint hint!!!

      --J

      posted in Developers' Forum
      H
      honkinberry
    • RE: ENV['COMPUTERNAME'] for Mac?

      I'm not so concerned if a user has set the ENV variable to a bogus value in an attempt to circumvent our licensing system. I was hoping for just a 95% solution.
      (Key point, why would someone hack a license system for free software???)

      So I just want to query the machine name on a Mac, secure or not.
      If there's a way to do that with SSH, if you could point in the right direction, I'll find out.

      posted in Developers' Forum
      H
      honkinberry
    • RE: ENV['COMPUTERNAME'] for Mac?

      There is indeed an etc/hostname file, and that's what I want -- how to read that from SU Ruby?

      And as for iterating ENV, isn't it a bit quicker to just type ENV ? That seems to work. πŸ˜‰

      --J

      posted in Developers' Forum
      H
      honkinberry
    • ENV['COMPUTERNAME'] for Mac?

      Hi all,
      long-time fan, first time posting.

      I was hoping to access ENV['COMPUTERNAME'] to use with our License management system.
      But it seems that value is only available on the PC side. Is there a way to get this on the Mac side?

      Thanks for any assistance!

      --J

      posted in Developers' Forum
      H
      honkinberry
    • 1
    • 2
    • 3
    • 3 / 3