#!BPY ''' Name: 'Nigels Mesh Export Script' Blender: 244 Group: 'Export' Tooltip: 'Export scene mesh data as a Lua file.' ''' from Blender import Window, sys, Draw import bpy import math def my_object_util(sce): # Remove these when writing your own tool print 'Blend object count', len(bpy.data.objects) print 'Scene object count', len(sce.objects) # context means its selected, in the view layer and not hidden. print 'Scene context count', len(sce.objects.context) # Store the current context context = list(sce.objects.context) f = open( '/home/nigel/Blender/meshes.lua', 'w' ) f.write( 'meshes = {}\n' ) for mesh in [ x for x in context if x.type == 'Mesh' ]: f.write( 'mesh = {}\n' ) f.write( 'mesh.name = \'' + mesh.name + '\'\n' ) f.write( 'mesh.filename = \'' + mesh.getData( name_only=True ) + '.mesh\'\n' ) f.write( 'mesh.loc = { ' + str(mesh.LocX) + ', ' + str(mesh.LocZ) + ', ' + str(-mesh.LocY) + ' }\n' ) q = mesh.getMatrix().toQuat() f.write( 'mesh.rot = { ' + str(q.w) + ', ' + str(q.x) + ', ' + str(q.z) + ', ' + str(-q.y) + ' }\n' ) f.write( 'mesh.scale = { ' + str(mesh.SizeX) + ', ' + str(mesh.SizeZ) + ', ' + str(mesh.SizeY) + ' }\n' ) f.write( 'meshes[mesh.name] = mesh\n' ) print mesh.getMatrix().translationPart(), q f.close() def main(): # Gets the current scene, there can be many scenes in 1 blend file. sce = bpy.data.scenes.active Window.WaitCursor(1) t = sys.time() # Run the object editing function my_object_util(sce) # Timing the script is a good way to be aware on any speed hits when scripting print 'Script finished in %.2f seconds' % (sys.time()-t) Window.WaitCursor(0) Draw.PupMenu( "Export%t | Finished" ) # This lets you can import the script without running it if __name__ == '__main__': main()