Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python 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. randymills
    R
    • Profile
    • Following 0
    • Followers 0
    • Topics 2
    • Posts 7
    • Best 0
    • Controversial 0
    • Groups 0

    randymills

    @randymills

    0
    Reputation
    23
    Profile views
    7
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    randymills Unfollow Follow

    Latest posts made by randymills

    • RE: Set VERTEXCOLOR in PaintTool

      @m_adam Thank you so much for the help, that works perfectly and thank you for showing me both methods, that's very helpful and appreciated!

      posted in Cinema 4D SDK
      R
      randymills
    • Set VERTEXCOLOR in PaintTool

      I'm working on a python script that will assign vertex color tags with random colors to each mesh in my object to prep my models for working in Substance Painter. I have a sample script that is getting me close to what I need, but I can't for the life of me figure out what I'm doing wrong with the c4d.DescID(c4d.DescLevel) setup. I continue to get the following error, which suggests the DescLevel is reading c4d.ID_CA_PAINT_TOOL_VERTEXCOLOR, c4d.DTYPE_VECTOR as an integer, even though I'm defining it as a vector (unless I'm misinterpreting this):

      Traceback (most recent call last):
        File "scriptmanager", line 43, in <module>
        File "scriptmanager", line 22, in main
      TypeError: 'c4d.Vector' object cannot be interpreted as an integer
      

      Current code sample (simplified but w/ test code included to show what I've tried already):

      import c4d
      
      doc: c4d.documents.BaseDocument  # The currently active document.
      op: c4d.BaseObject | None  # The primary selected object in `doc`. Can be `None`.
      
      def main() -> None:
          if op is None:
              raise RuntimeError("No object selected")
          
          c4d.CallCommand(431000045) # Create Vertex Color Tag
      
          doc.SetAction(1021286)  #Makes the paint tool active  
          tool = doc.GetAction()  
          tool = c4d.plugins.FindPlugin(tool, c4d.PLUGINTYPE_TOOL)
          if not tool:
              print("Vertex Paint tool not found!")
              return False
          # Set the vertex color parameter
          myVertexColor = c4d.Vector(0.0,1.0,0.0) # Green
          # myVertexColor = c4d.DescLevel(c4d.Vector(0.0,1.0,0.0)) # Green
          
          desc_level = c4d.DescLevel(c4d.ID_CA_PAINT_TOOL_VERTEXCOLOR, c4d.DTYPE_VECTOR, 0)
          # Debug: Verify the DescID
          print(f"DescID: {desc_level}")
          vertexColorSuccess = tool.SetParameter(desc_level, myVertexColor)
          if not vertexColorSuccess:
              print("Failed to set vertex color parameter!")
              return False
          # Debug: Verify the parameter was set
          current_value = tool.GetParameter(desc_level, c4d.DESCFLAGS_GET_0)
          print(f"Set color: {current_value}")
          
          # tool[c4d.ID_CA_PAINT_TOOL_VERTEXCOLOR]=myVertexColor
          # myVertexColorTag = c4d.DescID(c4d.ID_CA_PAINT_TOOL_VERTEXCOLOR, c4d.DTYPE_VECTOR, 0)
          # tool.SetParameter(myVertexColorTag, myVertexColor, c4d.DESCFLAGS_SET_0)
          c4d.CallButton(tool, c4d.ID_CA_PAINT_TOOL_APPLY_ALL) # Applies the color to all vertices
          c4d.EventAdd()
      if __name__ == '__main__':
          main()
      

      Am I thinking about this all wrong...should I be accessing/setting the vertex color a different way?

      posted in Cinema 4D SDK python r25 windows
      R
      randymills
    • RE: Files and modules organization

      AWESOME! Thanks @ferdinand!!!

      posted in Cinema 4D SDK
      R
      randymills
    • RE: Encountered a possible error in the example code in the docs for AssetDataBasesInterface.FindRepository

      Thanks Ferdinand and that does seem very plausible given that I am very new to type hinting in my code, and I have actually caught myself swapping the colon for the equals sign already. Learning from you guys every day though! I'm off to break some more sh!t! Thanks so much for your time, will let you know when I get stuck...

      posted in Cinema 4D SDK
      R
      randymills
    • RE: Encountered a possible error in the example code in the docs for AssetDataBasesInterface.FindRepository

      Ferdinand, I stand corrected and apologize for any confusion. Thank you for taking the time to explain that so thoroughly, very helpful! Having examples, like you provided in the documentation here, has been the ONLY way I've been able to navigate my way through the API. I'm quickly finding out the difference between what's included in the Python API vs. the C++ API and learning to work my way around my shortcomings as a coder, so I greatly appreciate your help and your time. After reading your response I have a much clearer understanding of this concept. Thank you!

      It does seem that I made a mistake somewhere on my end, since I tried again this morning after reconnecting my custom databases in the Asset Browser and it is working as you described above. I'm not sure what happened yesterday to cause the "issubclass() arg 1 must be a class" error, but it is not reproduceable this morning, and changing the class in maxon.Cast back to "AssetRepositoryRef" now works. I'll continue testing and let you know if I come across this issue again, but I can't seem to reproduce it today and it's working as intended. Would resetting the databases in the Asset Browser make sense to you as to why it may have solved this issue on my end? Could I have stored something other than a subclass in memory somehow?

      Again, thank you for your time!

      posted in Cinema 4D SDK
      R
      randymills
    • Encountered a possible error in the example code in the docs for AssetDataBasesInterface.FindRepository

      I have been working on a bit of code that versions up an asset automatically based on the timestamp of a master asset and I was having a really hard time figuring out how to properly assign the custom database to the new version. I was using the example for AssetDataBasesInterface.FindRepository found here https://developers.maxon.net/docs/py/2024_4_0a/modules/maxon_generated/frameworks/asset/interface/maxon.AssetDataBasesInterface.html#maxon.AssetDataBasesInterface.FindRepository, but I think there may be an error in the code.

      I was consistently getting an issubclass error when running the example code:

      url: maxon.Url = maxon.Url(r"/Volumes/database")
      obj: maxon.ObjectRef = maxon.AssetDataBasesInterface.FindRepository(url)
      if obj.IsNullValue():
          raise RuntimeError(f"Could not establish repository for: {url}.")
      
      # Cast #obj to an AssetRepositoryRef. What #obj must be cast to depends on the repository #url
      # is representing. But all repositories are of type AssetRepositoryInterface, so a ref for that
      # will give access to all common asset repository methods.
      repo: maxon.AssetRepositoryRef = maxon.Cast(maxon.AssetRepositoryRef, obj)
      if repo.IsNullValue():
          raise RuntimeError(f"Could not establish repository for: {url}.")
      

      After reading a little more about issubclass() I figured out that I needed to define the class to Cast as maxon.AssetRepositoryInterface instead of maxon.AssetRepositoryRef and that seems to work perfectly.

      The updated version looks like this and works for me:

      url: maxon.Url = maxon.Url(r"/Volumes/database")
      obj: maxon.ObjectRef = maxon.AssetDataBasesInterface.FindRepository(url)
      if obj.IsNullValue():
          raise RuntimeError(f"Could not establish repository for: {url}.")
      
      # Cast #obj to an AssetRepositoryRef. What #obj must be cast to depends on the repository #url
      # is representing. But all repositories are of type AssetRepositoryInterface, so a ref for that
      # will give access to all common asset repository methods.
      repo: maxon.AssetRepositoryRef = maxon.Cast(maxon.AssetRepositoryInterface, obj)
      if repo.IsNullValue():
          raise RuntimeError(f"Could not establish repository for: {url}.")
      

      Thought I'd post here in case anyone else is struggling with this as hard as I've been!

      posted in Cinema 4D SDK python 2024
      R
      randymills
    • RE: TexBox CustomGUI for Python?

      Was there any further investigation into this topic? We are trying to add a drag and drop field to our python dialog for textures from image assets in the asset browser...I can make a separate post, but scouring the forum first for relevant articles.

      posted in Cinema 4D SDK
      R
      randymills