
Tue, 02/20/2018 - 10:00
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.
Tue, 02/20/2018 - 20:24
Hi,
you have to create the triangulation before writing. Something like:
BRepMesh_IncrementalMesh Mesh( Original_Solid,0.0001);
Mesh.Perform();
Best regards,
Patrik
Thu, 02/22/2018 - 04:11
Thanks Patrik.
I added this code in my file but my VS gives me 'Unresolved external symbol'.
Thu, 02/22/2018 - 10:02
Hi,
missing libs for Linker...
Please check them (e.g. TKMesh.lib), or post the whole error list.
Best regards,
Patrik
Sun, 03/04/2018 - 09:24
Thanks