• Login
sketchucation logo sketchucation
  • Login
๐Ÿ”Œ Quick Selection | Try Didier Bur's reworked classic extension that supercharges selections in SketchUp Download

Open SU vs open model - __FILE__ might vary

Scheduled Pinned Locked Moved Developers' Forum
10 Posts 4 Posters 301 Views 4 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.
  • C Offline
    Chris Fullmer
    last edited by 10 Sept 2011, 19:05

    Not of great consequence probably, but I came across an oddity on my Win XP machine. The __FILE__ reference returns a different string when SketchUp is opened by clicking on the actual SketchUp icon vs clicking on a model file. It cause me a little grief in a quick hardcoded string comparison I was playing with.

    Clicking on the sketchup icon, __FILE__ gives me:
    C:/Program Files/Google/Google SketchUp 8/Plugins/multiflux_loader.rb

    Clicking on the model file __FILE__ gives me:
    C:/PROGRA~1/Google/GOOGLE~3/Plugins/multiflux_loader.rb

    Clearly the same path per se. But the string is not comparable. So don't rely on simple path string comparison on loading without being aware that the sting will not always be the same.

    Lately you've been tan, suspicious for the winter.
    All my Plugins I've written

    1 Reply Last reply Reply Quote 0
    • T Offline
      TIG Moderator
      last edited by 10 Sept 2011, 21:04

      This is the old 'DOS-path' way versus the 'sensible-path' way!
      Both of these filepaths will return true from ' File.exist?(filepath)' - so why 'compare paths' when you can just 'check for existence' ?

      TIG

      1 Reply Last reply Reply Quote 0
      • C Offline
        Chris Fullmer
        last edited by 10 Sept 2011, 21:20

        Yep, that's an easy fix to get around it. It never crossed my mind that the paths might return differently based on how I opened Sketchup, so it just threw me for a loop when something was working one way for so long suddenly started doing something else.

        Lately you've been tan, suspicious for the winter.
        All my Plugins I've written

        1 Reply Last reply Reply Quote 0
        • D Offline
          Dan Rathbun
          last edited by 11 Sept 2011, 08:33

          This is a BUG.

          And it can cause problems for file/plugin managers etc.

          I tried manually fixing it using regedit but as soon as Sketchup starts up via a icon click, it resets the registry value back to the old 16bit format.

          I noticed the value for "HKCR\Sketchup.KMZModel" has the correct format... but when I double-clicked a KMZ icon Google Earth opened instead.

          I'm not here much anymore.

          1 Reply Last reply Reply Quote 0
          • D Offline
            Dan Rathbun
            last edited by 11 Sept 2011, 08:48

            IMHO the double-click is unusable.

            __FILE__ is not the only thing that gets messed up.

            It also affects: Sketchup.find_support_file, Sketchup.find_support_files, Sketchup.get_resource_path, Sketchup.template_dir, and $LOAD_PATH

            Here's a test script (put it "Plugins/_test" and run it both after a normal startup, and a double-click startup):
            FILE.rb

            I will not be surprised if some utility script chokes when Sketchup starts via double-click.

            I'm not here much anymore.

            1 Reply Last reply Reply Quote 0
            • T Offline
              thomthom
              last edited by 11 Sept 2011, 09:47

              @chris fullmer said:

              Clearly the same path per se. But the string is not comparable. So don't rely on simple path string comparison on loading without being aware that the sting will not always be the same.

              What is you use File.expand_path( __FILE__ ) before comparison ?

              Thomas Thomassen โ€” SketchUp Monkey & Coding addict
              List of my plugins and link to the CookieWare fund

              1 Reply Last reply Reply Quote 0
              • D Offline
                Dan Rathbun
                last edited by 12 Sept 2011, 17:52

                @thomthom said:

                @chris fullmer said:

                Clearly the same path per se. But the string is not comparable. So don't rely on simple path string comparison on loading without being aware that the sting will not always be the same.

                What IF you use File.expand_path( __FILE__ ) before comparison ?

                It has no effect.. ie, does not correct the paths.

                I'm not here much anymore.

                1 Reply Last reply Reply Quote 0
                • T Offline
                  TIG Moderator
                  last edited by 13 Sept 2011, 10:17

                  How about trying
                  File.identical?(string_file_path_to_check, __FILE__) ?
                  To compare against a preset string and another passed path.
                  If I understand it right... if the two arguments both point at the same file then irrespective of their actual 'strings' you'll get ' true' ?

                  OR even more simply File.file?(string_file_path_to_check) or File.file?(__FILE__) to check that the specified file exists and that it is a file and not a directory [if it's a directory use Dir.exist?() OR File.exist?()] ๐Ÿ˜•

                  TIG

                  1 Reply Last reply Reply Quote 0
                  • D Offline
                    Dan Rathbun
                    last edited by 13 Sept 2011, 10:54

                    The issue is not whether the file exists.. it does, because we are inside the file itself eval'ing __FILE__.

                    The issue is, that we wish to test if THIS __FILE__'s absolute path is identical to some other absolute path. Often the test will involve stripping off the filename.

                    The average plugin may not run into any problems with this bug, but a plugin / file manager like Smustard Organizer, or Dana Woodman's Installer, may have problems.

                    I'm not here much anymore.

                    1 Reply Last reply Reply Quote 0
                    • D Offline
                      Dan Rathbun
                      last edited by 13 Sept 2011, 11:08

                      TIG's suggestion DOES work !!!

                      File.identical?("C:/Program Files/Google/Google SketchUp 8/Plugins/testfile.rb", "C:/PROGRA~1/Google/GOOGLE~3/Plugins/testfile.rb")

                      true

                      Then, stripping off the filename and testing dir against dir:
                      File.identical?("C:/Program Files/Google/Google SketchUp 8/Plugins", "C:/PROGRA~1/Google/GOOGLE~3/Plugins")

                      true

                      But it's still stupid, that the installer writes 32 bit quoted pathname, and the app overwrites it each time it starts up with a 16bit pathname.
                      If I start SU7, i wonder if it will overwrite the registry key. Bet it will...

                      I'm not here much anymore.

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

                      Advertisement