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. lednevandrey
    3. Posts
    L
    • Profile
    • Following 0
    • Followers 0
    • Topics 3
    • Posts 8
    • Best 0
    • Controversial 0
    • Groups 0

    Posts made by lednevandrey

    • RE: What is the meaning of code like `doc: c4d.documents.BaseDocument`?

      Hello, Ferdinand!

      Thank you for your attention to my question, your time, and your academic explanations.

      posted in Cinema 4D SDK
      L
      lednevandrey
    • What is the meaning of code like `doc: c4d.documents.BaseDocument`?

      Hey Ferdinand!

      Thank you for the clarification.
      Forgive my ignorance, I am new to Python, give me a link to the material describing the notation...

      doc: c4d.documents.BaseDocument  # The currently active document.
      op: c4d.BaseObject | None  # The primary selected object in `doc`. Can be `None`
      def main() -> None:
      

      I understand that the literals "doc:", "op:" denote variables, but variables are assigned using the "=" sign, and here the ":" sign is used.
      What is the difference?

      "def main() -> None:" as I understand it, indicates that the main() function does not return anything.

      Could you send me a link where I can read about this notation?


      edit (@ferdinand): I have forked this question since it deviated from the subject of the original posting. Please open new topics for new subjects. But since this question comes up again and again, I decided to answer it in an exhaustive manner for future reference. This subject is technically out of scope of support, as it is about a Python feature and we cannot teach you how Python works (but I made here an exception as this keeps confusing beginners).

      posted in Cinema 4D SDK python
      L
      lednevandrey
    • RE: How to change the projection type for a created material.

      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?

      posted in Cinema 4D SDK
      L
      lednevandrey
    • RE: How to change the projection type for a created material.

      material[c4d.TEXTURETAG_PROJECTION] = c4d.TEXTURETAG_PROJECTION_UVW

      This approach doesn't work.???

      posted in Cinema 4D SDK
      L
      lednevandrey
    • How to change the projection type for a created material.

      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?

      posted in Cinema 4D SDK 2023 python windows
      L
      lednevandrey
    • RE: images for the material shaders not assigned to the specified shader

      Hi Ferdinand!
      Thank you. It worked.

      posted in Cinema 4D SDK
      L
      lednevandrey
    • RE: images for the material shaders not assigned to the specified shader

      Hi Ferdinand!

      Thank you for your attention to my problem.
      I took into account your comments and reworked the script. But when I run it, the console shows an error:

      ModuleNotFoundError:No module named 'mxutils'

      How to install a module 'mxutils' in the C4D environment?

      posted in Cinema 4D SDK
      L
      lednevandrey
    • images for the material shaders not assigned to the specified shader

      Hello everyone.

      I am new to C4D scripts.
      I may have posted this message in the wrong section of this forum, please let me know if that happened.

      I want to create a script to get a material with certain properties and assign it to an object selected in the scene.
      For the Brightness and Displacement channels, images from the disk are added.

      import c4d
      from c4d import storage
      
      def main():
      
          # doc = c4d.documents.BaseDocument
      
          # Step 1: Create a new material
          material = c4d.BaseMaterial(c4d.Mmaterial)  # Creating new material
          material.SetName("MyMat")  # Assigning a name to a material
          doc.InsertMaterial(material)  # type: ignore # Adding material to a document
      
          # Step 2: Disable the Color Channel
          material[c4d.MATERIAL_USE_COLOR] = False
      
          # Step 3: Disable the Reflectivity channel
          material[c4d.MATERIAL_USE_REFLECTION] = False
      
           #Step 4: Enable the Brightness channel
          material[c4d.MATERIAL_USE_LUMINANCE] = True
          
          # Step 5: Select a texture file for the Brightness channel
          luminance_texture_path = storage.LoadDialog(type=c4d.FILESELECTTYPE_IMAGES, title="Select a texture for the Brightness channel")
          if luminance_texture_path:  # Checking if the user has selected a file
              luminance_shader = c4d.BaseShader(c4d.Xbitmap)  # Create a shader for the image
              luminance_shader[c4d.BITMAPSHADER_FILENAME] = luminance_texture_path  # Assigning a path to a file
              material[c4d.MATERIAL_LUMINANCE_SHADER] = luminance_shader  # Assigning a shader to a material
              
          # Step 6: Enable the DISPLACEMENTt channel
          material[c4d.MATERIAL_USE_DISPLACEMENT] = True
      
          # Step 7: Select a texture file for the Displacement channel
          displacement_texture_path = storage.LoadDialog(type=c4d.FILESELECTTYPE_IMAGES, title="Select a texture for the Displacement channel")
          if displacement_texture_path:  # Checking if the user has selected a file
              displacement_shader = c4d.BaseShader(c4d.Xbitmap)  # Create a shader for the image
              displacement_shader[c4d.BITMAPSHADER_FILENAME] = displacement_texture_path  # Assigning a path to a file
              material[c4d.MATERIAL_DISPLACEMENT_SHADER] = displacement_shader # Assigning a path to a file
      
          # Updating the material to apply the changes
          material.Update(True, True)
      
          # Step 8: Assign material to selected objects
          selected_objects = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_0)  # type: ignore # Get a list of selected objects
          if selected_objects:  # Checking if objects are selected
              for obj in selected_objects:
                  texture_tag = c4d.TextureTag()  # Create a new texture tag
                  texture_tag.SetMaterial(material)  # Assigning the material to the tag
                  obj.InsertTag(texture_tag)  # Add a tag to the object
      
          # Updating the scene
          c4d.EventAdd()
      
      # Script running
      if __name__ == '__main__':
          main()
      

      Why are the selected images for the material shaders not assigned to the specified shader?


      edit (@ferdinand):
      @lednevandrey said:

      Script for S4D 2023.2

      posted in Cinema 4D SDK python 2023 windows
      L
      lednevandrey