*#FILE_EXTENSION .stl
*realformat "%15.6e"
*intformat "%8i"
*# Interface GID-STL to export triangle closed mesh
*# Written by Kike III - October 2001
*if(nelem(Triangle)==0)
*MessageBox Error: Must create a mesh of triangles.
*endif
*if(nelem(Linear) || nelem(Quadrilateral) || nelem(Tetrahedra) || nelem(Hexahedra))
*WarningBox Warning: Exist Bad elements. A STL file is a collection of triangles bounding a volume.
*endif
*if(isquadratic)
*WarningBox Warning: Quadratic triangles are written as linear.
*endif
solid GiD
*set elems(triangle)
*loop elems
*set var ax=operation(NodesCoord(2,1)-NodesCoord(1,1))
*set var ay=operation(NodesCoord(2,2)-NodesCoord(1,2))
*set var az=operation(NodesCoord(2,3)-NodesCoord(1,3))
*set var bx=operation(NodesCoord(3,1)-NodesCoord(2,1))
*set var by=operation(NodesCoord(3,2)-NodesCoord(2,2))
*set var bz=operation(NodesCoord(3,3)-NodesCoord(2,3))
*set var nx=operation(ay*bz-az*by)
*set var ny=operation(az*bx-ax*bz)
*set var nz=operation(ax*by-ay*bx)
*set var modulo=operation(sqrt(nx*nx+ny*ny+nz*nz))
*set var nx=operation(nx/modulo)
*set var ny=operation(ny/modulo)
*set var nz=operation(nz/modulo)
  facet normal *nx *ny *nz
    outer loop
*for(INODO=1;INODO<=3;INODO=INODO+1)
      vertex *NodesCoord(*INODO,1) *NodesCoord(*INODO,2) *NodesCoord(*INODO,3)
*end INODO
    endloop
  endfacet
*end elems
endsolid GiD
