To the answer
It won't work if the code in line 17 -
"C:\\Users\\Desktop\\UVLayouts\\" doesn't exist on your computer as a Directory (or blender doesn't allowed to modify in that directory). You could change the path of it or create a directory on that location with the same naming.
The mechanism of how
bpy.ops.uv.export_layout work on opening a file make this error. It use
open, a python built-in function to deal with file.
It requires the parent folder of the filepath exist, as discussion in here.
You should check out the discussion carefully since that is a basic knowledge of python. And for my advise, you could always search the error in google, the answer for your problem is there most of the time. You need to search it with a good key words, in this case
FileNotFoundError: [Errno 2] No such file or directory will do the work.
As Martin Z point out, we should fix this script a little bit to make it more robust (for those not familiar with programming):
# You should change this varibale in "here" to match your own directory path
# use '/' or '\\' for hirecacy
target_dir = "C:/some/directory/"
selObj = 
for obj in bpy.context.selected_objects:
while i < len(selObj):
bpy.context.scene.objects.active = bpy.context.scene.objects[selObj[i]]
bpy.ops.uv.smart_project(angle_limit=66.0, island_margin=0.0, user_area_weight=0.0)
full_file_name=target_dir + bpy.data.objects[selObj[i]].name
# This code detected whether target_dir exist, if not, then create it
dirname = os.path.dirname(full_file_name)
if not os.path.exists(dirname):
bpy.ops.uv.export_layout(filepath=full_file_name, mode='PNG', opacity=0)
Run this script in blender 2.7x text editor, and change
target_dir = "C:/some/directory/" to your desired location. And still, strongly recommend to read the code carefully.