For some reason the function stated in the title is not running when I tell it to run. I am trying to make it apply some texture baked images onto my object using python scripting but it simply isnt running without giving me an error. The error comes from farther down the code when I am trying to connect certain nodes that have been added however as the function is not running the nodes dont exist and it gives me an attribute error stating 'NoneType' object has no attribute 'outputs'. If anybody can help it would be much appreciated. Many thanks!
win = bpy.context.window
scr = win.screen
areas = [area for area in scr.areas if area.type == 'NODE_EDITOR']
regions = [region for region in areas[0].regions if region.type == 'WINDOW']
#global directory
#global imgName
directory = 'C:\\stable internship\\Programming'
filepath = directory + '\\'
objectName = 'myod'
filesToTexture = [{"name": objectName + "_normal.png", "name": objectName + "_normal.png"}, {"name": objectName + "_specular.png", "name": objectName + "_specular.png"}, {"name": objectName + "_roughness.png", "name": objectName + "_roughness.png"}, {"name": objectName + "_color.png", "name": objectName + "_color.png"}]
print(filesToTexture)
print(filepath)
print(objectName)
with bpy.context.temp_override(window=win,area=areas[0], region=regions[0],screen=scr):
print("IS THIS WORKING")
bpy.ops.node.nw_add_textures_for_principled(filepath=filepath, directory=filepath,files=filesToTexture, relative_path=True)
material = bpy.context.active_object.active_material
base_color_texture_node = None
for node in material.node_tree.nodes:
if node.type == 'TEX_IMAGE' and node.label.startswith('Base Color'):
base_color_texture_node = node
break
material.node_tree.links.new(base_color_texture_node.outputs['Alpha'], principled_bsdf_node.inputs['Alpha'])
Earlier in my code I set up everything already for the function including having the shader editor open and use nodes on so that the function can add the textures. However, after running my program it stays exactly the same and it gives me an attribute error.


bpy.ops.node.nw_add_textures_for_principled. it works in this case. – Harry McKenzie Jul 24 '23 at 16:01