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

    Python: How to get axis scale from the preference settings?

    Cinema 4D SDK
    2
    3
    627
    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.
    • R
      rownn
      last edited by

      Hey everyone,

      another question. How can I get the axis scale value from the preference settings?
      I tried this ...

      wc = c4d.GetWorldContainerInstance()
      print (wc[c4d.PREF_VIEW_OBJECTAXIS_SCALE])
      

      but it only and always returns 0.

      Thx for help and greetings
      rownn

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

        Hello @rownn,

        thank you for reaching out to us. Please remember to follow the forum guidelines and add the required tags to your posting, describing the OS, programming environment and version of Cinema 4D you are using.

        The world container unfortunately does not contain all user settings. Under the hood, preferences are largely organized in preferences plugins which carry their settings on the node representing that plugin. So, to read and write such settings, one must retrieve and interact with these plugins. The code at the end of the posting goes into the technical details.

        Cheers,
        Ferdinand

        """Example for reading and writing arbitrary parameters in the Preferences 
        dialog of CInema 4D.
        
        The world container unfortunately does not contain all user settings. Under
        the hood, preferences are largely organized in preferences plugins which
        carry their settings on the node representing that plugin. So, to read and 
        write such settings, one must retrieve and interact with these plugins. 
        
        As discussed in:
            plugincafe.maxon.net/topic/13555
        """
        
        import c4d
        
        # The id of the preferences plugin node, there is no symbol for it, so we
        # have to hard-code it. I just happened to know that id. The only way to get
        # hold of it, is to search all plugins by their name via c4d.plugins.
        # FilterPluginList and look for plugin names that look promising. I.e.,
        # something that contains "preferences" or "prefs" in this case. That is
        # at least how I usually do it when I have to dig out some internal node.
        ID_PREFERENCES_NODE = 465001632
        
        
        def main():
            """
            """
            # Get the preferences plugin node or bail if we failed to retrieve it.
            prefs = c4d.plugins.FindPlugin(ID_PREFERENCES_NODE)
            if not isinstance(prefs, c4d.BaseList2D):
                raise RuntimeError("Could not access preferences node.")
        
            # The global settings node which primarily carries references to other
            # specialized settings nodes.
            print(prefs)
        
            # Code I did use to figure out where stuff is. The preferences are
            # basically a bunch of connected PreferenceData plugins. We now need
            # to find the node that represents the viewport tab. The code is not
            # required for what you want to do, I just left it in so that it can be
            # understood how I did came up with the magic numbers below.
            for bc, descid, _ in prefs.GetDescription(0):
                name = bc[c4d.DESC_NAME]
                if "viewport display" in name.lower():
                    print(name, descid, prefs[descid])
        
            # It will print something like this:
            #   Viewport Display (465001625, 1, 465001632) None
            #   Viewport Display ((465001625, 1, 465001632), (888, 133, 465001632))
            #       <c4d.BaseList2D object called Viewport Display/Viewport ...
        
            # So, the second thing is what we are looking for.
            descIdViewportSettings = c4d.DescID(
                c4d.DescLevel(465001625, 1, 465001632),
                c4d.DescLevel(888, 133, 465001632))
        
            viewportPrefs = prefs[descIdViewportSettings]
        
            # We could have also searched for the viewport settings plugin right away
            # in the plugins of Cinema as described at the top. 465001625 is its ID, so
            # one could also call c4d.plugins.FindPlugin(465001625) to get the viewport
            # plugin right away.
        
            # The viewport settings node.
            print(viewportPrefs)
        
            # And your value.
            print(viewportPrefs[c4d.PREF_VIEW_OBJECTAXIS_SCALE])
        
            # Since this is just a node, a BaseList2D, we can also write values.
        
            # Set the axis scale to 50%.
            viewportPrefs[c4d.PREF_VIEW_OBJECTAXIS_SCALE] = .5
        
            # Push an update event to Cinema 4D.
            c4d.EventAdd()
        
        
        if __name__ == '__main__':
            main()
        
        

        MAXON SDK Specialist
        developers.maxon.net

        1 Reply Last reply Reply Quote 1
        • ferdinandF
          ferdinand
          last edited by

          Hello @rownn,

          without any further questions or replies, we will consider this thread as solved by Monday the 20th and flag it accordingly.

          Thank you for your understanding,
          Ferdinand

          MAXON SDK Specialist
          developers.maxon.net

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