Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python 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

    Parameters for commandData Plugin

    Cinema 4D SDK
    python r20 windows
    2
    3
    591
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • B
      Boony2000
      last edited by

      Hi!

      Is it possible to add a commandData plugin multiple times to a menu, but label it differently and pass a parameter to Execute()? Or is the only way to do that via GetSubContainer()?

      I'm thinking of something like

      menu.InsData(c4d.MENURESOURCE_COMMAND, "PLUGIN_CMD_12345, menuLabel1, menuParam1)
      menu.InsData(c4d.MENURESOURCE_COMMAND, "PLUGIN_CMD_12345, menuLabel2, menuParam2)
      

      to then do something like this in Execute

      def Execute(self, doc, param):
          if param == x:
              doX()
          elif param == y:
              doY()
      

      Thanks!

      1 Reply Last reply Reply Quote 0
      • S
        s_bach
        last edited by

        Hello,

        you cannot add a new argument to the Execute() function.

        Instead, you could write a more generic CommandData plugin that stores an internal value. You could register different versions of that command using different plugin IDs and then call these different versions. Something like this:

        class DynamicCommand(plugins.CommandData):
        
            # internal value
            _setting = 0
        
            def __init__(self, setting):
                # set internal value on creation
                self._setting = setting
        
            def Execute(self, doc):
                # use internal value on execution
                print(self._setting)
        
                return True
        

        Which can be registered using constructors with different arguments:

        plugins.RegisterCommandPlugin(id_a, "Command A", c4d.PLUGINFLAG_HIDEPLUGINMENU, bitmaps.BaseBitmap(), "", DynamicCommand(123))
        plugins.RegisterCommandPlugin(id_b, "Command B", c4d.PLUGINFLAG_HIDEPLUGINMENU, bitmaps.BaseBitmap(), "", DynamicCommand(456))
        

        Best wishes,
        Sebastian

        MAXON SDK Specialist

        Development Blog, MAXON Registered Developer

        1 Reply Last reply Reply Quote 1
        • B
          Boony2000
          last edited by

          Hi Sebastian!

          Thanks for your answer. I was looking for something a little more flexible than registering multiple plugins, but I guess GetSubContainer will have to do 🙂

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