M
hi,
To have a sub menu, you need to register more than one plugin.
If you add an extra folder (//User/PluginDirectory/Menu) and make cinema4D point to PluginDirectory. An extra level will be created in the menu named in that example Menu.
Interesting fact. If you register two command, and one have SubID Registered, than the SubID works as expected. (this is obviously a bug)
If you burry the following code inside a sub folder, the second command will not appear, it's named "---" so should act as a separator. (but there's nothing to separate)
And you will be able to execute subIDs from the first command.
I would not do that on a public plugins. This will not work if the user remove that extra folder.
import c4d
MAIN_CMD_PLUGIN_ID = 1055692
MAIN_CMD_PLUGIN_ID2 = 1055693
class MYCOMMANDWITHDIALOG (c4d.plugins.CommandData):
def Execute(self, doc):
print ("execute")
return True
def GetSubContainer(self, doc, submenu):
print ("getsubcontainer", doc, submenu)
bc = c4d.BaseContainer()
bc.SetString(1, "Create Primitives")
bc.SetString(1000, "Create a cube")
bc.SetString(1001, "Create a sphere")
submenu.InsData(0, bc)
return True
def ExecuteSubID(self, doc, subid):
print("execute subID", doc, subid)
op = None
if subid == 1000:
op = c4d.BaseObject(c4d.Ocube)
elif subid == 1001:
op = c4d.BaseObject(c4d.Osphere)
if op is None:
return False
doc.InsertObject(op)
return True
class Dummy (c4d.plugins.CommandData):
def Execute(self, doc):
return True
def main():
c4d.plugins.RegisterCommandPlugin(id=MAIN_CMD_PLUGIN_ID,
str ="Command with sub id",
info = 0,
help ="Command with sub command or dialog option",
dat = MYCOMMANDWITHDIALOG(),
icon=None)
c4d.plugins.RegisterCommandPlugin(id=MAIN_CMD_PLUGIN_ID2,
str ="---",
info = 0,
help ="DummyHiddenCommand",
dat = Dummy(),
icon=None)
if __name__ == '__main__':
main()
Cheers,
Manuel