sketchucation logo sketchucation
    • Login
    🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Opening other files from ruby

    Scheduled Pinned Locked Moved Plugins
    6 Posts 3 Posters 221 Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • K Offline
      ktkoh
      last edited by

      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

      1 Reply Last reply Reply Quote 0
      • J Offline
        Jim
        last edited by

        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.

        Hi

        1 Reply Last reply Reply Quote 0
        • K Offline
          ktkoh
          last edited by

          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

          1 Reply Last reply Reply Quote 0
          • Dan RathbunD Offline
            Dan Rathbun
            last edited by

            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 )

            I'm not here much anymore.

            1 Reply Last reply Reply Quote 0
            • Dan RathbunD Offline
              Dan Rathbun
              last edited by

              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.

              I'm not here much anymore.

              1 Reply Last reply Reply Quote 0
              • K Offline
                ktkoh
                last edited by

                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

                1 Reply Last reply Reply Quote 0
                • 1 / 1
                • First post
                  Last post
                Buy SketchPlus
                Buy SUbD
                Buy WrapR
                Buy eBook
                Buy Modelur
                Buy Vertex Tools
                Buy SketchCuisine
                Buy FormFonts

                Advertisement