Retrieve 'User' File Locations
-
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
-
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 ? -
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 ?
-
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 ?
-
Thanks TIG.
On Mac : is Sketchup.find_support_file('Materials') writable ? -
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 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 defaultSantiago (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/MaterialsFor 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')
-
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 fromFile.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] ?
Advertisement