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
    1. Maxon Developers Forum
    2. iplai
    3. Best
    • Profile
    • Following 2
    • Followers 0
    • Topics 1
    • Posts 16
    • Best 4
    • Controversial 0
    • Groups 0

    Best posts made by iplai

    • RE: Paste JSON Values on the Node Network?

      @bentraje
      I misunderstood your question in my previous reply.
      This is my trial:

      import c4d
      
      with open(r"Path\to\your\file.json") as f:
          c4d.CopyStringToClipboard(f.read())
          # Paste command in Node Editor
          # Command ID can be got by Script Log
          c4d.CallCommand(465002305)
      

      1.gif

      posted in Cinema 4D SDK
      iplaiI
      iplai
    • RE: C4D Parent constraint python

      @mats

      Maybe you should call the Set Inital State button of the tag and set the local offset vector as the target's negative vector.
      Here's the code:

      import c4d
      
      objList = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_SELECTIONORDER | c4d.GETACTIVEOBJECTFLAGS_CHILDREN)
      tag = c4d.BaseTag(c4d.Tcaconstraint)
      obj1, obj2 = objList[:2]
      obj1.InsertTag(tag)
      c4d.CallButton(tag, c4d.ID_CA_CONSTRAINT_TAG_SET_INITIAL_STATE) # SET INITIAL STATE
      tag[c4d.ID_CA_CONSTRAINT_TAG_PARENT] = True
      tag[30009, 1000] = obj2[c4d.ID_BASEOBJECT_REL_POSITION] * -1  # Local Offset P
      tag[30001] = obj2  # Target
      c4d.EventAdd()
      
      
      posted in Cinema 4D SDK
      iplaiI
      iplai
    • RE: Complete Replica of a Native Objects UI?

      There is a third-party module to serialize and deserialize the user data of any BaseList2D object in python dict format. Here's an example:

      c4d.ID_USERDATA: {
          (c4d.ID_USERDATA, 1): {
              c4d.DTYPE_: c4d.DTYPE_REAL,
              c4d.DESC_NAME: 'Data',
              c4d.DESC_SHORT_NAME: 'Data',
              c4d.DESC_MIN: 0,
              c4d.DESC_MAX: 1,
              c4d.DESC_STEP: 0.01,
              c4d.DESC_UNIT: c4d.DESC_UNIT_PERCENT,
              c4d.DESC_CUSTOMGUI: c4d.CUSTOMGUI_REAL,
              c4d.DESC_PARENTGROUP: (700, 5, 0),
          },
          (c4d.ID_USERDATA, 2): {
              c4d.DTYPE_: c4d.DTYPE_GROUP,
              c4d.DESC_NAME: 'Group',
              c4d.DESC_SHORT_NAME: 'Group',
              c4d.DESC_ANIMATE: c4d.DESC_ANIMATE_OFF,
              c4d.DESC_COLUMNS: 1,
              c4d.DESC_TITLEBAR: 1,
              c4d.DESC_DEFAULT: 1,
              c4d.DESC_PARENTGROUP: (),
          },
          (c4d.ID_USERDATA, 3): {
              c4d.DTYPE_: c4d.DTYPE_LONG,
              c4d.DESC_NAME: 'Data',
              c4d.DESC_SHORT_NAME: 'Data',
              c4d.DESC_UNIT: c4d.DESC_UNIT_INT,
              c4d.DESC_CUSTOMGUI: c4d.CUSTOMGUI_LONGSLIDER,
              c4d.DESC_MIN: 0,
              c4d.DESC_MAX: 100,
              c4d.DESC_STEP: 1,
              c4d.DESC_PARENTGROUP: ((700, 5, 0), (2, 1, 0)),
          },
      }
      

      Snipaste_2022-12-20_09-45-38.png
      The module is not fully tested, but it's enough for me for my daily scripting work. The processing of parameters is implemented in a way described by @ferdinand . Sort of like the .res file used by plugins developing, the json data defines the details of a parameter. If you feel like it, you can implement it yourself by refering to following functions:
      DumpParams
      DumpParamDetails
      DumpUserDataDetails
      LoadUserData
      ...
      Considering sometimes there's a huge amount of parameters, I spent a lot of time to judge and handle dirty parameters, namely the parameter has been changed, there is still no perfect way. If you don't care whether the parameter is dirty, problem goes easier. Maybe do some filters by restricting DescLevel.creator to a specific value etc.

      posted in Cinema 4D SDK
      iplaiI
      iplai
    • Geometry Axis asset node and LoadAssets

      My script works and I got what I want, but there are two problems.

      • maxon.AssetManagerInterface.LoadAssets always return False event the asset loaded successfully.

      • I set the parameters of Geometry Axis by find the param's name. Is there a better way to change the parameters?

      import maxon, c4d
      
      def loadGeometryAxis(x=0, y=0, z=0, parent: c4d.BaseList2D = None):
          repository = maxon.AssetInterface.GetUserPrefsRepository()
          if not repository:
              raise RuntimeError("Could not access the user preferences repository.")
          # Geometry Axis asset id
          assetid = maxon.Id("net.maxon.neutron.asset.geo.geometryaxis")
          assetsToLoad = [(assetid, ""), ]
          sceneNodesHook = doc.FindSceneHook(c4d.SCENENODES_IDS_SCENEHOOK_ID)
          if not sceneNodesHook:
              raise RuntimeError("Could not retrieve Scene Nodes scene hook.")
          sceneNodesHook.Message(maxon.neutron.MSG_CREATE_IF_REQUIRED)
          sceneNodes = sceneNodesHook.GetNimbusRef(maxon.neutron.NODESPACE)
          if not sceneNodes:
              raise RuntimeError("Could not retrieve Scene Nodes graph model.")
          graph = sceneNodes.GetGraph()
          didLoad = maxon.AssetManagerInterface.LoadAssets(repository, assetsToLoad, graphModelRef=graph)
          if not didLoad:
              # `didLoad` is always False, event the asset loaded successfully.
              # What's wrong?
              # raise RuntimeError(f"Could not load assets for the ids: {assetsToLoad}")
              ...
          obj = doc.GetFirstObject()
          # Is there is a better way to change the parameters?
          for bc, descid, _ in obj.GetDescription(c4d.DESCFLAGS_DESC_0):
              name = bc[c4d.DESC_NAME]
              if name == "Axis X":
                  obj[descid] = x
              if name == "Axis Y":
                  obj[descid] = y
              if name == "Axis Z":
                  obj[descid] = z
          if parent is not None:
              obj.InsertUnderLast(parent)
      
      
      if __name__ == "__main__":
          cube = c4d.BaseObject(c4d.Ocube)
          loadGeometryAxis(y=1, parent=cube)
          doc.InsertObject(cube)
      
      

      Snipaste_2022-10-28_05-56-26.png

      posted in Cinema 4D SDK python s26
      iplaiI
      iplai