Export a stl with solids (layers)

Moderator: GiD Team

AndreaPhD
Posts: 3
Joined: Tue Dec 10, 2019 5:28 pm

Export a stl with solids (layers)

Postby AndreaPhD » Tue Dec 10, 2019 5:42 pm

Hi all,
I usually need to export a stl file of my geometry, composed by surfaces. The geometry is subdivided in several layers, and also the stl faces are assigned at the corresponding layers. If I export the stl file of the whole geometry, the stl file I get has just one "solid", named GiD, without the subdivision in more "solids". Is it possible to export stl file mantaining the layers structure?
Thanks in advance,
regards
User avatar
escolano
Posts: 1610
Joined: Thu Sep 18, 2014 3:31 pm

Re: Export a stl with solids (layers)

Postby escolano » Thu Dec 12, 2019 12:49 pm

From the point of view of GiD it is trivial to write its layer information,
but unfortunately STL is a very simple format, and doesn't allow to store layer information.
It allows only triangles defined by its vertices (and maybe vertex normals), and at least in theory the triangles must enclose a single volume.
https://en.wikipedia.org/wiki/STL_(file_format)
AndreaPhD
Posts: 3
Joined: Tue Dec 10, 2019 5:28 pm

Re: Export a stl with solids (layers)

Postby AndreaPhD » Wed Jan 08, 2020 2:58 pm

Thank for the replay,
I try to be more specific: I have a layers structured geometry, then I do triangulated surface mesh, each layer contains the corresponding meshed surface. So far everifhing is fine. Then I export all the surface at once as a stl file, by default, in the header of the file, there is the "solid GiD" and at the end "endsolid GiD". An example can be much clearer:
If I have 2 surface in layer1 and layer2, I can mesh them and export as STL. What I get is an stl with only one solid:
solid GiD
... list of triangles...
endolid Gid
while I would like to get is
solid layer1
..list of triangles
endsolid layer1
solid layer2
..list of triangles
endsolid layer2
Is that possible somehow?
I'm doing this manually and it is quite cumbersome for complex geometries,
thanks again
User avatar
escolano
Posts: 1610
Joined: Thu Sep 18, 2014 3:31 pm

Re: Export a stl with solids (layers)

Postby escolano » Wed Jan 08, 2020 3:58 pm

Write what you want is trivial in GiD, but at least strictly in theory it won't be a valid STL format!!
Although I think that some programs are doing it (write more than one solid block)
and GiD also is able to read STL with multiple solid blocks (without assume the block name as a layername)

To do it simply copy this template .bas code in a file named for example STLByLayers.bas inside the folder <GiD>/templates

Then to use simply go to menu Files->Export->Using template .bas (only mesh)->STLByLayers

Code: Select all

*#FILE_EXTENSION .stl
*realformat "%15.9g"
*intformat "%8i"
*# Interface GID-STL to export triangle mesh by layers (writing multipe solid/endsolid blocks)
*if(nelem(Triangle)==0)
*MessageBox Error: Must create a mesh of triangles.
*endif
*if(nelem(Linear) || nelem(Quadrilateral) || nelem(Tetrahedra) || nelem(Hexahedra) || nelem(Prism) || nelem(Sphere) || nelem(Circle))
*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
*loop layers
*set layer *layername *elems
*if(LayerNumEntities)
solid *layername
*loop elems *OnlyInLayer
  facet normal *ElemsNormal(1) *ElemsNormal(2) *ElemsNormal(3) 
    outer loop
      vertex *NodesCoord(1,1) *NodesCoord(1,2) *NodesCoord(1,3)
      vertex *NodesCoord(2,1) *NodesCoord(2,2) *NodesCoord(2,3)
      vertex *NodesCoord(3,1) *NodesCoord(3,2) *NodesCoord(3,3)
    endloop
  endfacet
*end elems
endsolid *layername
*endif
*end layers
AndreaPhD
Posts: 3
Joined: Tue Dec 10, 2019 5:28 pm

Re: Export a stl with solids (layers)

Postby AndreaPhD » Fri Jan 17, 2020 2:19 pm

Dear Escolano and GiD Staff,
thank you!
It works perfectly,
have a nice day

Return to “Import/Export”

Who is online

Users browsing this forum: No registered users and 0 guests