How to turn user current view in Sketchup into a URL link which can be accessed by the public with a browser

26 Views Asked by At

How can I take the user's current view in Sketchup, which I have done and create a URL link for this image that, if I was to paste into a browser would have a direct link to the image not a website with the image within, and can be publicly viewed anyone with the link if it was to be pasted into a browser. The code below gets the user current view, but how to then generate this URL for this image: ```

require "sketchup.rb"
require "base64"
canvas_width = 800
canvas_height = 600
options = {
  :filename => "view.png",
  :width => canvas_width,
  :height => canvas_height,
  :antialias => true,
  :compression => 0.9,
  :transparent => false
}


view = Sketchup.active_model.active_view
view.write_image(options)
image_data = File.read("view.png")
encoded_image = Base64.encode64(image_data)


html = <<-HTML
<html>
  <head>
    <style>
      body {
        margin: 0;
        padding: 0;
        overflow: hidden;
        display: flex;
        justify-content: center;
        align-items: center;
        height: 100vh;
      }
      
      {
        max-width: 100%;
        max-height: 100%;
      }
    </style>
  </head>
  <body>
    <img id="sketchup-view" src="data:image/png;base64,#{encoded_image}">
  </body>
</html>
HTML


dialog = UI::WebDialog.new("test", true, "test", canvas_width, canvas_height)
dialog.set_html(html)
dialog.show
toolbar = UI::Toolbar.new("test")
cmd = UI::Command.new("test") { dialog.show }
icon = File.join(__dir__, "images", "icons8-sound-wave-100.png")
cmd.small_icon = icon
cmd.large_icon = icon
cmd.tooltip = "test"
cmd.status_bar_text = "test"
toolbar = toolbar.add_item(cmd)
toolbar.show```
0

There are 0 best solutions below