Probably there is a better way but you can try this method
selectionTag = op.GetTag(5673)
c4d.CallButton(selectionTag , c4d.POLYGONSELECTIONTAG_COMMAND3)
Probably there is a better way but you can try this method
selectionTag = op.GetTag(5673)
c4d.CallButton(selectionTag , c4d.POLYGONSELECTIONTAG_COMMAND3)
Create a ".pyp" file in the Plugins directory(my_menu.pyp) and try this example.
import c4d
from c4d import gui
def EnhanceMainMenu():
mainMenu = gui.GetMenuResource("M_EDITOR")
pluginsMenu = gui.SearchPluginMenuResource()
menu = c4d.BaseContainer()
menu.InsData(c4d.MENURESOURCE_SUBTITLE, "My Menu 1")
menu.InsData(c4d.MENURESOURCE_COMMAND, "PLUGIN_CMD_{}".format(c4d.Ocube))
menu.InsData(c4d.MENURESOURCE_SEPERATOR, True);
menu.InsData(c4d.MENURESOURCE_COMMAND, "PLUGIN_CMD_{}".format(c4d.Osphere))
menu.InsData(c4d.MENURESOURCE_COMMAND, "PLUGIN_CMD_{}".format(c4d.Oplane))
submenu = c4d.BaseContainer()
submenu.InsData(c4d.MENURESOURCE_SUBTITLE, "Menu 2 ")
submenu.InsData(c4d.MENURESOURCE_COMMAND, "PLUGIN_CMD_{}".format(c4d.Onull))
menu.InsData(c4d.MENURESOURCE_SUBMENU, submenu)
if pluginsMenu: mainMenu.InsDataAfter(c4d.MENURESOURCE_STRING, menu, pluginsMenu)
else: mainMenu.InsData(c4d.MENURESOURCE_STRING, menu)
def PluginMessage(id, data):
if id==c4d.C4DPL_BUILDMENU:
EnhanceMainMenu()
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)
I'm such an idiot Seems like the same code can be applied to user-defined descriptions.
SOLVED!
@mikeudin
We all have to learn C++
I guess you want to create a node of the node.
Thanks, Maxime!
I tested the code, and it works.
But this is not what I exactly wanted.
As I mentioned, the problem is that some users are installing C4D in a custom directory and I can't find preferences path nor an actual installation path.
I also tried os.walk() Method to find MAXON directory, but it has two significant problems.
The only thing that users can define is the release number, and I have to find it according to the string, for example, "R20".
Here is how the installer works.
It works on most of the computers but some users already reported that it can't find their directory so they are forced to manually define it but most of them are defining global directory. If you remember, I had to remove symbolcache file and this is one of the reasons why I made this installer.