3 # ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5 # + This file is part of enGrid. +
7 # + Copyright 2008,2009 Oliver Gloth +
9 # + enGrid is free software: you can redistribute it and/or modify +
10 # + it under the terms of the GNU General Public License as published by +
11 # + the Free Software Foundation, either version 3 of the License, or +
12 # + (at your option) any later version. +
14 # + enGrid is distributed in the hope that it will be useful, +
15 # + but WITHOUT ANY WARRANTY; without even the implied warranty of +
16 # + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +
17 # + GNU General Public License for more details. +
19 # + You should have received a copy of the GNU General Public License +
20 # + along with enGrid. If not, see <http:#www.gnu.org/licenses/>. +
22 # ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
25 # Export script for Blender.
31 Tooltip: 'Export to Gmsh 2 ASCII format'
37 def writeGmsh2(filename
):
38 if not filename
.lower().endswith('.msh'):
40 out
= file(filename
, "w")
41 scn
= bpy
.data
.scenes
.active
42 object = scn
.objects
.active
44 Blender
.Draw
.PupMenu('Error%t|Select 1 active object')
46 if object.type != 'Mesh':
47 Blender
.Draw
.PupMenu('Error%t|Select a mesh object')
50 mesh
= object.getData(0,1)
54 out
.write('$MeshFormat\n2 0 8\n$EndMeshFormat\n')
55 out
.write('$Nodes\n%d\n' % len(nodes
))
60 out
.write("%e " % n
.co
[0])
61 out
.write("%e " % n
.co
[1])
62 out
.write("%e\n" % n
.co
[2])
65 out
.write('$EndNodes\n')
66 out
.write('$Elements\n%d\n' % len(faces
))
72 Blender
.Draw
.PupMenu('Error%t|Only triangles and quads allowed')
78 out
.write('1 %d' % (f
.mat
+ 1))
80 out
.write(' %d' % (v
.index
+ 1))
84 out
.write('$EndElements\n')
86 Blender
.Window
.FileSelector(writeGmsh2
, "Export", Blender
.sys
.makename(ext
='.msh'))