Insert skp directly into sketchup like 3d warehouse

I made this little plugin that opens a page inside SketchUp, but I can’t make the links that download skp work and insert the files in SketchUp.
If my website links to skp files, is it possible?

require 'sketchup'

module MyPlugin
  def self.open_website
    # Create a new HTML dialog
    dialog = UI::HtmlDialog.new
    # Set the width and height of the HTML dialog
    dialog.set_size(800, 600)
    # Set the URL of the HTML dialog
    dialog.set_url("https://3dwarehouse.sketchup.com/user/2007bc5e-f8dc-4e22-a9ff-0fa999479db0/Fazt3ds")
    # Set the callback for link clicks
    dialog.add_action_callback("link_clicked") { |dialog, params|
      # Get the clicked link URL from the action value
      link_url = params
      # Load the clicked URL in the same HTML dialog
      dialog.set_url(link_url)
    }
    # Show the HTML dialog
    dialog.show
  end
end

unless file_loaded?(__FILE__)
  cmd = UI::Command.new("Open Website") { MyPlugin.open_website }
  cmd.tooltip = "Opens a specified website"
  cmd.status_bar_text = "Opens a specified website"
  cmd.menu_text = "Open Website"
  toolbar = UI::Toolbar.new "My Toolbar"
  toolbar = toolbar.add_item cmd
  toolbar.show
  file_loaded(__FILE__)
end

The #add_action_callback method establishes a Ruby callback method that your html dialog can call to perform some function.

Since in your example the Html/JavaScript code is not yours (you set an url of public site), the referred sketchup.link_clicked(...)
JavaScript method is not there. So it will not works as you think.

You need to set up on your ow website where you can place the JavaScript counterpart of the code… then pass the url of your file to e.g.: load_from_url:

The DefinitionList #load_from_url method loads a component from a location specified by string url.

Then you can use:
Model #place_component-instance_method

2 Likes