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

    Script to change Navigation Camera Mode (help)

    Cinema 4D SDK
    python 2024 windows
    2
    5
    830
    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.
    • joel_motionJ
      joel_motion
      last edited by

      I see this in the Documentation under Classic Resource Overview » Navigation
      "Parameter: Camera Mode

      • Parameter ID: c4d.PREF_NAVIGATION_CAMERA
      • Parameter Type: int
      • Cycle Values:
        - Cursor (c4d.PREF_NAVIGATION_CAMERA_CUR)
        - Center (c4d.PREF_NAVIGATION_CAMERA_CTR)
        - Object (c4d.PREF_NAVIGATION_CAMERA_OBJ)
        - Camera (c4d.PREF_NAVIGATION_CAMERA_CAM)
        - Custom (c4d.PREF_NAVIGATION_CAMERA_CUSTOM)"

      It also states "Parameters are accessed with C4DAtom.GetParameter()/C4DAtom.SetParameter()."
      But when I try to use that, I get the error "descriptor 'GetParameter' for 'c4d.C4DAtom' objects doesn't apply to a 'int' object."

      What I'm looking to do is write a script, that I can set to a hotkey, which will toggle between "Cursor" and "Camera" modes. I imagine this should be a simple "if/else" script.
      I run into this problem all the time when building a scene: Say you're setting up and interior/exterior of a house. Inside the house, it's helpful to use the "Camera" mode to navigate, since you're apt to suddenly fly out of the interior when using "Cursor" mode. But whenever you're dealing with the exterior of an object, "Cursor" mode is great!

      Apologies if this is basic. I'm still very much a novice. I have a design background, not computer science. Trying to learn as I go.

      i_mazlovI 1 Reply Last reply Reply Quote 0
      • i_mazlovI
        i_mazlov @joel_motion
        last edited by i_mazlov

        Hello @joel_motion,

        From how you put your goal, it looks that the easiest way to achieve this is to simply call the corresponding command

        c4d.CallCommand(440000095) # Camera Mode
        c4d.CallCommand(440000092) # Cursor Mode
        

        There's nothing special about retrieving these "magic numbers", you can easily spot them in the Script Log once actually changing the navigation mode. You can find Script Log in the Extensions menu or in a Script layout as shown by Ferdinand here.

        Cheers,
        Ilia

        MAXON SDK Specialist
        developers.maxon.net

        joel_motionJ 1 Reply Last reply Reply Quote 0
        • joel_motionJ
          joel_motion @i_mazlov
          last edited by

          @i_mazlov Thanks for the reply!

          This is what I see in the script log when I toggled the navigation preference:
          d1b8c94a-c5d0-44c5-b2fb-928a9602a175-image.png
          I can see that those command "magic numbers" you sent me are close to what I see in my script log (seemingly the "preference" number + the integer corresponding to the option).
          I'm not sure why it didn't show the c4d.CallCommand number in the script log.

          If I wanted to write the script to check what mode is currently in use, would I write something like this?

          if prefs(440000091)[c4d.PREF_NAVIGATION_CAMERA] = 4
                 c4d.CallCommand(440000092)
          

          Thanks again for taking time to respond.
          Any information or resources you could share with me would be great!

          i_mazlovI 1 Reply Last reply Reply Quote 0
          • i_mazlovI
            i_mazlov @joel_motion
            last edited by

            Hi @joel_motion,

            When you change the camera mode from the preferences dialog, the script log captures the lines you observe:

            prefs(440000091)[c4d.PREF_NAVIGATION_CAMERA] = 3
            prefs(440000091)[c4d.PREF_NAVIGATION_CAMERA] = 4
            

            where 3 and 4 actually stand for

            c4d.PREF_NAVIGATION_CAMERA_CUR
            c4d.PREF_NAVIGATION_CAMERA_CAM
            

            correspondingly and 440000091 is actually a sub-category parameter of the preferences plugin

            c4d.PREFS_NAVIGATION
            

            Please note, that prefs(440000091) is a function call that actually expands into c4d.plugins.FindPlugin(440000091, c4d.PLUGINTYPE_PREFS).

            If you'd like to retrieve or/and to set this parameter, you would actually do the same thing as script log shows to you:

            prefsPlugin: c4d.BasePlugin = c4d.plugins.FindPlugin(c4d.PREFS_NAVIGATION, c4d.PLUGINTYPE_PREFS)
            
            navigationValue: int = prefsPlugin[c4d.PREF_NAVIGATION_CAMERA]
            print(f'Current navigation value: {navigationValue}')
            
            prefsPlugin[c4d.PREF_NAVIGATION_CAMERA] = c4d.PREF_NAVIGATION_CAMERA_CAM
            
            newNavigationValue: int = prefsPlugin[c4d.PREF_NAVIGATION_CAMERA]
            print(f'Current navigation value: {newNavigationValue}')
            

            Regarding the c4d.CallCommand(440000095) function, it is captured if you change the camera mode via viewport menu: Cameras -> Navigation -> Cursor mode / Camera mode.

            Cheers,
            Ilia

            MAXON SDK Specialist
            developers.maxon.net

            joel_motionJ 1 Reply Last reply Reply Quote 0
            • joel_motionJ
              joel_motion @i_mazlov
              last edited by

              @i_mazlov

              Thank you very much for your response!

              I am not sure how long it would have taken me to figure out the "prefsPlugin: c4d.BasePlugin =... " part without your help.

              This is the code I wrote, which works exactly how I wanted it to (and now I have the script mapped to a hotkey).

              import c4d
              
              def main():
                  prefsPlugin: c4d.BasePlugin = c4d.plugins.FindPlugin(c4d.PREFS_NAVIGATION, c4d.PLUGINTYPE_PREFS)
              
                  navigationValue: int = prefsPlugin[c4d.PREF_NAVIGATION_CAMERA]
                  
                  if navigationValue == 3:
                      prefsPlugin[c4d.PREF_NAVIGATION_CAMERA] = c4d.PREF_NAVIGATION_CAMERA_CAM
                      
                  else:
                       prefsPlugin[c4d.PREF_NAVIGATION_CAMERA] = c4d.PREF_NAVIGATION_CAMERA_CUR
              
              if __name__=='__main__':
                  main()
              

              Thanks again!

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