Global variable for Preferences Folder?
-
Hi,
Is there a global variable for preferences folder where it automatically retrieves the path of the preferences?
Currently, I have it hard coded like in the following, but it would be nice a fail-safe of doing it (i.e. global variable).
def open_folder(path=r'C:\Users\Luke\AppData\Roaming\MAXON\Maxon Cinema 4D R21_64C2B3BD\plugins'): webbrowser.open('file:///' + path)
-
Lol. Ignore this. Just when I was writing this, stumbled upon the documentation that solves my problem.
Here is the method.
c4d.storage.GeGetStartupWritePath()
-
@bentraje
Since you're looking for the plugins folder it might be advised to useGeGetPluginPath
instead? -
@C4DS said in Global variable for Preferences Folder?:
GeGetPluginPath
Unfortunately, it returns me the following path
C:\\Program Files\\Maxon Cinema 4D R21\\corelibs'
.
No worries, I just did theos.path.join(path, "plugins")
and it works as expected. -
@bentraje said in Global variable for Preferences Folder?:
Unfortunately, it returns me the following path
C:\\Program Files\\Maxon Cinema 4D R21\\corelibs'
.I am using the
GeGetPluginPath
alot in my C++ plugins, but the Python SDK documentation mentions:Warning The Python implementation is different from the C++. In the Python SDK, this function returns the path of the Python SDK module. To get the path of your Python plugin use __file__.
Also note that from R21 (or was it R20) the user can define his/her own path(s) for plugins.
In that case you'll end up with a possibly non-existing path if you simply concatenate "plugins" to the startup-write path. -
Ah gotcha. Thanks for the heads up!
-
you seem to have solved your problem yourself, so there is not much for me to add here apart from offering alternative solutions. One slightly dodgy way to get the preferences path is to use the path which is stored under
c4d.PREF_MEMORY_PVHARDFOLDER
in the world container of Cinema (it is theMemory>Cache Path
attribute).A more elegant way is to use
maxon.Application.GetUrl()
which does properly handle the different paths under which the preferences can be stored (see example at the end of my posting for details).Cheers,
Ferdinand"""On how to iterate over the different preferences paths with the maxon API. """ import maxon def main(): """Entry point. """ for urlType in (maxon.APPLICATION_URLTYPE.GLOBALPREFS_DIR, maxon.APPLICATION_URLTYPE.PREFS_DIR, maxon.APPLICATION_URLTYPE.PREFS_DIR_STATIC): print (f"{urlType}:{maxon.Application.GetUrl(urlType)}") if __name__=='__main__': main()