Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    How to add "scripts" to a menu?

    Cinema 4D SDK
    2024 python
    2
    4
    1.3k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic was forked from Building menus with C4DPL_BUILDMENU in S26+ ferdinand
    This topic has been deleted. Only users with topic management privileges can see it.
    • M
      mogh
      last edited by ferdinand

      Hi,
      is there a way to insert scripts (*.py) into a menu ?

      by the way there are still spelling errors in the docu "MENURESOURCE_SEPARATOR vs MENURESOURCE_SEPERATOR"
      https://developers.maxon.net/docs/py/2024_3_0/consts/MENURESOURCE.html?highlight=menuresource_separator

      kind regards
      mogh

      ferdinandF 1 Reply Last reply Reply Quote 0
      • ferdinandF
        ferdinand @mogh
        last edited by ferdinand

        Hey @mogh,

        Thank you for reaching out to us. Please open a new thread for questions that do not exactly match an existing thread, I have forked your question.

        Thank you for pointing out the issue in the documentation, I have fixed it and the other occurrence in Plugin Structure. Regarding your question, it depends a bit on what you mean with "script". I assume you are talking about a Script Manager script? But long story short, to add something to a menu it must be a command (or a submenu). A random Python file on disk does not satisfy this condition. But the Script Manager creates commands for all its scripts. You can look them up using the Command Manager:

        6e5775a6-aff5-4c05-953d-2297b3df4be8-image.png

        The problem with this is that the Script Manager script command IDs are assigned dynamically and might change on restart when you add new scripts (the IDs are assigned to the scripts in alpha-numerically order on startup). But there is c4d.GetDynamicScriptID with which you can figure out the ID of a script. @m_adam once wrote this code example where he demonstrated the usage of the function and the other Script Manager related functions.

        With such IDs you could then populate a menu using the f"PLUGIN_CMD_{value}" pattern shown in the other thread. I would however be careful with c4d.C4DPL_BUILDMENU, there is a good chance that Script Manager script command IDs have not yet been established at this point. So, you might have to inject your menu at a later point. I did not test that, this is just a hunch 🙂

        When you just want to run your own Python scripts which are not in the search path of the Script Manager, you will have to write your own CommandData wrappers to insert them into menus.

        Cheers,
        Ferdinand

        MAXON SDK Specialist
        developers.maxon.net

        M 1 Reply Last reply Reply Quote 1
        • M
          mogh @ferdinand
          last edited by

          My intention was not to highjack but add to the topic - anyway back to the topic ...

          Thanks for your quick summary of the pitfalls of this problem. While it is good to know that scripts get dynamical IDs, in my opinion it might juts be more reasonable to create small plugins for each script to insert them Properly.

          @ferdinand said in How to add "scripts" into a menu?:

          this is just a hunch

          the joke's on me I guess 😉

          cheers mogh

          ferdinandF 1 Reply Last reply Reply Quote 0
          • ferdinandF
            ferdinand @mogh
            last edited by ferdinand

            Hey @mogh,

            I know that you did not meant any harm and the word hijack was a bit strong - which is why reworded that before you answered. But topics should remain focused on a singular thing, the specific question of the original poster, rather than being a collection of questions from multiple people which roughly align with whatever broader topic they see embodied in a thread.

            Cheers,
            Ferdinand

            MAXON SDK Specialist
            developers.maxon.net

            1 Reply Last reply Reply Quote 0
            • First post
              Last post