Adding material properties in blender using python?

I have created a cube in blender using Python API. The code I used is

import bpy

new_mesh.from_pydata(vertices, edges, faces)

new_object ="new_object", new_mesh)

Now, I want to convert two faces → Face 1 =(0,1,2,3) and Face 2 = (4,5,6,7) of the cube into a glass material. This is what I did for adding a new glass material.

# Create a new material
face_to_convert_to_glass = [(0,1,2,3),(4,5,6,7)]
material_glass ='Green')
material_glass.use_nodes = True
p_BSDF = material_glass.node_tree.nodes["Principled BSDF"]
p_BSDF.inputs[0].default_value = (0, 1, 0, 1)
p_BSDF.inputs[7].default_value = 0
p_BSDF.inputs[15].default_value = 1

It may be a simple thing but being a novice I am not able to link the glass material with the new_object I created. How do I achieve this using Python ?

Moved to : Coding – Python Support

your code is assuming that the object you created is selected, which it won’t be- assuming there’s not something else going on in your code that you have omitted. append the material directly to the mesh you created instead: