首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法在.html SketchUp中打开SketchUp文件

无法在.html SketchUp中打开SketchUp文件
EN

Stack Overflow用户
提问于 2022-03-11 03:58:58
回答 1查看 79关注 0票数 1

我正在尝试创建一个打开.html文件的工具,但是我需要在打开上述.html文件的代码块方面提供帮助。下面有个密码..。

代码语言:javascript
复制
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文件),并相应地修改我的代码(第一行是特定的)。

代码语言:javascript
复制
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

我面临的问题是什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-03-11 06:50:34

如何测试代码如下:

  1. 创建.rb文件(例如,将其命名为“open-html.rb”),并复制和粘贴下面的代码。然后,将该文件放入folder.
  2. Activate插件中,该工具位于SketchUp中,方法是转到Plugins or Extension Menu -> Open basic.html inside the plugins folder
  3. Done!如果插件文件夹中有一个名为“basic.html”的HTML文件,那么这个脚本将打开它。

可能的解决方案#1

代码语言:javascript
复制
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

代码语言:javascript
复制
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
end
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71433489

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档