Unable to convert an STEP file into an STL file

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

Hi,

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

BRepMesh_IncrementalMesh Mesh( Original_Solid,0.0001);

Mesh.Perform();

Best regards,

Patrik

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

Hi,

missing libs for Linker...

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

Best regards,

Patrik

Vishesh Chanana's picture

Thanks