Solved How can i set custom Databases paths in prefs with python?

Hi
I have a python startup plugin that sets texture paths in Prefs>File Assets! with SetGlobalTexturePaths(...) for all workstations and render slaves. Is there a similar method for setting custom paths for node material Asset Databases (below the File Assets field) ?
c5385534-5590-4fa6-a08b-fd3c08bbfab2-image.png

Any help appreciated.

-b

Hello,

these paths are accessed with a preference plugin. You can access that plugin:

plugin = c4d.plugins.FindPlugin(1040566)

paths = plugin[c4d.PREF_DATABASE_PATHS]

# print paths
print(paths)

# add a path
paths = paths + "\n" + "X:\someting" 
plugin[c4d.PREF_DATABASE_PATHS] = paths

c4d.EventAdd()

best wishes,
Sebastian

Thanks! Ill try that.

Regards
Bonsak

So im trying to get this to work inside our startup plugin. I can set new database paths but i cant read the existing ones. So im constantly overwriting the paths field.

import c4d
import os, sys

def PluginMessage(id, data):	
	if id == c4d.C4DPL_PROGRAM_STARTED:
		try: 
			# Get plugin object
			plugin = c4d.plugins.FindPlugin(1040566)
			# Print plugin object
			print('Plugin {}').format(plugin)

			# Get existing paths
			dbPaths = plugin[c4d.PREF_DATABASE_PATHS]
			# Print existing paths
			print('Existing DB paths {}').format(dbPaths)

			# Set new paths
			dbPaths = dbPaths + "\n" + "S:/_3D_Central/Maxon/Racecar-Assets-Redshift" 
			plugin[c4d.PREF_DATABASE_PATHS] = dbPaths

			# Print new paths
			print('New DB paths {}').format(dbPaths)

		except KeyError: 
			sys.exit(1)

print('Existing DB paths {}').format(dbPaths) doesnt print anyting even though there are entries in the Databases field.
Am i doing something wrong?

Regards
Bonsak

Hello,

this particular preferences plugin only loads its data when needed. To trigger that, you can call GetDescription() which will internally load the data.

plugin.GetDescription(c4d.DESCFLAGS_DESC_0)

# Get existing paths
dbPaths = plugin[c4d.PREF_DATABASE_PATHS]

best wishes,
Sebastian

Thanks! Works like a charm!

-b

Hi
I managed to delete my original plugin :) So now im recreating it. But when i run this plugin now with the findplugin argument, it returns None. As stated higher up in the thread im trying to set custom database paths in prefs on startup.

import c4d
import os, sys


def PluginMessage(id, data):	
	if id == c4d.C4DPL_PROGRAM_STARTED:
		# try: 
		# Get plugin object
		plugin = c4d.plugins.FindPlugin(1040566)

		# Print plugin object
		print('Plugin ', plugin)
		plugin.GetDescription(c4d.DESCFLAGS_DESC_0)
		dbPaths = plugin[c4d.PREF_DATABASE_PATHS]
		print('Existing DB paths {}').format(dbPaths)

Any help appreciated.

Regards
Bonsak

Ok. I figured it out. The ID was wrong. It was supposed to be 465001634

-b