OCCUtils full example: Make box and export it to STEP
This example creates a box using OCCUtils’s Primitive::MakeBox (or see How to create a Box TopoDS_Solid in OpenCASCADE ) and exports it to a STEP file.
First, initialize the git repository:
occutils_make_box.sh
git initNow we can add OCCUtilsusing the submodule method:
occutils_submodule.sh
git submodule init
git submodule add https://github.com/ulikoehler/OCCUtils.git OCCUtilsNow we can add the CMake config:
CMakeLists.txt
project(mkbox)
cmake_minimum_required(VERSION 3.3)
add_subdirectory(OCCUtils)
add_executable( mkbox main.cpp )
add_dependencies( mkbox occutils )
target_include_directories( mkbox PUBLIC /usr/include/opencascade/ )
target_link_libraries( mkbox
occutils
TKernel
TKMath
TKFillet
TKBinXCAF
TKBRep
TKBO
TKFeat
TKG2d
TKXDESTEP
TKG3d
TKGeomAlgo
TKGeomBase
TKHLR
TKIGES
TKPrim
TKShHealing
TKSTEP
TKSTEP209
TKSTEPAttr
TKSTEPBase
TKXSBase
TKSTL
TKTopAlgo
TKV3d
TKOffset
TKService
)And the main source code:
mkbox.cpp
#include <occutils/Primitive.hxx>
#include <occutils/STEPExport.hxx>
#include <vector>
using namespace OCCUtils;
int main() {
TopoDS_Solid myCube = Primitive::MakeBox(5.0 /* X size */, 7.0 /* Y size */, 9.0 /* Z size */);
STEP::ExportSTEP(myCube, "out.step");
}Now we can configure & build using
build_mkbox.sh
cmake .
makeWhen running the program using
run_mkbox.sh
./mkboxwe see the following debug output:
mkbox_output.txt
*******************************************************************
****** Statistics on Transfer (Write) ******
*******************************************************************
****** Transfer Mode = 0 I.E. As Is ******
****** Transferring Shape, ShapeType = 2 ******
** WorkSession : Sending all data
Step File Name : out.step(350 ents) Write Doneand mkbox will generate out.step which you can open, for example, in FreeCAD to view the generated STEP file:

Check out similar posts by category:
C/C++, OpenCASCADE
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow