[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [38451] trunk/blender/release/scripts/ templates/batch_export.py: template for patch exporting objects in a scene.

Campbell Barton ideasman42 at gmail.com
Sun Jul 17 15:29:51 CEST 2011


Revision: 38451
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=38451
Author:   campbellbarton
Date:     2011-07-17 13:29:50 +0000 (Sun, 17 Jul 2011)
Log Message:
-----------
template for patch exporting objects in a scene.

Added Paths:
-----------
    trunk/blender/release/scripts/templates/batch_export.py

Added: trunk/blender/release/scripts/templates/batch_export.py
===================================================================
--- trunk/blender/release/scripts/templates/batch_export.py	                        (rev 0)
+++ trunk/blender/release/scripts/templates/batch_export.py	2011-07-17 13:29:50 UTC (rev 38451)
@@ -0,0 +1,33 @@
+# exports each selected object into its own file
+
+import bpy
+import os
+
+# export to blend file location
+basedir = os.path.dirname(bpy.data.filepath)
+
+if not basedir:
+    raise Exception("Blend file is not saved")
+
+selection = bpy.context.selected_objects
+
+bpy.ops.object.select_all(action='DESELECT')
+
+for obj in selection:
+
+    obj.select = True
+
+    name = bpy.path.clean_name(obj.name)
+    fn = os.path.join(basedir, name)
+
+    bpy.ops.export_scene.fbx(filepath=fn + ".fbx", use_selection=True)
+
+    ## Can be used for multiple formats
+    # bpy.ops.export_scene.x3d(filepath=fn + ".x3d", use_selection=True)
+
+    obj.select = False
+    
+    print("written:", fn)
+
+for obj in selection:
+    obj.select = True




More information about the Bf-blender-cvs mailing list