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 to change the projection type for a created material.

    Cinema 4D SDK
    2023 python windows
    2
    5
    737
    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.
    • L
      lednevandrey
      last edited by

      For the object selected in the scene, a new material tag is added. By default, the projection type of the new material tag is set to spherical.
      How to change the projection type of the new material tag?

      # Step 1: Create a new material
          material = c4d.BaseMaterial(c4d.Mmaterial)  # Creating new material
          material.SetName("MyMat")  # Assigning a name to a material
          material[c4d.TEXTURETAG_PROJECTION] = c4d.TEXTURETAG_PROJECTION_UVW  
      

      For a newbie in Python programming, it is very difficult to understand the large volume of documentation.
      In other programming environments, for example for AfterEffects, there are functions that show the assigned effects, and field values, for a certain scene object.
      Is there a trick that allows you to print the field properties of a certain tag of such an object?

      1 Reply Last reply Reply Quote 0
      • L
        lednevandrey
        last edited by

        material[c4d.TEXTURETAG_PROJECTION] = c4d.TEXTURETAG_PROJECTION_UVW

        This approach doesn't work.???

        ferdinandF 1 Reply Last reply Reply Quote 0
        • ferdinandF
          ferdinand @lednevandrey
          last edited by

          Hey @lednevandrey,

          your code is 50% correct 😉 The assignment pair TEXTURETAG_PROJECTION and TEXTURETAG_PROJECTION_UVW is correct and expresses setting the projection of a material tag to UVW. But they are associated with a Material Tag and not a material (as you attempt in your code). So, what you are trying there is systematically not possible, a material has no projection type. You need an object and its material tag. As a little warning, the type and symbol for a Material Tag are c4d.TextureTag and c4d.Ttexture.

          I am not so sure what you mean with '' but you might want to read Python SDK - Python Console: Drag and Drop. Something like TEXTURETAG_PROJECTION is called a parameter in Cinema 4D and you can explore them via drag and drop in the Python console.

          Cheers,
          Ferdinand

          MAXON SDK Specialist
          developers.maxon.net

          1 Reply Last reply Reply Quote 0
          • L
            lednevandrey
            last edited by lednevandrey

            Hey Ferdinand!

            To the request

            Material

            Shows this message
            <c4d.TextureTag object called Material/Material with ID 5616 at 2260375040320>

            But when I try to change the value of TEXTURETAG_PROJECTION with the line

            Material[c4d.TEXTURETAG_PROJECTION] = c4d.TEXTURETAG_PROJECTION_UVW

            As I understand, I refer to the TEXTURE tag....

            then I get the message
            NameError: name 'Material' is not defined. Did you mean: 'material'?

            And in the description of the parameters c4d.TextureTag, there is no value TEXTURETAG_PROJECTION.

            How to correctly refer to the material tag?

            1 Reply Last reply Reply Quote 0
            • ferdinandF
              ferdinand
              last edited by ferdinand

              Hey @lednevandrey,

              without wanting to be rude, I really struggle with understanding what you want to convey. Material[c4d.TEXTURETAG_PROJECTION] = c4d.TEXTURETAG_PROJECTION_UVW does not work because Python is case sensitive and you gave your BaseMaterial instance the symbol material. So, Python is complaining about that.

              But as said before, a material, i.e., BaseMaterial is not the right place to set the projection. It is the counter part to the thing you see in the Material Manager of Cinema 4D and has no projection. The projection is set in the Material Tag, which slightly confusingly is called TextureTag in the API.

              Cheers,
              Ferdinand

              """Assigns the first material in the document to the selected object and sets its projection to UVW.
              """
              
              import c4d
              import 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:
                  """Called by Cinema 4D when the script is being executed.
                  """
                  if not op:
                      raise ValueError("Please select an object.")
                  
                  # Get the first material in the document.
                  material: c4d.BaseMaterial = doc.GetFirstMaterial()
                  if not material:
                      raise ValueError("No materials found in the document.")
              
                  # Get the first existing texture tag on #op or create a new one when none exists.
                  tag: c4d.BaseTag = op.GetTag(c4d.Ttexture) or op.MakeTag(c4d.Ttexture)
                  if not tag:
                      raise ValueError("Failed to get or create a texture tag.")
                  
                  # Set the material and projection.
                  tag[c4d.TEXTURETAG_MATERIAL] = material
                  tag[c4d.TEXTURETAG_PROJECTION] = c4d.TEXTURETAG_PROJECTION_UVW
              
                  # Update the Cinema 4D UI.
                  c4d.EventAdd()
              
              
              if __name__ == '__main__':
                  main()
              

              MAXON SDK Specialist
              developers.maxon.net

              1 Reply Last reply Reply Quote 1
              • ferdinandF ferdinand forked this topic on
              • First post
                Last post