Advertisement
salahzar

Export all selected objects as separate glb

Jan 26th, 2023 (edited)
1,119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.12 KB | Source Code | 0 0
  1. # exports each selected object into its own file
  2.  
  3. import bpy
  4. import os
  5.  
  6. # export to blend file location
  7. # USE DOUBLE \\ as separator instead of single or EVEN BETTER THE /
  8. basedir = "c:\\exportpakkio"
  9.  
  10.  
  11.  
  12. view_layer = bpy.context.view_layer
  13.  
  14. obj_active = view_layer.objects.active
  15. selection = bpy.context.selected_objects
  16.  
  17. bpy.ops.object.select_all(action='DESELECT')
  18.  
  19. for obj in selection:
  20.  
  21.     obj.select_set(True)
  22.  
  23.     # some exporters only use the active object
  24.     view_layer.objects.active = obj
  25.  
  26.     name = bpy.path.clean_name(obj.name)
  27.     fn = os.path.join(basedir, name)
  28.     bpy.ops.export_scene.gltf(
  29.             filepath=fn,
  30.             export_format="GLB",
  31.             #export_selected=True (I got a warning here)
  32.             use_selection=True
  33.         )
  34.  
  35.     # bpy.ops.export_scene.obj(filepath=fn + ".obj", use_selection=True)
  36.  
  37.     # Can be used for multiple formats
  38.     # bpy.ops.export_scene.x3d(filepath=fn + ".x3d", use_selection=True)
  39.  
  40.     obj.select_set(False)
  41.  
  42.     print("written:", fn)
  43.  
  44.  
  45. view_layer.objects.active = obj_active
  46.  
  47. for obj in selection:
  48.     obj.select_set(True)
Tags: blender
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement