have a look at this old one of mine, it uses webDialog but could be updated…
I recall it works cross platform, but a quick test would confirm…
copy/paste into Ruby Console or save as a .rb and use load "your/path/to/dlg_browser.rb"
it lets you choose any folder, makes a thumbnail set, shows them in a browser…
when you click they attach to the mouse for inserting…
I have a htmlDialog version somewhere, but will need to find it tonight…
# my namespace
module JcB
OSX = Sketchup.platform == :platform_osx unless defined? JcB::OSX
NODLG = UI::WebDialog.new('noDlg', false, '', 0, 0, 0, 0, false) unless defined? JcB::NODLG
# a html browser for components...
module ComponentBrowser
extend self
def de_focus
NODLG.show
NODLG.close
end
def make_browser
head = <<-HEAD
<html><head>
<title>Drop Comps</title>
<style>
body {
font:caption;
margin:1mm;
color:GrayText;
background-color:Window;
}
button{
text-align: left;
width:68mm;
height:36mm;
cursor:pointer;
}
img {
width:64mm;
height:36mm;
border: 0;
}
.container div {
position: relative;
background-color: rgba(245, 245, 245, 0.58);
width: 63mm;
height: 6.4mm;
bottom: 10mm;
padding: 1mm;
}
</style>
</head>
<body onscroll="dlgBlur()">
HEAD
model = Sketchup.active_model
defs = model.definitions
i = 0
body = ''
dir = File.dirname(UI.openpanel('Get Comps', '.skp'))
skps = Dir.entries(dir).reject { |s| s unless s =~ /\.skp/ }
return if skps.count == 0
img_dir = File.join(dir, 'dlg_thumbnails')
Dir.mkdir(img_dir) unless Dir.exist?(img_dir)
skps.each do |name|
i += 1
basename = name.sub('.skp', '')
img_name = basename + '.png'
skp = File.join(dir, name)
img = File.join(img_dir, img_name)
Sketchup.save_thumbnail(skp, img) # unless File.exist?(img)
col = 'inherit'
in_mod = 'highlight'
col = in_mod if defs[basename].respond_to?(:path)
body << %(
<div class="container">
<button id='action#{i}' style="background-color: #{col};" onmouseover="click()"
onclick="importSkp(); this.id='action'; this.style.background='#{in_mod}';"
onmouseout="this.id='action#{i}'" value="#{basename}">
<img src="#{img}" alt="#{name}"><div>#{basename}</div></button></div>
)
end
tail = <<-TAIL
<script>
function dlgBlur() { window.location='skp:dlg_blur'; }
</script>
<script>
function importSkp() { window.location='skp:import_skp'; }
</script>
</body></html>
TAIL
html = head + body + tail
sel = model.selection
ents = model.entities
scale = NODLG.screen_scale_factor.to_i
vpw = model.active_view.vpwidth
vph = model.active_view.vpheight
dlgw = vpw / scale
dlgh = (vph - 22) / scale
min = 268
dlg = UI::WebDialog.new(File.basename(dir), true, '', min, dlgh, 40, 112, true)
# dlg.min_width = min
# dlg.max_width = dlgw
# dlg.min_height = min
# dlg.max_height = dlgh
dlg.add_action_callback('dlg_blur') do |_d|
de_focus # if OSX # to prevent default focus taking/holding on mac...,
Sketchup.send_action('selectSelectionTool:')
sel.clear unless sel.empty?
end
dlg.add_action_callback('import_skp') do |d|
tl = d.get_element_value('action')
skp = File.join(dir, tl + '.skp')
de_focus # if OSX # to prevent default focus taking/holding on mac...,
# if defs[tl].respond_to?(:path)
# comp = ents.add_instance(defs[tl], ORIGIN)
# sel.add(comp)
# Sketchup.send_action('selectMoveTool:')
# else
# model.import(skp)
# end
model.import(skp)
end
dlg.set_html(html)
if OSX
dlg.show_modal
else
dlg.show
end # if
de_focus # to prevent default focus taking/holding on mac.
end
end
end
# to run use
JcB::ComponentBrowser.make_browser
john