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

    Preset option with shortcut or custom layout in CommandData plugin

    Cinema 4D SDK
    3
    4
    691
    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.
    • César VoncC
      César Vonc
      last edited by

      Hello,

      I have a CommandData Python plugin that contains different options.

      When I assign a shortcut to my CommandData, or add it to a custom layout, it opens with the default options.

      Is is possible to define different shortcuts or custom layout icons that pass parameters to my CommandData plugin and then preset different options ?

      For example, imagine a shortcut that execute the Optimize command with the Unused Points checked, and an other one unchecked.
      Is it possible ?

      Thanks,

      https://code.vonc.fr

      C4DSC 1 Reply Last reply Reply Quote 1
      • C4DSC
        C4DS @César Vonc
        last edited by

        @césar-vonc

        Yes you can do this with scripts. I have done this in the past with my Dials plugin.

        Let's say you have a CommandData.
        You simply create a script which does perform c4d.CallCommand(pluginID, option)
        where <pluginID> is the plugin id of the CommandData, and option is the CallCommand::ExecuteSubID to be executed.

        You then assign a shortcut / icon to your script ... and you're done.
        You can create as many scripts / shortcuts as you want, each with a different <option> value

        1 Reply Last reply Reply Quote 1
        • ManuelM
          Manuel
          last edited by

          Hi,

          as @C4DS said, the easiest way of doing it would be to create script or CommandData to launch your main commandData.

          Using commandData would allow you to hide them from the extension menu and still being able to assign shortcut on them.

          You could also assign different shortcut and check which one has called your plugin.
          You could find the shortcut list assign to your command and react to them by order. First one will trigger this option, second that, etc.

          The issue is that you must rely on the shortcut order.

           def Execute(self, doc):
          
                  # retrieve the shortcut list
                  for x in range(c4d.gui.GetShortcutCount()):
                      shortcutBc = c4d.gui.GetShortcut(x)
                      # you have to check the combinaison, that could be a bit hard because shortcut can have up to 4 keys and modifier.
                      if shortcutBc[1000] == PLUGIN_ID:
                          for data in shortcutBc:
                              print (data)
          
          
                  # Check for specific key pressed
                  bc = c4d.BaseContainer()
                  # user ord('E') or 69 for the e key. do not use ord('e')
                  if c4d.gui.GetInputState(c4d.BFM_INPUT_KEYBOARD, ord('E'),  bc):
                      if bc[c4d.BFM_INPUT_VALUE] == 1:
                          print ("option 1")
                      else:
                          print ("e NOT PRESSED")
          
          

          Cheers,
          Manuel

          MAXON SDK Specialist

          MAXON Registered Developer

          1 Reply Last reply Reply Quote 1
          • César VoncC
            César Vonc
            last edited by

            Thank you very much ! 🙂

            https://code.vonc.fr

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