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.
# 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 # 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