Thanks @ferdinand
I wrote this little script for those who want to add one plugin path via the C4D script. I will update it later.
It will NOT overwrite existing paths. Restart is required for instant result.
import c4d
import os
import json
def add_plugin_path(path, restart = False):
if os.path.exists(path): new_path = path.replace("\\", "/")
else:
print("Path does not exists")
return
prefs_folder = c4d.storage.GeGetC4DPath(c4d.C4D_PATH_PREFS)
prefs_path = os.path.dirname(prefs_folder)
plugins_json_path = os.path.join(prefs_path, 'plugins.json')
if os.path.exists(plugins_json_path):
with open(plugins_json_path,'r',encoding="utf-8-sig") as plugins: plugins_json_raw = plugins.read()
plugins_dict = json.loads(plugins_json_raw)
content_dict = plugins_dict["content"]["_impl"]["_data"][1]["content"]
# Check if the new path is already in Plugins Path
for content_path in content_dict:
if os.path.normpath(content_path["_0"]["_path"]) == os.path.normpath(new_path):
print(f"'{new_path}' is already in Plugins Path.")
return
else:
plugins_dict = {
'identification': 'plugins',
'content': {
'referenceDataType': 'net.maxon.interface.datadictionary-C',
'_impl': {
'_mode': 2,
'_data': [
{
'dataType': 'net.maxon.datatype.id',
'content': 'searchPaths'
},
{
'dataType': '(net.maxon.interface.url-C,bool)',
'isArray': True,
'content': []}]}}}
# Create new path content
new_content = {
"_0": {
"referenceIndex": len(plugins_dict["content"]["_impl"]["_data"][1]["content"]),
"referenceDataType": "net.maxon.interface.url-C",
"_scheme": "file",
"_path": new_path,
"_authority": {},
"_data": {}
},
"_1": True
}
# Append the new path to the list of paths
plugins_dict["content"]["_impl"]["_data"][1]["content"].append(new_content)
# Convert the dictionary back to a JSON string
updated_plugins_dict = json.dumps(plugins_dict, indent=4)
# Write the updated dictionary back to a JSON file
with open(plugins_json_path, 'w') as plugins_json: plugins_json.write(updated_plugins_dict)
if restart: c4d.RestartMe()
custom_path = r"/Path/To/Plugin/Directory/"
add_plugin_path(path = custom_path, restart = False)