Multi objects selection with edit mode

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 ="test")

if mat is None:
    mat ="test")
    mat.use_nodes = True
    bsdf = mat.node_tree.nodes["Principled BSDF"]
    texImage ='ShaderNodeTexImage')
    texImage.image ="D:\\test.png")['Base Color'], texImage.outputs['Color'])
if[0] = mat


I am not very good with the Python and materials, but my first guess is that you are not changing modes when you should be, OR you are creating your two objects in Object mode, then attempting to add materials to them simultaneously, when you should be creating both objects in edit mode, then adding the materials to it. When you create two objects in edit mode, they are two separate objects. When you create two items in Edit mode, they are one and the same object. HOWEVER . . . . my bet is that if you are trying to add the same materials to, for example, two cubes, you should be making ONE cube, then instead of making a duplicate object of it [SHIFT D], making a duplicate instance of it [ALT D]. When you do that, however you add materials to the first one, all the others you create INSTANCES of, will have the exact same texture.

1 Like

I assume by ‘stuck’ you mean you’re getting an error? if so, tell us what the error says.