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

    Fallback Shortcut

    Scheduled Pinned Locked Moved PYTHON Development
    5 Posts 0 Posters 435 Views
    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.
    • H Offline
      Helper
      last edited by

      On 25/05/2013 at 07:07, xxxxxxxx wrote:

      Hi,

      I need to implement some sort of fallback shortcut behaviour. I have a CommandData plugin
      and have to make sure it has assigned a hotkey. When the user has not set a specific hotkey
      in the Commands Manager i want to assign a fallback hotkey to the CommandData plugin.
      I have only found this thread here (Which does not really shed some light on the whole topic) :

      https://developers.maxon.net/forum/topic/4786/4668_shortcuts&KW=AddShortcut

      1. Are gui.AddShortCut() and gui.GetShortCut() the correct methods ?
      2. How does unpacking into integer values work ? The docs are not really specific about that.

      > SHORTCUT_ADDRESS - int - Manager ID. (I have no idea which manager is meant)
      >
      > ShortcutKey - int - The shortcut key is stored under ID 1 + n*10. (How do I pack for example the A key into an integer ? Or more specifically what is meant with n ?)

      Thanks for reading,
      Ferdinand

      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

        On 25/05/2013 at 07:27, xxxxxxxx wrote:

        I'll have time to take a look into the docs later. 🙂 For now, I'm wondering why
        you want to refuse the user's choice of shortcuts? And how are you planning to
        choose the fallback shortcut? What if this shortcut is already taken and how does the
        user know what the fallback shortcut is when (s)he didn't specify it him/herself?

        @1: Souns pretty much like the required methods. But I haven't used either of them yet.
        @2: I'm also not sure what the manager ID is. I think there is a little more information
        in the C++ docs. For the packing: My guess is that it works byte-wise, so you have 3 bytes
        you can fill with character ordinary numbers. Just a wild guess.

        Best,
        -Nik

        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

          On 25/05/2013 at 08:57, xxxxxxxx wrote:

          i have to admit i have not thought of the scenario where the default key is already taken.

          spent some time trying to unpack existing hotkeys. with not so much luck. the extrude tool
          hotkey bcs.

          _______________________________
          (0, 0)
          (1, 77)
          (10, 0)
          (11, 84)
          (1000, 1011183)
          (1001, 0)
          (1002, 0)
          _______________________________
          (0, 0)
          (1, 68)
          (1000, 1011183)
          (1001, 0)
          (1002, 0)
          

          i think 0 is the qualifier and 1 he hotkey from what i understand from the python docs.
          but i have no idea how i should unpack those integers with struct. i ' ll go with making
          setting a hotkey as mandatory step for now, as the whole topic seems to be an awful
          time sink. thanks for your help anyways nikklas.

          happy rendering,
          ferdinand

          1 Reply Last reply Reply Quote 0
          • H Offline
            Helper
            last edited by

            On 25/05/2013 at 13:44, xxxxxxxx wrote:

            Hi Ferdinand,

            the managers refer to the restrictions like XPresso, Object Manager, Timeline, Console, etc. The C++
            documentation states, that passing 0 will make the shortcut a global shortcut.

            The ShortcutQualifier and ShortcutKey entries in the container are not constants, but are computed
            by 0 + n * 10 for the qualifier and 1 + n * 10 for the key. Though I'm not sure what it means. For
            example, I have found a "Move Camera" shortcut via Python. There is apart from the SHORTCUT_
            entries, it has only two other entries: 0 and 1. The value of the entry with value 1 is (among the
            rule above) an item for the shortcut key. The value is 49 which is equal to an ASCII "one" (1).
            Looking at the Command Manager, the "Move Camera" command indeed has a shortcut assigned
            with the value 1.

            Here's something for the "Auto Tangents" command, it has the shortcuts "A" and "T~1" by default.
            "T~1" is a multi-key shortcut.

            import c4d
            from c4d.gui import *
              
            for i in xrange(GetShortcutCount()) :
                bc = GetShortcut(i)
                if c4d.GetCommandName(bc[c4d.SHORTCUT_PLUGINID]) == "Auto Tangents":
                    for k, v in bc:
                        print k, v
                    print "~"*20
            

            Yields

            0 0
            1 65
            1000 465001102
            1001 465001516
            1002 0
            ~~~~~~~~~~~~~~~~~~~~
            0 0
            1 84
            10 0
            11 49
            1000 465001102
            1001 465001516
            1002 0
            ~~~~~~~~~~~~~~~~~~~~
            

            84 is the ASCII code for T, 49 the ASCII code for 1. You can also use constants like KEY_F10 or
            similar which will have a value beyond the ASCII range.

            Best,
            -Niklas

            1 Reply Last reply Reply Quote 0
            • H Offline
              Helper
              last edited by

              On 25/05/2013 at 14:16, xxxxxxxx wrote:

              hi,

              thanks for the reply. ascii values, now that you said it it seems pretty obvious. thanks for your help.

              happy rendering,
              ferdinand

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