Cut a shape after importing a stl file

Hello everyone,

I use opencascade for my c# project and because of that I have a OCCTProxy like occt sample project.

I want to open holes on stl file. Firstly I import a stl file and create a cylinder which will be a hole on stl file. While cutting the my stl file, I got an error about System.AccessViolationException.

Do you know why I'm getting this error?

Error is: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

        TCollection_AsciiString theFileName = Utilities::ToAsciiString(inp);
	auto aTris = RWStl::ReadFile(theFileName.ToCString(), 0.1);
	auto face = TopoDS_Face();
	auto aBuilder = BRep_Builder();
	aBuilder.MakeFace(face, aTris);
	Handle(AIS_Shape) shape = new AIS_Shape(face);

	BRepPrimAPI_MakeCylinder holeMaker(position, holeRadius, 100);
	TopoDS_Shape holeTopoDsShape = holeMaker.Shape();

	BRepAlgoAPI_Cut cutMaker(shape->Shape(), holeTopoDsShape);   //error occurs
	TopoDS_Shape result = cutMaker.Shape();

gkv311 n's picture

STL format provides only triangulation (tessellation), not a boundary representation (B-Rep) expected by OCCT Boolean operations. You may try reading STL into inefficient B-Rep definition (each triangle defining individual TopoDS_Face) using legacy StlAPI_Reader, but result might be extremely poor performance.

Batuhan Cengiz's picture

Yes, I have already tried that and it works but stl looks like in bad quality. Maybe there is an another solution to get better quality, just I would wait and see the other replies. :) Thanks a lot anyway.

Batuhan Cengiz's picture

Yes, I have already tried that and it works but stl looks like in bad quality. Maybe there is an another solution to get better quality, just I would wait and see the other replies. :) Thanks a lot anyway.