Advertisement
Guest User

Untitled

a guest
Jul 25th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. import bpy
  2.  
  3.  
  4. obj = bpy.context.scene.objects.active # Active Object
  5.  
  6. mat_names = ["Material.001", "Material", "Material.002"] # names of the materials
  7.  
  8. mats = []
  9.  
  10. folder = "C:\test\test" # folder to save the different images in: Remember the double bar (\)!
  11.  
  12. bf_area_type = bpy.context.area.type
  13.  
  14. for m in mat_names:
  15.  
  16. mats.extend([bpy.data.materials[m]]) #adding the materials based on their names
  17.  
  18. for i, mat in enumerate(mats):
  19.  
  20. #if the object has not material slot, it adds one slot to it.
  21. if obj.data.materials:
  22.  
  23. obj.data.materials[0] = mat
  24. else:
  25. obj.data.materials.append(mat)
  26.  
  27. #render
  28. bpy.ops.render.render()
  29.  
  30. #change the area type to Image editor
  31. bpy.context.area.type = "IMAGE_EDITOR"
  32.  
  33. #Save the image
  34. bpy.ops.image.save_as(save_as_render=True, copy=True, filepath=folder+"//Render{}.png".format(i), relative_path=False, show_multiview=False, use_multiview=False)
  35.  
  36. #Reset the area type
  37. bpy.context.area.type = bf_area_type
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement