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

Write to STL

Dominik Mokris's picture
Forums: 

Hello everyone,

a very basic question. I am learning to import a STEP file and export it to STL. I modified Laszlo's code from https://github.com/lvk88/OccTutorial/blob/master/OtherExamples/runners/convertStepToStl.cpp
as follows:

int main(int argc, char *argv[])
{
    STEPControl_Reader reader;
    reader.ReadFile(argv[1]);
    reader.TransferRoots();
    TopoDS_Shape stepShape = reader.OneShape();
    StlAPI_Writer STLwriter;
    STLwriter.Write(stepShape,argv[2]);
    return 0;
}

However, when I run

./main valve203.STEP out.stl

(the valve file was posted here some time ago and is also attached), the result is more or less empty; it says only:

solid shape, STL ascii file, created with Open CASCADE Technology
endsolid shape

What's wrong? Certainly I am missing something very basic.

Attachments: 
qa qa's picture

Hi,

The step file itself does not contain any mesh. You should create it before saving manually. It can be done using BRepMesh_IncrementalMesh functionality.

qa qa

Dominik Mokris's picture

I see, apparently I misunderstood the phrase "Converts a given shape to STL format" from the documentation, because I thought that this included meshing.

Anyway, using the BRepMesh_IncrementalMesh turned out to be surprisingly simple.

Thank you very much. Without your help I would be unlikely to understand what was wrong in a finite time!

Dominik

Dominik Mokris's picture

One more issue.

Say I want to import a STEP file such as as1-oc-214.stp (which one can obtain e.g. at https://www.cax-if.de/library/as1-oc-214.zip ).
When I open it in FreeCAD, it consists of 18 parts.
However, when I import it with OpenCascade, it is just one big body.
What am I doing wrong?
I've already tried various combinations of "read.step.shape.repr", "read.step.assembly.level", etc., but without much success.

My code:

STEPControl_Reader reader;
reader.ReadFile(filename);
Handle(TColStd_HSequenceOfTransient) list = reader.GiveList();
std::cout << list->Length(); // Prints "1", I would like something like "18".

Thank you very much!
 

Dominik Mokris's picture

Solved, apparently I had to use STEPCAFControl_Reader and more involved code, similarly to an older thread https://www.opencascade.com/content/import-step-export-mesh-wrong-placem... .