HTML help file for an extension

I’d like to distribute an HTML help file with an extension using UI.openURL
If I store the HTML in the …\plugins\myextension sub directory,
how do I format the relative path in UI.openURL to work on any windows or Mac system?

help = File.join(File.dirname(__FILE__), 'html', 'help.html') UI.openURL(help)

or similar…
john

To be cross-platform compatible [MAC & PC] try something like :

help = File.join(File.dirname(__FILE__), 'myextensions', 'help.html')
UI.openURL("file:///#{help}")

Assuming the calling file in _FILE_ needs to look into a nested subfolder…
Otherwise omit the ‘myextensions’,

@tig
do we need
UI.openURL('file://' + help)
as well?
john

[quote=“TIG, post:3, topic:6360”]
UI.openURL(“file:///#{help}”)
[/quote] UI.openURL("file:///#{help}")
should work on PC & MAC…

I put test.html in …plugins/test subfolder. (windows)
help = File.join(File.dirname(FILE), ‘test’, ‘help.html’)
returned
./test/help.html
Then
UI.openURL(“file:///#{help}”)
returned false.

Then I tried:
help = File.join(File.dirname(FILE), ‘help.html’)
which returned
./help.html
But
UI.openURL(“file:///#{help}”)
still returned false.

What am I missing?

your ‘calling’ script needs to be in the same folder…

make a launch_help.rb with
`` help = File.join(File.dirname(__FILE__), 'help.html') UI.openURL("file:///#{help}")
put it beside the help.html

to load from ‘Ruby Console’ use
load(" <<ADD YOUR FUL PATH>>") you can do that by just dragging it in or typing it out…
john

My calling script is in the same folder. It’s called by a toolbar click.
this is it:

module Sketchup::MYmodule
def self.help
UI.messagebox “Help”
help = File.join(File.dirname(FILE), ‘help.html’)
UI.openURL(“file:///#{help}”)
end
end

When I click on the tool I get the messagebox but no help file(?)

[quote=“barry_milliken_droid, post:8, topic:6360”]
help = File.join(File.dirname(FILE), ‘help.html’)
[/quote] It’s actually:

help = File.join(File.dirname(__FILE__), 'help.html')

“__FILE__” not “FILE”
Once you have a true path to the file it will open with:

UI.openURL("file:///#{help}")

To test the path is right add this to the code and run it with the Ruby Console open:

puts help
puts File.exist?(help)

It will return true if so…

PS: Please STOP using the SketchUp module. :disappointed:
Just use your own !

swap the order and see what ruby sees
help = File.join(File.dirname(__FILE__), 'help.html') UI.messagebox(help)
btw: to format code so we see __FILE__ and not FILE use backticks e.g. `__FILE__` in your posts…

john

It now works. Thanks all, Not sure I understand all of the above.

  1. Modules: I copied syntax from sandboxmenus which uses the syntax
    module Sketchup::SandboxTools
    I’ll remove the “Sketchup::” from my scripts.
  2. Not sure what backticks are, but I see that the double underscores disappeared from my post somehow.
  3. John is saying that in some situations the console gives different results than the same syntax executed from a file(??)

maybe…
if your requesting __FILE__ from console it will alway return your working directory, from a script it returns the path to the script…

it’s very good when people move files out of Plugins, then load them by other means, as the path is relative to the location…

backticks are on my keyboard beside left shift along with ~

As was said…

__FILE__

only works inside a script, it is actually the file path to the Ruby RB script that is calling it.

File.dirname(__FILE__)

gives you the folder that contains the Ruby script.
If you use it in the Ruby Console it won’t work as expected as it’ll be <main>, but if you ‘load’ a RB from the Ruby Console it will return the path to that RB as hoped…

The reason the “Sandbox” module is nested in the “Sketchup” module is because it IS part of “Sketchup”.
In your case use your own named module [probably your own name [at least initial capital letter - e.g. “Milliken”], you can then nest further methods/modules/classes within that as needed without ‘polluting’ the “Sketchup” name-space…

Even the su_examples extension Trimble intends for us to use a pattern for development uses the
module Sketchup::Examples
in all of its rb files.

But the RB files like the Examples belong to Sketchup too !
So nesting those modules is quite logical.
Third-parties [you, me et al] should NOT use the Sketchup module, or mess with Sketchup/native modules/classes/methods…
I doubt if any of the thousands of other freely available RBs include that module - they’ll all use their own.
Indeed using the Sketchup module is grounds for a rejection, should you ever make something to lodge in the Extensions-Warehouse…

True - we enforce that the developers have their own root namespace module - as per developer guidelines for EW.
Personally I recommend a root module for you or your company - then add your extension modules inside of that.

I’d guess that Ruby is about my tenth programming language. And I’ve done extensions to other CAD applications in the past. But as a newbie to OOP, Ruby and the Sketchup Object model (except as a user) the leaning curve looks like the face of El Capitan. I’m happily climbing about an inch a day (= about 20 lines of code).
So while I knew that
“module Sketchup” was bad practice, I thought maybe "module Sketchup::Mymodule’ was longhand for “module Mymodule”, since so many of the examples use the longer form. It would be tremendously useful if Trimble provided code examples that actually follow the practices that they advocate.

This function has worked for years. Now I have a MAC user who says it’s broken in SketchUp 2019. No error message, just nothing happens when he clicks on my Help icon.
He reports another extension that has a function to open Finder that is also broken.
I’m a windows developer so cannot test. Has anyone else seen this?

See my reply in your other topic