Importing STL files...


at the moment I'm trying to import STL files via RWStl::ReadFile().

But I've got some problems (see my code fragment below).

1) if I import ASCII files I get 0 for NbTriangles() and NbVertices()

2) my program always crashes when building some edges

Any help or hints would be nice....

Regards, Patrik Müller

OSD_Path aFile(aFileName);

Handle(StlMesh_Mesh) aSTLMesh = RWStl::ReadFile(aFile);

int NumberDomains = aSTLMesh->NbDomains();

int NumberTriangles = aSTLMesh->NbTriangles();

int NumberVertices = aSTLMesh->NbVertices();

int iND,iNT;

TColgp_SequenceOfXYZ aSeqOfXYZ;

StlMesh_SequenceOfMeshTriangle aSeqOfTriangle;

Standard_Integer v1,v2,v3;

gp_Pnt p1, p2, p3;

TopoDS_Edge e1, e2, e3;

TopoDS_Vertex Vertex1, Vertex2, Vertex3;

TopoDS_Shell AktShell;

TopoDS_Face AktFace;

TopoDS_Wire AktWire;

BRep_Builder B;


for (iND = 1; iND




for (iNT = 1; iNT NbTriangles(iND); iNT++)


const Handle(StlMesh_MeshTriangle) aTrian = aSeqOfTriangle.Value(iNT);





Vertex1 = BRepBuilderAPI_MakeVertex(p1);

Vertex2 = BRepBuilderAPI_MakeVertex(p2);

Vertex3 = BRepBuilderAPI_MakeVertex(p3);

e1 = BRepBuilderAPI_MakeEdge(Vertex1,Vertex2);

e2 = BRepBuilderAPI_MakeEdge(Vertex2,Vertex3);

e3 = BRepBuilderAPI_MakeEdge(Vertex1,Vertex3);

AktWire = BRepBuilderAPI_MakeWire( e1, e2, e3);

AktFace = BRepBuilderAPI_MakeFace( AktWire);




aShape = BRepBuilderAPI_MakeSolid(AktShell);

return aShape;

Jean Michel Boulcourt's picture

I don't know why it does crash when you build the edges, but after looking in the methods of RWStl, I can say that there are bugs inside. These methods have to be completely reviewed to conform to STL specifications and to be portable on all platforms (which is not the case as for now).

Patrik's picture


thanks for the answer. Reading binary files now works.

Regards, Patirk Müller