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 generator

    Cinema 4D SDK
    2025 python
    2
    3
    382
    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.
    • J
      james.thamesview
      last edited by

      I am using a python generator to produce sets of splines. I want the code to check the python generator object for a hair tag. Then I want to get the underlying hair material colour gradient and use that as the basis for customer hair textures to be applied to the splines
      this is a snippet of what I have so far (mainly using copilot to help me)
      for tag in op.GetTags():

              #print (tag,tag.GetType())
                  if tag.GetType() == c4d.Thairmaterial:
                      material_tag = tag
                      material = material_tag.GetMaterial()
                      source_gradient = material[c4d.HAIR_MATERIAL_COLOR_GRADIENT]
                      gradient = hair_material[c4d.HAIR_MATERIAL_COLOR_GRADIENT]
                      for i in range(gradient.GetKnotCount()):
                          knot = gradient.GetKnot(i)
                          print(f"Knot {i}: Color = {knot.col}, Position = {knot.pos}")     
              
              break
      

      This fails with "AttributeError: 'c4d.BaseTag' object has no attribute 'GetMaterial' "
      It looks to me like python is not seeing tag as a Hair material and/or I am calling the wrong method to get the underlying material.
      So two questions:
      1: how do I correct this
      2: what should I be searching for in the docs to be able to work this out for myself

      Thanks in advance

      Regards

      Jim

      i_mazlovI 1 Reply Last reply Reply Quote 0
      • i_mazlovI
        i_mazlov @james.thamesview
        last edited by i_mazlov

        Hi Jim.

        Thanks for reaching out to us! According to our Support Procedures:

        We cannot provide support for the side-effects of unexperienced users using AI models to write code.

        Your code contains multiple issues that were likly hallutinated by AI tool you're using:

        1. There's no such function "GetMaterial()" on the hair material tag
        2. There's no such ID c4d.HAIR_MATERIAL_COLOR_GRADIENT (it's c4d.HAIRMATERIAL_COLOR_GRADIENT)
        3. The GetKnot() returns you not a class instance rather a dictionary, so accessing its content is performed by using the subscript operator rather than dot operator.

        I would also suggest you reading through the following manuals, which I supposed would be of great use for you:
        How to get/set parameters using Drag&Drop
        How to use Visual Studio Code Integration

        Using the VSCode integration allows you to use syntax highlight as well as IntelliSense, which would immediately give you hints on the correct usage of functions and methods, as well as an in-place documentation.

        Please find the suggested code snipet for your problem below.

        Cheers,
        Ilia

        Code snippet for the Script Manager:

        import c4d, mxutils
        
        doc: c4d.documents.BaseDocument  # The currently active document.
        op: c4d.BaseObject | None  # The primary selected object in `doc`. Can be `None`.
        
        def main() -> None:
            # Find hair tag on the active object
            tag = mxutils.CheckType(op.GetTag(c4d.Thairmaterial), c4d.BaseTag)
            # Retrieve the linked material
            material = mxutils.CheckType(tag[c4d.HAIRMATERIAL_TAG_LINK], c4d.BaseMaterial)
            # Retrieve the gradient attribute
            gradient = mxutils.CheckType(material[c4d.HAIRMATERIAL_COLOR_GRADIENT], c4d.Gradient)
            # Iterate gradient knots
            for i in range(gradient.GetKnotCount()):
                print(gradient.GetKnot(i))
        
        if __name__ == '__main__':
            main()
            c4d.EventAdd()
        

        MAXON SDK Specialist
        developers.maxon.net

        J 1 Reply Last reply Reply Quote 0
        • J
          james.thamesview @i_mazlov
          last edited by

          @i_mazlov
          Thanks for your help. I using visual studio code as you suggested and am getting to grips with the Drag and Drop to assist with parameter getting and setting.

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