我正在尝试创建一个打开.html文件的工具,但是我需要在打开上述.html文件的代码块方面提供帮助。下面有个密码..。
help_file = Sketchup.find_support_files("html", "Plugins")
if help_file
# Print out the help_file full path
UI.messagebox(help_file)
# Open the help_file in a web browser
UI.openURL("file://" + help_file)
else
UI.messagebox("Failure")
end这段代码的输出显示在下面的截图中。
https://i.stack.imgur.com/ixLIT.png
这正是我所期望的。Chrome中也没有打开.html,因为有两个.html文件。因此,现在我更进一步,并尝试指定我希望打开的.html文件。我想打开'basic.html‘(到目前为止它是一个空白的.html文件),并相应地修改我的代码(第一行是特定的)。
help_file = Sketchup.find_support_files("basic.html", "Plugins")
if help_file
# Print out the help_file full path
UI.messagebox(help_file)
# Open the help_file in a web browser
UI.openURL("file://" + help_file)
else
UI.messagebox("Failure")
end不幸的是,我没有得到我所期望的输出。这就是我最后的下场。
https://i.stack.imgur.com/4xyQT.png
basic.html也没有在Chrome中打开,这真是太令人失望了。
下面是我在Plugins文件夹中的文件的样子,以防你想看到它。
https://i.stack.imgur.com/OW7xM.png
我面临的问题是什么?
发布于 2022-03-11 06:50:34
如何测试代码如下:
Plugins or Extension Menu -> Open basic.html inside the plugins folder可能的解决方案#1
module DevName
module PluginName
class Main
def activate
@dlg = UI::HtmlDialog.new(html_properties_activate)
plugins_folder = "file:///#{Sketchup.find_support_file('Plugins').gsub(/ /, '%20')}" #/
html_file = File.join(plugins_folder, 'basic.html')
@dlg.set_url(html_file)
@dlg.show
@dlg.center
end
def html_properties_activate
{
dialog_title: 'Dialog Example',
preferences_key: 'com.sample.plugin',
scrollable: true,
resizable: true,
width: 420,
height: 320
}
end
end
unless defined?(@loaded)
UI.menu('Plugins').add_item('Open basic.html inside the plugins folder') do
Sketchup.active_model.select_tool(DevName::PluginName::Main.new)
end
@loaded = true
end
end
end可能的解决方案#2 (更好的解决方案)
我更喜欢使用'basic.html‘脚本的相对路径来查找'.rb’的位置,而不是使用'Plugins‘文件夹路径。
另外,在打开本地HTML文件时,最好使用.set_file而不是.set_url。
module DevName
module PluginName2
class Main
def activate
@dlg = UI::HtmlDialog.new(html_properties_activate)
path = File.dirname(__FILE__)
html_file = File.join(path, '/basic.html')
@dlg.set_file(html_file)
@dlg.show
@dlg.center
end
def html_properties_activate
{
dialog_title: 'Dialog Example',
preferences_key: 'com.sample.plugin',
scrollable: true,
resizable: true,
width: 420,
height: 320
}
end
end
unless defined?(@loaded)
UI.menu('Plugins').add_item('Open basic.html inside plugins folder Solution #2') do
Sketchup.active_model.select_tool(DevName::PluginName2::Main.new)
end
@loaded = true
end
end
endhttps://stackoverflow.com/questions/71433489
复制相似问题