How to create a radial (pie) menu?
-
Hello, i'd like to create a radial (pie) menu in Python similar to M_GLOBAL_POPUP (V key), but without submenus - just regular commands instead.
Is that possible?
In similar thread was a mention that this can be done using GeDialog and GeUserArea classes. Maybe somebody can show little example of it?
-
Hi @Gaal-Dornik
Yes, you can create just regular command with
c4d.gui.ShowPopupDialog
Just like this:import c4d def main() -> None: menu = c4d.BaseContainer() # Add some commands menu.InsData(5159, "CMD") menu.InsData(1007455, "CMD") menu.InsData(1018544, "CMD") # Show the popup menu c4d.gui.ShowPopupDialog(cd=None, bc=menu, x=500, y=500) if __name__ == '__main__': main()
And this is the result:
For more information about
c4d.gui.ShowPopupDialog
, you can go to This page.And about your question:
How to create a radial (pie) menu?
I've done some research on this:
- Just using
c4d.gui.ShowPopupDialog
to create the radial menu. But I don't like the style of that. I want to highly customizable of UI creation methed. - Use
c4d.gui.GeUserArea
. we can usec4d.gui.GeUserArea
to draw anything we want. But unfortunately, we can't just keep the UI widgets and make the background Dialog disappear. - Use third-party UI Library like PySide(PyQt), we can create any style of UI interface, but the problem is that Cinema 4D doesn't support third-party libraries, so we can't normally use PySide in Cinema 4D Python, While there are people in this thread who can use it, I think PySide is too big for a gadget like Radial Menu (it's fully 300MB in size).
That's it. If you have intrested or some ideas for that, please tell me.
Cheers~
Gheyret - Just using
-
Thanks for your response.
Currently i've done it using c4d.gui.ShowPopupDialog, it's not very fancy, but does the job.
- Do you know is there a way to show multiple ShowPopupDialog at once?
- Maybe i can modify the existing M_GLOBAL_POPUP in Python?
-
Hello @Gaal-Dornik,
Thank you for reaching out to us. And thank you @gheyret for your community answer.
@gheyret has already lined out some of the problems that come with creating a pie menu in Cinema 4D.
Do you know is there a way to show multiple ShowPopupDialog at once?
No, that is not possible, because a popup menu is intrinsically modal in Cinema 4D, i.e., blocking. So when you have this code,
a = c4d.gui.ShowPopupDialog(cd=None, bc=menuA, x=300, y=300) b = c4d.gui.ShowPopupDialog(cd=None, bc=menuB, x=400, y=300)
the second line will only run once the user made a choice the first popup menu.
Maybe i can modify the existing M_GLOBAL_POPUP in Python?
You can do that with c4d.gui.SearchMenuResource, but I would strongly advise against doing that at runtime; at least when you do not specify what 'modify' means. You can sort of do it when
C4DPL_BUILDMENU
is emitted, but even there it is quite risky when you delete or move things.Just appending things to existing menus is always fine, you can have a look at this thread for details.
How to Deal with This?
This is not the first time the question has been asked, and while @gheyret is correct in his analysis, an external UI is not the only solution.
- Handle multiple dialogs in tandem. We before talked about this here. Below I provided a bit more detailed sketch for doing this. When you play around with this, you will see that my sketch is still quite error prone. You could tidy this up by writing more code, but this multiple dialogs in tandem thing is tricky to handle.
- The alternative is draw the menu yourself into a viewport. The menu is therefore also restricted to viewports. There were multiple plugins in the past which have done this as commercial plugins. Here one of them had been discussed. The menu itself must be then a plugin hook which provides access to view port and is also allowed to manipulate the scene.
ToolData
is one choice, in C++ we can also use aSceneHookdata
plugin.
Cheers,
FerdinandResult:
-
Wow ! @ferdinand this has opened up a whole new world of ideas for me. I've come up with some new approaches and I can't wait to give them a try.
-
Thanks for your detailed answers, i hoped there is a simpler way to do it)...
Pie menus is a very common thing nowadays, why maxon developers haven't implemented it already?
In modo for example you can create pie menus, popups...etc without any coding.
Not every user is ready/have the time/etc to learn python to build a simple popup, but almost every user needs to customize their working software.
I really hope you'll implement these features soon.