Hi all!
I received a message “file not found or invalid” when i tried to get component from my browser! Could you pls help me solve this problem?

Here is the script (its origin is from a member named John in this forum, then I modified a little bit according to my idea):
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:0mm;
color:GrayText;
background-color:Window;
}
button{
text-align: center;
width: 140px;
height:140px;
cursor:pointer;
}
.grid-container > button:hover {
box-shadow: 0 4px 16px 0 rgba(0, 0, 0, 0.5), 0 6px 30px 0 rgba(0, 0, 0, 0.4);
background-color: window;
text-shadow: 2px 2px 4px #000000;
color: black;
}
img {
width: 100px;
height: 100px;
border: 0;
}
.grid-container {
display: grid;
grid-template-columns: auto auto auto auto;
grid-gap: 20px;
background-color: window;
padding: 20px;
}
.grid-container > button {
background-color: window;
border: 0px solid black;
text-align: center;
font-size: 14px;
margin: 15px;
}
</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)
body << %(<div class="grid-container">)
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)
body << %(
<button id='action#{i}';"
onclick="importSkp(this);"
onmouseout="this.id='action#{i}'" value="#{basename}">
<img src="#{img}" alt="#{name}">
<div style="margin-top: 3px;">#{basename}</div>
</button>
)
end
body << %(</div>)
tail = <<-TAIL
<script>
function dlgBlur() { window.location='skp:dlg_blur'; }
</script>
<script>
function importSkp(self) {
window.location='skp:import_skp';
self.id = 'action';
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 = 600
dlg = UI::WebDialog.new(File.basename(dir), true, '', min, dlgh, 80, 112, true)
dlg.add_action_callback('dlg_blur') do |_d|
de_focus
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
model.import(skp)
end
dlg.set_html(html)
dlg.show
de_focus
end
end
end
JcB::ComponentBrowser.make_browser