I have dozens of objects (all curves, not meshes) imported with their own material and Base Color defined. I need to use nodes, but when I do, the Base Color changes to white, ignoring the color of the non-node material.

How do I keep the Base Color of a material WITHOUT node in the Base color when converting to a material WITH node?


enter image description here


enter image description here


1 Answer 1


AI Icon Warning, Potential AI generated content⚠️

This post is suspected to have been generated with the help of an artificial intelligence, chat bot, or other language model tools without proper attribution.

There is reason to believe this post was not written by a human due to its structure, and grammatical construction, and has been marked by our community.
Current AI chat bots are a language models, that means they are like a parrot, they can mimic human language well, but they are built to write seemingly logical, seemingly factual grammatically valid text, rather than actually be correct, like a human would.
The veracity of the following content cannot be ascertained. See the Concerns regarding AI generated content.

I managed to find a solution. I asked ChatGPT to create the script.

import bpy

# Iterate through selected objects
selected_objects = bpy.context.selected_objects
for obj in selected_objects:
    if obj.type in ['CURVE', 'MESH']:
        # Check if the object has a material
        if len(obj.data.materials) > 0:
            material = obj.data.materials[0]  # Assuming only one material is assigned
            # Create a new material with nodes
            material.use_nodes = True
            material.node_tree.nodes.clear()  # Clear existing nodes
            # Create the principled BSDF node
            principled_node = material.node_tree.nodes.new('ShaderNodeBsdfPrincipled')
            principled_node.location = (0, 0)  # Set the location of the node
            # Retrieve the base color from the original material
            base_color = material.diffuse_color[:3]  # Extract RGB components
            # Set the base color in the principled BSDF node
            principled_node.inputs['Base Color'].default_value = (*base_color, 1)
            # Create the output node
            output_node = material.node_tree.nodes.new('ShaderNodeOutputMaterial')
            output_node.location = (400, 0)  # Set the location of the node
            # Connect the principled BSDF node to the output node
            material.node_tree.links.new(principled_node.outputs['BSDF'], output_node.inputs['Surface'])
  • $\begingroup$ Thank you for sharing the solution (and for properly marking it as GPT this time), however it would be even better if you analyzed the code and modified it to better fit your question: 1) you don't really want to delete the default Principled BSDF node (and replace it with usually inferior Diffuse node); 2) no point to remove the output just to add it back; 3) the print statement doesn't seem very useful; 4) it could be all wrapped in a loop for obj in bpy.data.objects: or for obj in bpy.context.selected_objects: $\endgroup$ Commented Jul 19, 2023 at 15:05
  • $\begingroup$ @MarkusvonBroady Thank you for your assistance. Since the script was created by an AI and I have no knowledge of Python (0%), there is indeed much room for improvement. I have taken your points into consideration and updated the script to use the Principled BSDF. I believe it is slightly better now. Thank you very much for the feedback. $\endgroup$
    – rdllngr
    Commented Jul 19, 2023 at 18:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .