.fbd converter script

The following simple script converts Blender meshes to .fbd format. This is the native format of CGX, the pre-/post-processor for the finite element solver CCX.     CCX, or CalculiX, is a mature, robust fea application, one of the best built in the open source domain. Further info is available here: http://www.dhondt.de/ . (Since CGX has not been successfully compiled yet on windows, right now this script is potentially useful only to linux users.)    This script has been tested, but not extensively. Comments welcome.   

-l 

#!BPY



"""
Name: 'FBD file format (.fbd)...'
Blender: 234
Group: 'Export'
Tooltip: 'Export selected mesh to FBD format (*.fbd)'
"""

# --------------------------------------------------------------------------
#  FBD Export v0.2 by Gary Bollenbach 
# --------------------------------------------------------------------------
# ***** BEGIN GPL LICENSE BLOCK *****
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
# ***** END GPL LICENSE BLOCK *****
# --------------------------------------------------------------------------





#  Object(s) for export must 
#  be SELECTED.  If multiple 
#  objects are exported, they
#  must first be JOINED.




import Blender

# ==============================
# ====== Write .fbd Format ======
# ==============================

def write(filename):
	file = open(filename, "wb")
	objects = Blender.Object.GetSelected()
	objname = objects[0].name
	meshname = objects[0].data.name
	mesh = Blender.NMesh.GetRaw(meshname)
	obj = Blender.Object.Get(objname)

	# === FBD Header ===
	file.write("** .fbd output from Blender
")

	# === Vertex List ===
	for i in range(len(mesh.verts)):	
		x, y, z = mesh.verts[i].co
		file.write("pnt ")
		lnu = str(i+1)
		file.write(lnu)
		file.write(" %f %f %f
" % (x, y, z))

	# === Edges List ===
	num = 0
	for i in range(len(mesh.faces)):
		mesh.faces[i].v.reverse()	
		g = 0
		while g < (len(mesh.faces[i].v) -1):
			t3 = ((mesh.faces[i].v[g].index +1))
			t4 = ((mesh.faces[i].v[g+1].index +1))
			file.write("line ")
			num += 1
			file.write(str(num)+' ')
			file.write(`t3`+' ')
			file.write(`t4`+' ')
			file.write("4")
			file.write("
")
			g += 1
			
		t3 = ((mesh.faces[i].v[0].index +1))
		t4 = ((mesh.faces[i].v[len(mesh.faces[i].v)-1].index +1))
		file.write("line ")
		num += 1
		file.write(str(num)+' ')
		file.write(`t3`+' ')
		file.write(`t4`+' ')
		file.write("4")
		file.write("
")
	file.close()
	

def fs_callback(filename):
	write(filename +'.fbd')

Blender.Window.FileSelector(fs_callback, "Export fbd")