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
    • Unread
    • Recent
    • Tags
    • Users
    • Login
    1. Maxon Developers Forum
    2. merkvilson
    • Profile
    • Following 0
    • Followers 7
    • Topics 42
    • Posts 114
    • Best 8
    • Controversial 0
    • Groups 0

    merkvilson

    @merkvilson

    12
    Reputation
    519
    Profile views
    114
    Posts
    7
    Followers
    0
    Following
    Joined Last Online
    Email [email protected]

    merkvilson Unfollow Follow

    Best posts made by merkvilson

    • RE: How do I create a menu item on the home screen next to the buttons.

      Create a ".pyp" file in the Plugins directory(my_menu.pyp) and try this example.

      import c4d
      from c4d import gui
      
      def EnhanceMainMenu():
          mainMenu = gui.GetMenuResource("M_EDITOR")                 
          pluginsMenu = gui.SearchPluginMenuResource()               
      
      
          menu = c4d.BaseContainer()                                 
          menu.InsData(c4d.MENURESOURCE_SUBTITLE, "My Menu 1")  
          menu.InsData(c4d.MENURESOURCE_COMMAND, "PLUGIN_CMD_{}".format(c4d.Ocube))      
          menu.InsData(c4d.MENURESOURCE_SEPERATOR, True);             
          menu.InsData(c4d.MENURESOURCE_COMMAND, "PLUGIN_CMD_{}".format(c4d.Osphere))     
          menu.InsData(c4d.MENURESOURCE_COMMAND, "PLUGIN_CMD_{}".format(c4d.Oplane))     
      
          submenu = c4d.BaseContainer()
          submenu.InsData(c4d.MENURESOURCE_SUBTITLE, "Menu 2 ")
          submenu.InsData(c4d.MENURESOURCE_COMMAND, "PLUGIN_CMD_{}".format(c4d.Onull))     
          menu.InsData(c4d.MENURESOURCE_SUBMENU, submenu)
      
          if pluginsMenu: mainMenu.InsDataAfter(c4d.MENURESOURCE_STRING, menu, pluginsMenu)
          else: mainMenu.InsData(c4d.MENURESOURCE_STRING, menu)
      
      def PluginMessage(id, data):
          if id==c4d.C4DPL_BUILDMENU:
              EnhanceMainMenu()
      
      posted in Cinema 4D SDK
      merkvilsonM
      merkvilson
    • RE: Python: Selection tag

      Probably there is a better way but you can try this method

      selectionTag = op.GetTag(5673)
      c4d.CallButton(selectionTag , c4d.POLYGONSELECTIONTAG_COMMAND3)

      posted in Cinema 4D SDK
      merkvilsonM
      merkvilson
    • RE: Plugins Search Path from Preferences

      Thanks @ferdinand

      I wrote this little script for those who want to add one plugin path via the C4D script. I will update it later.
      It will NOT overwrite existing paths. Restart is required for instant result.

      import c4d
      import os
      import json
      
      
      def add_plugin_path(path, restart = False):
      
          if os.path.exists(path): new_path = path.replace("\\", "/")
          else:
              print("Path does not exists")
              return
      
          prefs_folder      = c4d.storage.GeGetC4DPath(c4d.C4D_PATH_PREFS)
          prefs_path        = os.path.dirname(prefs_folder)
          plugins_json_path = os.path.join(prefs_path, 'plugins.json')
      
      
          if os.path.exists(plugins_json_path):
              with open(plugins_json_path,'r',encoding="utf-8-sig") as plugins: plugins_json_raw = plugins.read()
              plugins_dict = json.loads(plugins_json_raw)
              content_dict = plugins_dict["content"]["_impl"]["_data"][1]["content"]
      
              # Check if the new path is already in Plugins Path
              for content_path in content_dict:
                  if os.path.normpath(content_path["_0"]["_path"]) == os.path.normpath(new_path):
                      print(f"'{new_path}' is already in Plugins Path.")
                      return
      
          else:
              plugins_dict = {
                  'identification': 'plugins',
                  'content': {
                      'referenceDataType': 'net.maxon.interface.datadictionary-C',
                          '_impl': {
                              '_mode': 2,
                              '_data': [
                                  {
                                      'dataType': 'net.maxon.datatype.id',
                                      'content': 'searchPaths'
                                  },
                                  {
                                      'dataType': '(net.maxon.interface.url-C,bool)',
                                      'isArray': True,
                                      'content': []}]}}}
      
      
      
          # Create new path content
          new_content = {
              "_0": {
                  "referenceIndex": len(plugins_dict["content"]["_impl"]["_data"][1]["content"]),
                  "referenceDataType": "net.maxon.interface.url-C",
                  "_scheme": "file",
                  "_path": new_path,
                  "_authority": {},
                  "_data": {}
              },
              "_1": True
          }
      
          # Append the new path to the list of paths
          plugins_dict["content"]["_impl"]["_data"][1]["content"].append(new_content)
      
          # Convert the dictionary back to a JSON string
          updated_plugins_dict = json.dumps(plugins_dict, indent=4)
      
          # Write the updated dictionary back to a JSON file
          with open(plugins_json_path, 'w') as plugins_json: plugins_json.write(updated_plugins_dict)
      
          if restart: c4d.RestartMe()
      
      custom_path = r"/Path/To/Plugin/Directory/"
      
      add_plugin_path(path = custom_path, restart = False)
      
      posted in Cinema 4D SDK
      merkvilsonM
      merkvilson
    • RE: INCLUDE user-defined res files

      I'm such an idiot 😂 Seems like the same code can be applied to user-defined descriptions.
      SOLVED! 👌

      posted in Cinema 4D SDK
      merkvilsonM
      merkvilson
    • RE: Change Hair preferences with Python API

      @mikeudin
      We all have to learn C++ 😅

      posted in Cinema 4D SDK
      merkvilsonM
      merkvilson
    • RE: how to control the on/off of a node in expresso?

      I guess you want to create a node of the node.
      alt text

      posted in Cinema 4D SDK
      merkvilsonM
      merkvilson
    • RE: How do I create a menu item on the home screen next to the buttons.

      image.png

      posted in Cinema 4D SDK
      merkvilsonM
      merkvilson
    • RE: Find C4D's directory without C4D

      Thanks, Maxime! 🙂

      I tested the code, and it works.
      But this is not what I exactly wanted.

      As I mentioned, the problem is that some users are installing C4D in a custom directory and I can't find preferences path nor an actual installation path.

      I also tried os.walk() Method to find MAXON directory, but it has two significant problems.

      1. It's too slow
      2. there are several folders called MAXON

      The only thing that users can define is the release number, and I have to find it according to the string, for example, "R20".

      Here is how the installer works.

      alt text

      It works on most of the computers but some users already reported that it can't find their directory so they are forced to manually define it but most of them are defining global directory. If you remember, I had to remove symbolcache file and this is one of the reasons why I made this installer.

      posted in Cinema 4D SDK
      merkvilsonM
      merkvilson

    Latest posts made by merkvilson

    • RE: Plugins Search Path from Preferences

      Thanks @ferdinand

      I wrote this little script for those who want to add one plugin path via the C4D script. I will update it later.
      It will NOT overwrite existing paths. Restart is required for instant result.

      import c4d
      import os
      import json
      
      
      def add_plugin_path(path, restart = False):
      
          if os.path.exists(path): new_path = path.replace("\\", "/")
          else:
              print("Path does not exists")
              return
      
          prefs_folder      = c4d.storage.GeGetC4DPath(c4d.C4D_PATH_PREFS)
          prefs_path        = os.path.dirname(prefs_folder)
          plugins_json_path = os.path.join(prefs_path, 'plugins.json')
      
      
          if os.path.exists(plugins_json_path):
              with open(plugins_json_path,'r',encoding="utf-8-sig") as plugins: plugins_json_raw = plugins.read()
              plugins_dict = json.loads(plugins_json_raw)
              content_dict = plugins_dict["content"]["_impl"]["_data"][1]["content"]
      
              # Check if the new path is already in Plugins Path
              for content_path in content_dict:
                  if os.path.normpath(content_path["_0"]["_path"]) == os.path.normpath(new_path):
                      print(f"'{new_path}' is already in Plugins Path.")
                      return
      
          else:
              plugins_dict = {
                  'identification': 'plugins',
                  'content': {
                      'referenceDataType': 'net.maxon.interface.datadictionary-C',
                          '_impl': {
                              '_mode': 2,
                              '_data': [
                                  {
                                      'dataType': 'net.maxon.datatype.id',
                                      'content': 'searchPaths'
                                  },
                                  {
                                      'dataType': '(net.maxon.interface.url-C,bool)',
                                      'isArray': True,
                                      'content': []}]}}}
      
      
      
          # Create new path content
          new_content = {
              "_0": {
                  "referenceIndex": len(plugins_dict["content"]["_impl"]["_data"][1]["content"]),
                  "referenceDataType": "net.maxon.interface.url-C",
                  "_scheme": "file",
                  "_path": new_path,
                  "_authority": {},
                  "_data": {}
              },
              "_1": True
          }
      
          # Append the new path to the list of paths
          plugins_dict["content"]["_impl"]["_data"][1]["content"].append(new_content)
      
          # Convert the dictionary back to a JSON string
          updated_plugins_dict = json.dumps(plugins_dict, indent=4)
      
          # Write the updated dictionary back to a JSON file
          with open(plugins_json_path, 'w') as plugins_json: plugins_json.write(updated_plugins_dict)
      
          if restart: c4d.RestartMe()
      
      custom_path = r"/Path/To/Plugin/Directory/"
      
      add_plugin_path(path = custom_path, restart = False)
      
      posted in Cinema 4D SDK
      merkvilsonM
      merkvilson
    • Plugins Search Path from Preferences

      Hello.
      I'm trying to access and subsequently modify Plugins Search Path, which is located in the Preferences window.
      I have to accomplish this task via a Python script (not from pyp file).

      I have a problem at the first step when I'm trying to simply access its value and print it.

      import c4d
      
      pid, att = None, c4d.plugins.GetFirstPlugin()
      while att:
          if 'Plugins/Plugins' in str(att):
              pid = att.GetID()
              break
          att = att.GetNext()
      
      prefs = c4d.plugins.FindPlugin(pid)
      plugins = prefs[c4d.PREF_PLUGINS_PATHS]
      print(prefs[c4d.PREF_PLUGINS_PATHS])
      

      In this example, it prints an empty string even though several paths are already added.

      However, if I open the preferences window, it prints the correct values instead of an empty string. Is it possible to bypass opening the prefs window and make the script work correctly?

      posted in Cinema 4D SDK python
      merkvilsonM
      merkvilson
    • RE: Dialog window with palette

      Is it possible to save and load the group window in a way similar to the l4d files?

      posted in Cinema 4D SDK
      merkvilsonM
      merkvilson
    • RE: How do I create a menu item on the home screen next to the buttons.

      image.png

      posted in Cinema 4D SDK
      merkvilsonM
      merkvilson
    • RE: How do I create a menu item on the home screen next to the buttons.

      Create a ".pyp" file in the Plugins directory(my_menu.pyp) and try this example.

      import c4d
      from c4d import gui
      
      def EnhanceMainMenu():
          mainMenu = gui.GetMenuResource("M_EDITOR")                 
          pluginsMenu = gui.SearchPluginMenuResource()               
      
      
          menu = c4d.BaseContainer()                                 
          menu.InsData(c4d.MENURESOURCE_SUBTITLE, "My Menu 1")  
          menu.InsData(c4d.MENURESOURCE_COMMAND, "PLUGIN_CMD_{}".format(c4d.Ocube))      
          menu.InsData(c4d.MENURESOURCE_SEPERATOR, True);             
          menu.InsData(c4d.MENURESOURCE_COMMAND, "PLUGIN_CMD_{}".format(c4d.Osphere))     
          menu.InsData(c4d.MENURESOURCE_COMMAND, "PLUGIN_CMD_{}".format(c4d.Oplane))     
      
          submenu = c4d.BaseContainer()
          submenu.InsData(c4d.MENURESOURCE_SUBTITLE, "Menu 2 ")
          submenu.InsData(c4d.MENURESOURCE_COMMAND, "PLUGIN_CMD_{}".format(c4d.Onull))     
          menu.InsData(c4d.MENURESOURCE_SUBMENU, submenu)
      
          if pluginsMenu: mainMenu.InsDataAfter(c4d.MENURESOURCE_STRING, menu, pluginsMenu)
          else: mainMenu.InsData(c4d.MENURESOURCE_STRING, menu)
      
      def PluginMessage(id, data):
          if id==c4d.C4DPL_BUILDMENU:
              EnhanceMainMenu()
      
      posted in Cinema 4D SDK
      merkvilsonM
      merkvilson
    • Dialog window with palette

      How to create dialog window with pre-loaded pallete(l4d file)?

      I'm not talking about BITMAPBUTTON.
      I'm trying to include an actual undockable palette with all palette functionality, such as orientation change, the ability to hide/unhide text, icon size changing functionality, etc.

      I know that I can drag and drop l4d palette file into C4D and it will create a new window with the palette. I also know how to load a palette with Python script, but it will create a palette in its own window. I need to load the palette into my GeDialog window.

      19005a31-7e06-4bb0-a123-9d8e8d291e01-image.png

      posted in Cinema 4D SDK python
      merkvilsonM
      merkvilson
    • Sound effector - Volume

      How to change the sound volume of the Sound Effector via Python Script?

      posted in Cinema 4D SDK python
      merkvilsonM
      merkvilson
    • C4D crashes when removing node via MSG_MENUPREPARE

      What am I doing wrong? Need to remove the node under certain circumstances via MSG_MENUPREPARE but it crashes the C4D.
      Is it possible to somehow bypass this behavior? Is this a bug?

      
      import c4d
      import os
      
      
      class OBug_Check(c4d.plugins.ObjectData):
      
          def Message(self, node, type, data):
              if type == c4d.MSG_MENUPREPARE:
                  node.Remove()
      
              return True
      
      
      if __name__ == "__main__":
          c4d.plugins.RegisterObjectPlugin(id=1000003,
                                           str="Bug Check",
                                           g=OBug_Check,
                                           description="OBug_Check",
                                           info=c4d.OBJECT_GENERATOR,
                                           icon=None)
      
      posted in Cinema 4D SDK python
      merkvilsonM
      merkvilson
    • Prevent selection

      Is it possible to prevent object/tag plugins from getting selected when clicking on them?

      Currently, If I click on let's say object generator plugin, it gets highlighted in the viewport, highlighted in the objects manager and its attributes manager shows on.
      I want to change the behavior, so if I have selected another non-plugin object and its attributes managers are visible I want to keep it even if I click the plugin object in the scene or the objects manager.

      posted in Cinema 4D SDK python
      merkvilsonM
      merkvilson
    • Material node plugin

      Is it possible to create a Python Node Plugin for the Material node?
      I need something as simple as a node with Bool output or the String output port.

      If not, are there any plugins for implementing such feature?

      posted in Cinema 4D SDK python
      merkvilsonM
      merkvilson