Plugin Cafe Homepage
Forum Home Forum Home > Plugin Cafe > PYTHON Development
  New Posts New Posts
  FAQ FAQ  Forum Search

CommandData Plugin with submenu

Author
Message
  Topic Search Topic Search
indexofrefraction View Drop Down
Member
Member
Avatar

Joined: 2018 Mar 08
Online Status: Offline
Posts: 9
Direct Link To This Post Topic: CommandData Plugin with submenu
    Posted: 2018 Aug 28 at 2:32am
Hi there,

i'm failing to get a submenu with a commanddata plugin...
could anybody more experienced maybe have a look at this code?

best, index

my folder structure is:
plugins
Test
test.pyp
icon.png

what i would like to get in the plugin menu is:
Plugins
Test Plugin
Submenu1
Submenu2

but what i get with the following code is just: (no submenu!)
Plugins
Test


import c4d
from c4d import bitmaps
import os.path

PLUGIN_ID = 1234567  # unique ID (obtained from www.plugincafe.com)
PLUGIN_SHORT = "Test Plugin"

MENUID_SUB1 = 1000
MENUID_SUB2 = 1010

class MenuHandler(c4d.plugins.CommandData):

def Register(self):
bmp = bitmaps.BaseBitmap()
dir, f = os.path.split(__file__)
fn = os.path.join(dir, "icon.png")
bmp.InitWith(fn)
return c4d.plugins.RegisterCommandPlugin(
id=PLUGIN_ID,
str=PLUGIN_SHORT,
info=c4d.PLUGINFLAG_COMMAND_HOTKEY,
icon=bmp,
help="",
dat=self
)

def GetSubContainer(self, doc, submenu):
bc = c4d.BaseContainer()
bc.SetString(1, PLUGIN_SHORT)
bc.SetString(MENUID_SUB1, "Submenu1")
bc.SetString(MENUID_SUB2, "Submenu2")
submenu.InsData(0, bc)
return True

def ExecuteSubID(self, doc, id):
if id == MENUID_SUB1: print "Submenu1"
elif id == MENUID_SUB2: print "Submenu2"
return True

def Execute(self, doc):
return True

if __name__ == "__main__":
MenuHandler().Register()




Edited by indexofrefraction - 2018 Aug 29 at 12:10am
Back to Top
indexofrefraction View Drop Down
Member
Member
Avatar

Joined: 2018 Mar 08
Online Status: Offline
Posts: 9
Direct Link To This Post Posted: 2018 Aug 29 at 12:03am
strange!
if i add a copy of this source in the same plugin folder 
then i get two plugin entries, both with the two desired submenus:

folder structure:
plugins
Test
test1.pyp
test2.pyp
icon.png
now i get:
Plugins
Test
Test1 Plugin
Submenu1
Submenu2
Test2 Plugin
Submenu1
Submenu2

but if i remove one pyp,
the remaining one does not show the submenus!
how can i use only one pyp and show a submenu?

???



Edited by indexofrefraction - 2018 Aug 29 at 5:09am
Back to Top
indexofrefraction View Drop Down
Member
Member
Avatar

Joined: 2018 Mar 08
Online Status: Offline
Posts: 9
Direct Link To This Post Posted: 2018 Aug 30 at 1:17am
no help here? 
i tried for hours, but still cant create a plugin 
with a sub menu to execute different actions
:/
Back to Top
Yannick Puech View Drop Down
Forum Moderator
Forum Moderator


Joined: 2011 Apr 13
Location: Spain
Online Status: Offline
Posts: 1143
Direct Link To This Post Posted: 2018 Aug 30 at 3:03am
Hi,

Sorry for the late answer.

There are limitations with GetSubContainer() and the "Plugins" menu.
If there is only one plugin registered then its menu structure returned by GetSubContainer() is not taken into account. But if the plugin is added to another menu then it is shown as expected.

So the solution is to register a CommandData plugin with c4d.PLUGINFLAG_HIDEPLUGINMENU flag. Then the plugin can be added to any other menu either manually or with code using the menu functions in c4d.gui module.




MAXON
Developer Support
Back to Top
indexofrefraction View Drop Down
Member
Member
Avatar

Joined: 2018 Mar 08
Online Status: Offline
Posts: 9
Direct Link To This Post Posted: 2018 Aug 30 at 3:36am
thanks yannick,

i actually had that idea this morning, but couldnt make it work

i added a 2nd pyp to the plugin with c4d.PLUGINFLAG_HIDEPLUGINMENU
but the main pyp didnt show its submenu then

are you sure this works?
(maybe i dont understand correctly)
it also needs a bogus plugin id, which is a bit odd, right?

