Advertisement
salahzar

blender_export_images.py

Feb 10th, 2023
786
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.09 KB | None | 0 0
  1. import bpy
  2.  
  3. # Get the objects
  4. objects = bpy.context.selected_objects
  5.  
  6. # Set the base path
  7. base_path = "C:/exportpakkio"
  8.  
  9. # Iterate over objects
  10. for obj in objects:
  11.     # Check if object has an active material
  12.     if obj.active_material:
  13.         # Get the material
  14.         mat = obj.active_material
  15.         # Check if the material has a node tree
  16.         if mat.node_tree:
  17.             # Iterate over the nodes in the node tree
  18.             for node in mat.node_tree.nodes:
  19.                 # Check if the node is a texture node and if its type is "TEX_IMAGE"
  20.                 if node.type == 'TEX_IMAGE':
  21.                     # Get the image
  22.                     img = node.image
  23.                     # Check if the image is not None
  24.                     if img:
  25.                         # Set the new path
  26.                         new_path = base_path + "/" + img.name
  27.                         # Save the image
  28.                         img.filepath_raw = new_path
  29.                         img.file_format = 'PNG'
  30.                         print("saving ",new_path)
  31.                         img.save()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement