Opening other files from ruby
-
I was wondering if I could open and display a picture file from a rb file. I use a data file and the first time the program runs on a computer it creates that file and I was thinking it would be a good time to also open a help file the first time the program ran. I would like it to be a jpeg file saved from a SU drawing showing what the data represents and which edges the program is asking the user to select. Is this feasable?
Keith
-
Your Operating System likely knows how to display images, so you can use
UI.openURL("image.jpg")
to have the image open in your default image viewer. -
Jim that command works however I couldn't get the path + file name formated with quotes so it would work the variable @helpfile contained the info but without the enclosing quote marks it didnt work.
Keith
-
To replace a substring with a string referenced by a variable, use double quote string replacement:
@base_path = Sketchup.find_support_file("Plugins") @rel_path = "my_author_dir" @helpfile = "nifty_pic.jpg"
fullpath = "#{@base_path}/#{@rel_path}/#{@helpfile}"
or use Ruby's built-in methods:
fullpath = File.join(@base_path,@rel_path,@helpfile)
then:
UI.openURL( fullpath )
-
If you want to make a fancier help file... you can use a
UI::WebDialog
as jpg and png files can be embedded in them.If your script is a UI::
Tool
class, you can have your help file automatically displayed in the Instructor window (which is also a HTML dialog basically.)
The trick is that the path must be given relative to the one of the: "Resources/#{locale}/helpcontent" or "Resources/#{locale}/helpcontent/tool" dir. (Can't remember which offhand.) Anyway.. your path will have a long series of "../../.." etc. all the way back to the root dir, then you append a path from the root to your plugin's dir, and put a "index.html" help file there.
Any time a user activates your tool, and the Instructor window is open, it will load the help file for your tool. -
Thanks Dan that worked just fine. I think I will only need to show the file once as the joint tools are not extreemly complicated but it is importsnt to know what edges the program is expecting you to pick.
Thanks
Keith
Advertisement