another approach i'm trying is:
generate a PopupDialog and show it with ShowPopupDialog when the menu is selected (works already)
but i would also like to be able to have a drag off window with the (main) menu items as buttons
that could be generated by opt-selecting the menu (any tips on how to create such a window?)

best index


Edited by indexofrefraction - 2018 Aug 30 at 3:45am
Back to Top
indexofrefraction View Drop Down
Member
Member
Avatar

Joined: 2018 Mar 08
Online Status: Offline
Posts: 9
Direct Link To This Post Posted: 2018 Aug 30 at 2:58pm
a followup question to the post above:

ShowPopupDialog() has these flags 
c4d.POPUP_ALLOWUNDOCK
c4d.POPUP_ALLOWUNDOCK_REC

https://developers.maxon.net/docs/Cinema4DPythonSDK/html/modules/c4d.gui/index.html?highlight=first_popup_id#c4d.gui.ShowPopupDialog

what are these for?
i was hoping that you get a drag off handle, 
but i cant see anything happen if i use these flags

is there a way to make a PopupDialog sticky?
or can i create a palette containing my command?

best index



Edited by indexofrefraction - 2018 Aug 30 at 3:06pm
Back to Top
Yannick Puech View Drop Down
Forum Moderator
Forum Moderator


Joined: 2011 Apr 13
Location: Spain
Online Status: Offline
Posts: 1143
Direct Link To This Post Posted: 2018 Aug 31 at 12:22am
Your workaround with a popup dialog sounds too hacky to me.

The command can be registered with c4d.PLUGINFLAG_HIDEPLUGINMENU flag (plugin won't be shown in "Plugins" menu).
Then manually add the command to any other menu/command palette with "Customize Commands" and "Customize Menu". The menu structure returned by the command's GetSubContainer() should be dynamically added as expected.

Note it is possible to customize the Cinema menu by code from a plugin.


If you have questions related to another subject, please create a new thread.



MAXON
Developer Support
Back to Top
indexofrefraction View Drop Down
Member
Member
Avatar

Joined: 2018 Mar 08
Online Status: Offline
Posts: 9
Direct Link To This Post Posted: 2018 Sep 01 at 2:26pm
it just came to me that i dont need to write a 2nd plugin with a new plugin id for this
maybe i can just add an existing command to the menu to get the effect!

i guess you need to find the menu bc of the original plugin?
experimenting to achieve that now...
  
Back to Top
Yannick Puech View Drop Down
Forum Moderator
Forum Moderator


Joined: 2011 Apr 13
Location: Spain
Online Status: Offline
Posts: 1143
Direct Link To This Post Posted: 2018 Sep 03 at 2:55am
Originally posted by indexofrefraction

it just came to me that i dont need to write a 2nd plugin with a new plugin id for this
maybe i can just add an existing command to the menu to get the effect!
This is the solution I explained in my 2 posts in this thread.
Register the command with PLUGINFLAG_HIDEPLUGINMENU so no menu is created for the plugin command in the "Plugins" menu.
Then in the global PluginMessage() function of the plugin custom menus can be added to Cinema 4D with the message C4DPL_BUILDMENU.

You can find a code snippet showing how to customize Cinema 4D main menu in the Python SDK docs here.


If you have any follow up question please wait for the new forum platform which is expected to be online soon.





Edited by Andreas Block - 2018 Sep 03 at 9:01am
MAXON
Developer Support
Back to Top
indexofrefraction View Drop Down
Member
Member
Avatar

Joined: 2018 Mar 08
Online Status: Offline
Posts: 9
Direct Link To This Post Posted: 2018 Sep 03 at 11:41am
ok, i got that example running in my plugin...
it adds a menu in the main menu bar after plugis
but how do i get this menu to be under plugins->plugins?

if i check the plugins menu bc i get:
4 IDS_EDITOR_PLUGINS
3 IDM_EXECUTE_LAST
2 1
3 IDM_PLUGINS
2 1
3 PLUGIN_CMD_12302
3 PLUGIN_CMD_1026375

so none of the installed plugins are displayed here directly
they are all joined together under IDM_PLUGINS 

but can i get the res or bc of IDM_PLUGINS ?
tried also to find PLUGIN_CMD_53000 or CMD_53000 , but no luck 
...


Edited by indexofrefraction - 2018 Sep 03 at 12:00pm
Back to Top

Forum Jump Forum Permissions View Drop Down

Bulletin Board Software by Web Wiz Forums® version 9.61 [Free Express Edition]
Copyright ©2001-2009 Web Wiz

This page was generated in 0.105 seconds.