sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Retrieve 'User' File Locations

    Scheduled Pinned Locked Moved Plugins
    8 Posts 2 Posters 574 Views 2 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.
    • P Offline
      pgarmyn
      last edited by pgarmyn

      Hello

      About the 'User' file locations. They are defined in Menu/Windows/Preferences/Files and this corresponds to the (Windows) Registry keys HKEY_CURRENT_USER/Software/SketchUp/SketchUp 2014/File Locations/....

      But I can't find a way to retrieve the key value for those File Locations:
      Sketchup.read_default("File Locations","Materials") should return “C:/Users/UserName/Documents” but it returns nil.

      Is this information protected by the Sketchup API ❓

      1 Reply Last reply Reply Quote 0
      • P Offline
        pgarmyn
        last edited by

        Just found TIG's post http://sketchucation.com/forums/viewtopic.php?f=323%26amp;t=44637#p398226
        But it seems there is no solutions. Users can read & write the value, but Ruby can't even read it. Forgotten ?

        1 Reply Last reply Reply Quote 0
        • P Offline
          pgarmyn
          last edited by

          Work around for SU 2014 :

          require 'win32/registry'
          defaultFileDir = Win32;;Registry;;HKEY_CURRENT_USER.open 'Software\SketchUp\SketchUp 2014\File Locations', Win32;;Registry;;KEY_READ
          defaultFileDir_materials=defaultFileDir["Materials"]
          defaultFileDir.close
          puts defaultFileDir_materials ##  output= C;\Users\P\Documents\ 
          

          And for SU-8 or SU-2013 ?

          1 Reply Last reply Reply Quote 0
          • TIGT Offline
            TIG Moderator
            last edited by

            For earlier WIN SUp versions get the appropriate 'Win32API.so' and use similar [but undoubtedly more convoluted] Registry hacking...
            Browse this...
            http://sketchucation.com/forums/viewtopic.php?t=42732
            Then here...
            http://knowledgebase.progress.com/articles/Article/21622
            http://msdn.microsoft.com/en-us/library/windows/desktop/ms724875%28v=vs.85%29.aspx
            http://www.oehive.org/win32api?page=6
            etc...

            On MACs there isn't user's choice in these folder-paths so Sketchup.find_support_file('Materials') returns the path ?

            TIG

            1 Reply Last reply Reply Quote 0
            • P Offline
              pgarmyn
              last edited by

              @TIG

              Thanks TIG.
              On Mac : is Sketchup.find_support_file('Materials') writable ?

              1 Reply Last reply Reply Quote 0
              • TIGT Offline
                TIG Moderator
                last edited by

                Not sure...
                I think on MAC >v8 it's in the User's Lib path... so it ought to be writable...

                File.writable?(Sketchup.find_support_file('Materials'))

                But on WIN if it's the SketchUp folder subfolder it will have limited permissions by default 😕

                TIG

                1 Reply Last reply Reply Quote 0
                • P Offline
                  pgarmyn
                  last edited by

                  @tig said:

                  Not sure...
                  I think on MAC >v8 it's in the User's Lib path... so it ought to be writable...
                  File.writable?(Sketchup.find_support_file('Materials'))
                  But on WIN if it's the SketchUp folder subfolder it will have limited permissions by default 😕

                  Santiago (Caronte01) tested my plugin (RichSection) on mac+SU2014.
                  I used Sketchup.find_support_file('Materials') to get the user Lib path for MAC.
                  It returned '/Applications/SketchUp 2014/SketchUp.app/Contents/Resources/Content/Materials'
                  I tried to fileutils.cp_r to this path and got : #<Errno::EACCES: Permission denied
                  (i did check the existence of the directory before cp_r : FileUtils.mkdir_p(dir) unless File.exist?(dir))

                  According to Jeff Hammond's post (Re: trying to add material collection OSX Mavericks) the User's Lib path for materials should be (?):
                  (user)~/Library/Application Support/SketchUp201X/SketchUp/Materials

                  For the Sketchup team : It can be useful to have a API method (for WIN and MAC) to retrieve the path for USER data : Sketchup.find_user_file('Materials')

                  1 Reply Last reply Reply Quote 0
                  • TIGT Offline
                    TIG Moderator
                    last edited by

                    If your Plugin uses its own 'custom materials' why not supply them disassembled in a 'Textures' subfolder within your plugin's own subfolder [that is itself within Plugins].
                    Then you'll know where it is automatically from File.dirname(__FILE__).
                    Because SKMs are not easily accessible with the API, then you define plain colors for newly made materials [if needed] as the tool runs [that way any purged materials are remade], and where needed add textures to these, based on Image files kept in a that plugin's 'Textures' subfolder ?
                    That way you never need to go near the Materials folder.
                    Your custom materials are automatically listed as loaded into the Model, and any other unloaded materials [as SKMs] can be accessed too from the Materials Browser by the user in the normal way...

                    You are unlikely to have permission to write to any Materials folder in the PC's Program Files tree, or the MAC equivalent.
                    If the users has set up their own custom Materials folders, then on a PC they could be anywhere... and on a MAC its location in their User Lib folder tree is recommended, but not guaranteed [it needs making by them] - and if it were missing and you made it then it's not going to be added to the list of 'Material Collections' in the Materials Browser anyway [unless the user does it manually] ?

                    TIG

                    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