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 @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)
Hello.
I'm trying to access and subsequently modify Plugins Search Path, which is located in the Preferences window.
I have to accomplish this task via a Python script (not from pyp file).
I have a problem at the first step when I'm trying to simply access its value and print it.
import c4d
pid, att = None, c4d.plugins.GetFirstPlugin()
while att:
if 'Plugins/Plugins' in str(att):
pid = att.GetID()
break
att = att.GetNext()
prefs = c4d.plugins.FindPlugin(pid)
plugins = prefs[c4d.PREF_PLUGINS_PATHS]
print(prefs[c4d.PREF_PLUGINS_PATHS])
In this example, it prints an empty string even though several paths are already added.
However, if I open the preferences window, it prints the correct values instead of an empty string. Is it possible to bypass opening the prefs window and make the script work correctly?
Is it possible to save and load the group window in a way similar to the l4d files?
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()
How to create dialog window with pre-loaded pallete(l4d file)?
I'm not talking about BITMAPBUTTON.
I'm trying to include an actual undockable palette with all palette functionality, such as orientation change, the ability to hide/unhide text, icon size changing functionality, etc.
I know that I can drag and drop l4d palette file into C4D and it will create a new window with the palette. I also know how to load a palette with Python script, but it will create a palette in its own window. I need to load the palette into my GeDialog window.
How to change the sound volume of the Sound Effector via Python Script?
What am I doing wrong? Need to remove the node under certain circumstances via MSG_MENUPREPARE but it crashes the C4D.
Is it possible to somehow bypass this behavior? Is this a bug?
import c4d
import os
class OBug_Check(c4d.plugins.ObjectData):
def Message(self, node, type, data):
if type == c4d.MSG_MENUPREPARE:
node.Remove()
return True
if __name__ == "__main__":
c4d.plugins.RegisterObjectPlugin(id=1000003,
str="Bug Check",
g=OBug_Check,
description="OBug_Check",
info=c4d.OBJECT_GENERATOR,
icon=None)
Is it possible to prevent object/tag plugins from getting selected when clicking on them?
Currently, If I click on let's say object generator plugin, it gets highlighted in the viewport, highlighted in the objects manager and its attributes manager shows on.
I want to change the behavior, so if I have selected another non-plugin object and its attributes managers are visible I want to keep it even if I click the plugin object in the scene or the objects manager.
Is it possible to create a Python Node Plugin for the Material node?
I need something as simple as a node with Bool output or the String output port.
If not, are there any plugins for implementing such feature?