Table of Contents

Getting started

Install

dotnet add package NetOcc

One AnyCPU package for .NET Framework 3.5 and 4.5+, .NET 6, 8 and 10, with the natives for win-x64, win-x86, linux-x64 and osx-arm64, and OCCT's documentation for IntelliSense.

Important

Windows needs the Visual C++ 2015-2022 runtime, Linux glibc 2.35 or newer, macOS 14 or newer on Apple silicon. See Platforms.

A first part

A block with a hole, rounded, measured, and written as STEP and STL:

flowchart LR
    box[MakeBox] --> cut[Cut]
    cylinder[MakeCylinder] --> cut
    cut --> fillet[MakeFillet] --> volume[VolumeProperties]
    fillet --> step[STEP file]
    fillet --> mesh[IncrementalMesh] --> stl[STL file]

Namespaces are OCCT's packages:

using OCC.Core.BRepAlgoAPI;
using OCC.Core.BRepFilletAPI;
using OCC.Core.BRepGProp;
using OCC.Core.BRepMesh;
using OCC.Core.BRepPrimAPI;
using OCC.Core.GProp;
using OCC.Core.gp;
using OCC.Core.STEPControl;
using OCC.Core.StlAPI;
using OCC.Core.TopAbs;
using OCC.Core.TopExp;
using OCC.Core.TopoDS;
using OCC.Core.TopTools;
// a 60 x 40 x 20 block with a hole through it
var block = new BRepPrimAPI_MakeBox(60, 40, 20).Shape();
var axis = new gp_Ax2(new gp_Pnt(30, 20, -1), new gp_Dir(0, 0, 1));
var hole = new BRepPrimAPI_MakeCylinder(axis, 8, 22).Shape();
var part = new BRepAlgoAPI_Cut(block, hole).Shape();

// round every edge by 1.5, each once
var edges = new TopTools_IndexedMapOfShape();
TopExp.MapShapes(part, TopAbs_ShapeEnum.TopAbs_EDGE, edges);
var fillet = new BRepFilletAPI_MakeFillet(part);
foreach (var edge in edges)
{
  fillet.Add(1.5, TopoDS.Edge(edge));
}

var rounded = fillet.Shape();

// its volume, then the part as STEP and, triangulated, as STL
var properties = new GProp_GProps();
BRepGProp.VolumeProperties(rounded, properties);
Console.WriteLine($"volume: {properties.Mass():F1} mm³");

var step = new STEPControl_Writer();
step.Transfer(rounded, STEPControl_StepModelType.STEPControl_AsIs);
step.Write("part.step");

new BRepMesh_IncrementalMesh(rounded, 0.1);
new StlAPI_Writer().Write(rounded, "part.stl");

What's going on:

  • Builders (BRepPrimAPI_MakeBox, BRepAlgoAPI_Cut, BRepFilletAPI_MakeFillet) take their input in the constructor or through Add, and give the result through Shape(). See Modeling.
  • TopoDS_Shape is every shape: solids, faces, edges. TopExp.MapShapes collects the parts of one type, each once; TopoDS.Edge casts. See Topology.
  • foreach works on OCCT's collections.
  • Meshing stores triangles in the shape's faces; STL writes them. See Meshing.

Where next

To Read
get the big picture of OCCT Introduction
work with points, curves and surfaces Geometry
take shapes apart and build them from edges and faces Topology
read STEP files with colors and assemblies Assemblies
show shapes in a window 3D views
translate OCCT C++ code into C# From C++ to C#
handle failures Errors