Hi, I'm sorry for the delay, but I can only confirm what you said.
In C++ it's possible to call RegisterCommandPlugin but not in Python at runtime.
So I guess the best approach is to have as you suggested a menu entry (a pre-registered c4d script or CommandData) that will then create a PopuDialog with a list of all scripts, and then it's up to you to execute them with the code @lasselauch provided.
So here an example of how to implement it.
import c4d
import os
def main():
# Gets all python script of a folder
searchPath = r"%appdata%\Roaming\Maxon\Maxon Cinema 4D R21_115_XXXXXX\library\scripts"
pythonFiles = [os.path.join(folder, f) for f in os.listdir(folder) if os.path.isfile(os.path.join(folder, f)) and f.endswith(".py")]
# Build the menu for all the entries
menu = c4d.BaseContainer()
for pythonFileId, pythonFile in enumerate(pythonFiles):
menuId = c4d.FIRST_POPUP_ID + pythonFileId
filename = os.path.basename(pythonFile)
menu.InsData(menuId, filename)
# Example to also list regular command.
# Uses POPUP_EXECUTECOMMANDS in ShowPopupDialog flag so if its a command its executed directly
menu.InsData(c4d.Ocube, "CMD")
# Display the PopupDialog
result = c4d.gui.ShowPopupDialog(cd=None, bc=menu, x=c4d.MOUSEPOS, y=c4d.MOUSEPOS, flags=c4d.POPUP_EXECUTECOMMANDS | c4d.POPUP_BELOW | c4d.POPUP_CENTERHORIZ)
# If result is bigger than FIRST_POPUP_ID it means user selected something
if result >= c4d.FIRST_POPUP_ID:
# Retrieves the selected python file
scriptId = result - c4d.FIRST_POPUP_ID
pythonFile = pythonFiles[scriptId]
# Execute it and copy the global to it ( so doc, op are accessible as well)
fl = open(pythonFile, 'rb')
code = compile(fl.read(), pythonFile, 'exec')
exec(code, globals())
# Execute main()
if __name__=='__main__':
main()
```
Cheers,
Maxime.