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

    How can i set custom Databases paths in prefs with python?

    Cinema 4D SDK
    python r21
    2
    8
    1.4k
    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
      bonsak
      last edited by bonsak

      Hi
      I have a python startup plugin that sets texture paths in Prefs>File Assets! with SetGlobalTexturePaths(...) for all workstations and render slaves. Is there a similar method for setting custom paths for node material Asset Databases (below the File Assets field) ?
      c5385534-5590-4fa6-a08b-fd3c08bbfab2-image.png

      Any help appreciated.

      -b

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

        Hello,

        these paths are accessed with a preference plugin. You can access that plugin:

        plugin = c4d.plugins.FindPlugin(1040566)
        
        paths = plugin[c4d.PREF_DATABASE_PATHS]
        
        # print paths
        print(paths)
        
        # add a path
        paths = paths + "\n" + "X:\someting" 
        plugin[c4d.PREF_DATABASE_PATHS] = paths
        
        c4d.EventAdd()
        

        best wishes,
        Sebastian

        MAXON SDK Specialist

        Development Blog, MAXON Registered Developer

        1 Reply Last reply Reply Quote 0
        • B
          bonsak
          last edited by

          Thanks! Ill try that.

          Regards
          Bonsak

          1 Reply Last reply Reply Quote 0
          • B
            bonsak
            last edited by

            So im trying to get this to work inside our startup plugin. I can set new database paths but i cant read the existing ones. So im constantly overwriting the paths field.

            import c4d
            import os, sys
            
            def PluginMessage(id, data):	
            	if id == c4d.C4DPL_PROGRAM_STARTED:
            		try: 
            			# Get plugin object
            			plugin = c4d.plugins.FindPlugin(1040566)
            			# Print plugin object
            			print('Plugin {}').format(plugin)
            
            			# Get existing paths
            			dbPaths = plugin[c4d.PREF_DATABASE_PATHS]
            			# Print existing paths
            			print('Existing DB paths {}').format(dbPaths)
            
            			# Set new paths
            			dbPaths = dbPaths + "\n" + "S:/_3D_Central/Maxon/Racecar-Assets-Redshift" 
            			plugin[c4d.PREF_DATABASE_PATHS] = dbPaths
            
            			# Print new paths
            			print('New DB paths {}').format(dbPaths)
            
            		except KeyError: 
            			sys.exit(1)
            

            print('Existing DB paths {}').format(dbPaths) doesnt print anyting even though there are entries in the Databases field.
            Am i doing something wrong?

            Regards
            Bonsak

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

              Hello,

              this particular preferences plugin only loads its data when needed. To trigger that, you can call GetDescription() which will internally load the data.

              plugin.GetDescription(c4d.DESCFLAGS_DESC_0)
              
              # Get existing paths
              dbPaths = plugin[c4d.PREF_DATABASE_PATHS]
              

              best wishes,
              Sebastian

              MAXON SDK Specialist

              Development Blog, MAXON Registered Developer

              1 Reply Last reply Reply Quote 0
              • B
                bonsak
                last edited by

                Thanks! Works like a charm!

                -b

                B 1 Reply Last reply Reply Quote 0
                • B
                  bonsak @bonsak
                  last edited by

                  Hi
                  I managed to delete my original plugin 🙂 So now im recreating it. But when i run this plugin now with the findplugin argument, it returns None. As stated higher up in the thread im trying to set custom database paths in prefs on startup.

                  import c4d
                  import os, sys
                  
                  
                  def PluginMessage(id, data):	
                  	if id == c4d.C4DPL_PROGRAM_STARTED:
                  		# try: 
                  		# Get plugin object
                  		plugin = c4d.plugins.FindPlugin(1040566)
                  
                  		# Print plugin object
                  		print('Plugin ', plugin)
                  		plugin.GetDescription(c4d.DESCFLAGS_DESC_0)
                  		dbPaths = plugin[c4d.PREF_DATABASE_PATHS]
                  		print('Existing DB paths {}').format(dbPaths)
                  

                  Any help appreciated.

                  Regards
                  Bonsak

                  1 Reply Last reply Reply Quote 0
                  • B
                    bonsak
                    last edited by

                    Ok. I figured it out. The ID was wrong. It was supposed to be 465001634

                    -b

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