Advertisement
salahzar

Export Selected as Collada

Jan 28th, 2023
743
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.00 KB | Software | 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:/exportcollada"
  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.wm.collada_export(filepath=fn,
  29.         selected=True,
  30.         open_sim=True,
  31.         use_texture_copies = True
  32.          )
  33.    
  34.     # Can be used for multiple formats
  35.     # bpy.ops.export_scene.x3d(filepath=fn + ".x3d", use_selection=True)
  36.  
  37.     obj.select_set(False)
  38.  
  39.     print("written:", fn)
  40.  
  41.  
  42. view_layer.objects.active = obj_active
  43.  
  44. for obj in selection:
  45.     obj.select_set(True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement