For all issues regarding the Forums use, please, refer to the Forum Rules.

Our Solutions

Need professional assistance?
Consider our:

Support Offerings


Need to speed up your development?
Have a look at our:

Samples & Tools


Need some functionality extending standard OCCT capabilities?
Check out our:

Adv. Components

Related pages

Unable to convert an STEP file into an STL file

Vishesh Chanana's picture

I am trying to convert a given input STEP file into an STL file format. I am using the following code to do the conversion process:

// STEP Read Methods
#include "STEPControl_Reader.hxx"
#include <TopoDS_Shape.hxx>
// STL Read & Write Methods
#include <StlAPI_Writer.hxx>

int step2stl(char *in, char *out) {
  // Read from STEP
  STEPControl_Reader reader;
  IFSelect_ReturnStatus stat = reader.ReadFile(in);
  Standard_Integer NbRoots = reader.NbRootsForTransfer();
  Standard_Integer NbTrans = reader.TransferRoots();
  TopoDS_Shape Original_Solid = reader.OneShape();
  // Write to STL
  StlAPI_Writer stlWriter = StlAPI_Writer();
  // stlWriter.SetCoefficient(0.0001);
  stlWriter.ASCIIMode() = Standard_False;
  stlWriter.Write( Original_Solid, out);
  //cout << "last check " << endl;
  return 1;

Standard_Integer main (int argc, char *argv[]) {
  cout << argv[2] << endl;
  step2stl(argv[1], argv[2]);
  return 0;

When I run this code, I receive an error at the line:

 stlWriter.Write( Original_Solid, out);

The error I receive is in the NCollection_Array2.hxx file. It gives an Exception unhandled error. The exception being : Standard_RangeError. 

I am using openCascade 7.2.0 and Visual studio 2017. 

Please help.

Patrik Mueller's picture


you have to create the triangulation before writing. Something like:

BRepMesh_IncrementalMesh Mesh( Original_Solid,0.0001);


Best regards,


Vishesh Chanana's picture

Thanks Patrik.

I added this code in my file but my VS gives me 'Unresolved external symbol'.

Patrik Mueller's picture


missing libs for Linker...

Please check them (e.g. TKMesh.lib), or post the whole error list.

Best regards,


Vishesh Chanana's picture


Contact us

Attention: DO NOT use this form for all kind of request for the removal of your personal data. Please follow this link for such cases.