Jump to content

lednevandrey

Limited Member
  • Posts

    1
  • Joined

  • Last visited

lednevandrey's Achievements

Newbie

Newbie (1/14)

  • Conversation Starter
  • One Month Later
  • Week One Done

Recent Badges

0

Reputation

  1. 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 # Присваиваем путь к файлу 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?
×
×
  • Create New...