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:

git init

Now we can add OCCUtilsusing the submodule method:

git submodule init
git submodule add https://github.com/ulikoehler/OCCUtils.git OCCUtils

Now we can add the CMake config:

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:

#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

cmake .
make

When running the program using

./mkbox

we see the following debug output:

*******************************************************************
******        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  Done

and mkbox will generate out.step which you can open, for example, in FreeCAD to view the generated STEP file: