I can not assign new material from script to two or more objects at same time also when I create manualy new material, next I assign it to object, script get stuck and do not change material. If anybody can help with my two problems I will be very thankful.
import bpy
obs = bpy.context.active_object
mat = bpy.data.materials.get("test")
if mat is None:
mat = bpy.data.materials.new(name="test")
mat.use_nodes = True
bsdf = mat.node_tree.nodes["Principled BSDF"]
texImage = mat.node_tree.nodes.new('ShaderNodeTexImage')
texImage.image = bpy.data.images.load("D:\\test.png")
mat.node_tree.links.new(bsdf.inputs['Base Color'], texImage.outputs['Color'])
if obs.data.materials:
obs.data.materials[0] = mat
else:
obs.data.materials.append(mat)