Export Solid to STEP file not working


I'm trying to export a solid (simple box) into a STEP file. The problem is, that the exported geometry is not a solid. You can see the problem in the attached Screenshot (STEP_BlockReference.png).

Below is an excerpt of the code which exports the solid into the STEP file.

TopoDS_Solid CreateTestSolid();

	TopoDS_Solid solid = CreateTestSolid();

	shared_ptr<string> step_target_file(new string(OUTPUT_BASE_PATH + "test.stp"));
	STEPControl_Writer step_writer = STEPControl_Writer();
	IFSelect_ReturnStatus result = step_writer.Transfer(solid, STEPControl_ManifoldSolidBrep, Standard_True);
	BOOST_TEST(result == IFSelect_RetDone);

	result = step_writer.Write(step_target_file->c_str());
	BOOST_TEST(result == IFSelect_RetDone);

TopoDS_Solid CreateTestSolid() {
	gp_Pnt a = gp_Pnt(1, 1, 1);
	gp_Pnt b = gp_Pnt(8, 1, 1);
	gp_Pnt c = gp_Pnt(8, 1, 4);
	gp_Pnt d = gp_Pnt(1, 1, 4);
	gp_Pnt e = gp_Pnt(1, 4, 1);
	gp_Pnt f = gp_Pnt(1, 4, 4);
	gp_Pnt g = gp_Pnt(8, 4, 4);
	gp_Pnt h = gp_Pnt(8, 4, 1);

	TopoDS_Edge a_b = BRepBuilderAPI_MakeEdge(a, b).Edge();
	TopoDS_Edge b_c = BRepBuilderAPI_MakeEdge(b, c).Edge();
	TopoDS_Edge c_d = BRepBuilderAPI_MakeEdge(c, d).Edge();
	TopoDS_Edge d_a = BRepBuilderAPI_MakeEdge(d, a).Edge();
	BRepBuilderAPI_MakeFace A = BRepBuilderAPI_MakeFace(BRepBuilderAPI_MakeWire(a_b, b_c, c_d, d_a).Wire());

	TopoDS_Edge b_h = BRepBuilderAPI_MakeEdge(b, h).Edge();
	TopoDS_Edge h_g = BRepBuilderAPI_MakeEdge(h, g).Edge();
	TopoDS_Edge g_c = BRepBuilderAPI_MakeEdge(g, c).Edge();
	TopoDS_Edge c_b = BRepBuilderAPI_MakeEdge(c, b).Edge();
	BRepBuilderAPI_MakeFace B = BRepBuilderAPI_MakeFace(BRepBuilderAPI_MakeWire(b_h, h_g, g_c, c_b).Wire());

	TopoDS_Edge h_e = BRepBuilderAPI_MakeEdge(h, e).Edge();
	TopoDS_Edge e_f = BRepBuilderAPI_MakeEdge(e, f).Edge();
	TopoDS_Edge f_g = BRepBuilderAPI_MakeEdge(f, g).Edge();
	TopoDS_Edge g_h = BRepBuilderAPI_MakeEdge(g, h).Edge();
	BRepBuilderAPI_MakeFace C = BRepBuilderAPI_MakeFace(BRepBuilderAPI_MakeWire(h_e, e_f, f_g, g_h).Wire());

	TopoDS_Edge e_a = BRepBuilderAPI_MakeEdge(e, a).Edge();
	TopoDS_Edge a_d = BRepBuilderAPI_MakeEdge(a, d).Edge();
	TopoDS_Edge d_f = BRepBuilderAPI_MakeEdge(d, f).Edge();
	TopoDS_Edge f_e = BRepBuilderAPI_MakeEdge(f, e).Edge();
	BRepBuilderAPI_MakeFace D = BRepBuilderAPI_MakeFace(BRepBuilderAPI_MakeWire(e_a, a_d, d_f, f_e).Wire());

	TopoDS_Edge e_h = BRepBuilderAPI_MakeEdge(e, h).Edge();
	TopoDS_Edge h_b = BRepBuilderAPI_MakeEdge(h, b).Edge();
	TopoDS_Edge b_a = BRepBuilderAPI_MakeEdge(b, a).Edge();
	TopoDS_Edge a_e = BRepBuilderAPI_MakeEdge(a, e).Edge();
	BRepBuilderAPI_MakeFace E = BRepBuilderAPI_MakeFace(BRepBuilderAPI_MakeWire(e_h, h_b, b_a, a_e).Wire());

	TopoDS_Edge d_c = BRepBuilderAPI_MakeEdge(d, c).Edge();
	TopoDS_Edge c_g = BRepBuilderAPI_MakeEdge(c, g).Edge();
	TopoDS_Edge g_f = BRepBuilderAPI_MakeEdge(g, f).Edge();
	TopoDS_Edge f_d = BRepBuilderAPI_MakeEdge(f, d).Edge();
	BRepBuilderAPI_MakeFace F = BRepBuilderAPI_MakeFace(BRepBuilderAPI_MakeWire(d_c, c_g, g_f, f_d).Wire());

	BRepBuilderAPI_Sewing sewing = BRepBuilderAPI_Sewing();

	const TopoDS_Shape& shape = sewing.SewedShape();
	BOOST_TEST(shape.ShapeType() == TopAbs_SHELL);

	const TopoDS_Shell& shell = (const TopoDS_Shell&)shape;
	TopoDS_Solid solid = BRepBuilderAPI_MakeSolid(shell).Solid();
	return solid;

If i export the solid into an IGES file it works correctly (See attached Screenshot "IGES_Solid.png").

The code below exports the solid into the IGES file:

	TopoDS_Solid solid = CreateTestSolid();

	shared_ptr<string> iges_target_file(new string(OUTPUT_BASE_PATH + "test.iges"));
	IGESControl_Writer iges_writer("mm", 1);

It would be great if someone can tell me what I'm doing wrong in the example above.


Thank you.

Kirill Gavrilov's picture

STEP file produced by your code sample is read back as Solid by OCCT itself (current development master).
How do you consider it is not a Solid?

Christoph Stampfel's picture


Thank you for your answer.

I was confused, that AutoCAD visualizes the solids as block reference. You are right, the solids are exported correctly.

Thank you.