Extensions with data outside of sub-folder?

I’ve never broached this subject before so I may need a little guidance.

Up until now I’ve always stored all of my plugin data within its plugin sub-folder. The problem is that when a User wants to upgrade they typically uninstall my plugin and then re-install the latest version which of course blows away any of the custom settings stored in the plugin folder (text files mainly).

My idea is to create a separate folder call “medeek” within the plugin folder that is separate from any particular plugin and store my data there for all four of my plugins. Is there a problem with this?

If this is possible how would I access this information (the correct path) given that my ruby scripts are running from separate plugin folders?

My typical way to load files is:

this_dir=File.dirname(__FILE__)
# Fix for ruby 2.0
if this_dir.respond_to?(:force_encoding)
	this_dir=this_dir.dup.force_encoding("UTF-8")
end

filename1 = File.join(this_dir,"library/panel/#{panel}.skp")

These two above are the best, the latter refers to the former.


I guess this the time for my oft reminder to you to please use the category search before starting new topic threads. Had you simply typed “plugin settings” into the magnify glass search box you’d see the 2 above threads at the top of the list. Further down you’d have found you’ve already once before opened a thread on this subject …

1 Like

Technically this is possible, but against the extension definition (and EWH rules) that the only top-level artifacts of an extension within the Plugins folder are a subfolder <extension_name> and a registration script <extension_name>.rb.

For this purpose one typically distinguishes

  • program files (executables, here Ruby scripts),
  • program data (resources like html, images, skp files),
  • user settings (stored by SketchUp in registry / plists / preferences.json)
  • and user data (user-generated program data, templates, material/component libraries)

In the context of SketchUp, the first two would be in your extension’s subfolder in Plugins, and user data (and your setting files) can be best protected from overwriting by putting them in the operating system’s user data directory. Depending on operating system, this is %AppData% or ~/Library/Application Support or $XDG_DATA_HOME.
As you proposed, it is indeed a good idea to create a vendor subfolder (“medeek”).

3 Likes

After reading through the various threads I think the best option is to use: %AppData%

What would be the correct path for MacOS though?

Would the correct way to load a file be:

filename1 = File.join('%AppData%',"medeek/medeek_wall/sometextfile.txt")

No. the substring "%AppData%" (case insensitive) is for use in Windows batch files and paths in the explorer bar. (Try pasting into the explorer address bar.)
So it is platform specific. What I’m getting at is that it’s an environment variable which is accessed in Ruby via the hash-like ENV object.

IS_WIN ||=( Sketchup.platform == :platform_win rescue RUBY_PLATFORM !~ /darwin/i )

if IS_WIN
  APPDATA_PATH ||= ENV["APPDATA"] # check for proper encoding!
else # Mac
  APPDATA_PATH ||= "~/Library/Application Support"
end

PLUGIN_DATA_PATH ||= File.join( APPDATA_PATH, "Medeek", PLUGIN_NAME )
2 Likes

FYI: I added an issue to add a page to the API docs on this topic:

To add to this - with the current versions of SU the Plugins folder is in a directory with user access. In older versions it used to be under Program Files - which would often be locked down for users without elevated access.

The appropriate location for where to store user data, vs machine data differs from platform to platform and even version to version. So this information has often become outdated.

In general I encourage developers to check with the documentation from Microsoft and Apple from time to time to get up to date information on this:

https://msdn.microsoft.com/en-us/library/windows/desktop/bb776892(v=vs.85).aspx

https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html

(They have lots of other great references by the way - like design guides etc.)

2 Likes