Calculating Volume and Surface Area
OCCT provides built-in functions to calculate geometric properties of solid shapes, including volume and surface area. This tutorial demonstrates how to:
- Create a parametric cone solid
- Calculate the volume of the solid using
getSolidVolume - Calculate the surface area using
getSolidSurfaceArea - Format and display the results with proper units
- Use pin labels for visual annotation
The example shows a practical workflow for measuring and displaying geometric properties, which is essential for engineering calculations, material estimates, and design validation.

- Rete
- Blockly
- TypeScript
Script Source (rete)
{
"id": "rete-v2-json",
"nodes": {
"cone": {
"id": "cone",
"name": "bitbybit.occt.shapes.solid.createCone",
"customName": "cone",
"async": true,
"drawable": true,
"data": {
"genericNodeData": {
"hide": false,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
},
"radius1": 2,
"radius2": 1,
"height": 2,
"angle": 360,
"center": [
0,
0,
0
],
"direction": [
0,
1,
0
]
},
"inputs": {
"height": {
"connections": [
{
"node": "numberSlider",
"output": "result",
"data": {}
}
]
}
},
"position": [
316,
429
]
},
"getSolidVolume": {
"id": "getSolidVolume",
"name": "bitbybit.occt.shapes.solid.getSolidVolume",
"customName": "get solid volume",
"async": true,
"drawable": false,
"data": {
"genericNodeData": {
"hide": false,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
}
},
"inputs": {
"shape": {
"connections": [
{
"node": "cone",
"output": "result",
"data": {}
}
]
}
},
"position": [
777,
228
]
},
"pinWithLabel": {
"id": "pinWithLabel",
"name": "bitbybit.occt.dimensions.pinWithLabel",
"customName": "pin with label",
"async": true,
"drawable": true,
"data": {
"genericNodeData": {
"hide": false,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
},
"startPoint": [
0,
0,
0
],
"endPoint": [
0,
5,
2
],
"direction": [
0,
0,
1
],
"offsetFromStart": 0,
"label": "Pin",
"labelOffset": 0.3,
"labelSize": 0.3,
"endType": "none",
"arrowSize": 0.3,
"arrowAngle": 30,
"arrowsFlipped": false,
"labelRotation": 0,
"labelFlipHorizontal": false,
"labelFlipVertical": false
},
"inputs": {
"startPoint": {
"connections": [
{
"node": "pointXyz",
"output": "result",
"data": {}
}
]
},
"endPoint": {
"connections": [
{
"node": "pointXyz2",
"output": "result",
"data": {}
}
]
},
"direction": {
"connections": [
{
"node": "vectorXyz",
"output": "result",
"data": {}
}
]
},
"label": {
"connections": [
{
"node": "format",
"output": "result",
"data": {}
}
]
}
},
"position": [
3856,
-1016
]
},
"toString": {
"id": "toString",
"name": "bitbybit.text.toString",
"customName": "to string",
"async": false,
"drawable": false,
"data": {
"genericNodeData": {
"hide": false,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
}
},
"inputs": {
"item": {
"connections": [
{
"node": "roundToDecimals",
"output": "result",
"data": {}
}
]
}
},
"position": [
1536,
224
]
},
"roundToDecimals": {
"id": "roundToDecimals",
"name": "bitbybit.math.roundToDecimals",
"customName": "round to decimals",
"async": false,
"drawable": false,
"data": {
"genericNodeData": {
"hide": false,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
},
"number": 1.123456,
"decimalPlaces": 2
},
"inputs": {
"number": {
"connections": [
{
"node": "getSolidVolume",
"output": "result",
"data": {}
}
]
}
},
"position": [
1163,
227
]
},
"pointXyz": {
"id": "pointXyz",
"name": "bitbybit.point.pointXYZ",
"customName": "point xyz",
"async": false,
"drawable": true,
"data": {
"genericNodeData": {
"hide": true,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
},
"x": 0,
"y": 0,
"z": 0
},
"inputs": {
"y": {
"connections": [
{
"node": "numberSlider",
"output": "result",
"data": {}
}
]
}
},
"position": [
320,
-824
]
},
"numberSlider": {
"id": "numberSlider",
"name": "bitbybit.math.numberSlider",
"customName": "number slider",
"async": false,
"drawable": false,
"data": {
"options": {},
"number": 5
},
"inputs": {},
"position": [
-471,
55
]
},
"pointXyz2": {
"id": "pointXyz2",
"name": "bitbybit.point.pointXYZ",
"customName": "point xyz",
"async": false,
"drawable": true,
"data": {
"genericNodeData": {
"hide": true,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
},
"x": 1,
"y": 0,
"z": 0
},
"inputs": {
"y": {
"connections": [
{
"node": "add",
"output": "result",
"data": {}
}
]
}
},
"position": [
875,
-615
]
},
"add": {
"id": "add",
"name": "bitbybit.math.add",
"customName": "add",
"async": false,
"drawable": false,
"data": {
"genericNodeData": {
"hide": false,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
},
"first": 1,
"second": 3
},
"inputs": {
"first": {
"connections": [
{
"node": "numberSlider",
"output": "result",
"data": {}
}
]
}
},
"position": [
312,
-446
]
},
"vectorXyz": {
"id": "vectorXyz",
"name": "bitbybit.vector.vectorXYZ",
"customName": "vector xyz",
"async": false,
"drawable": true,
"data": {
"genericNodeData": {
"hide": false,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
},
"x": 1,
"y": 0,
"z": 0
},
"inputs": {},
"position": [
3015,
-731
]
},
"format": {
"id": "format",
"name": "bitbybit.text.format",
"customName": "format",
"async": false,
"drawable": false,
"data": {
"genericNodeData": {
"hide": false,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
},
"text": "Volume {0} m3",
"values": [
"World"
]
},
"inputs": {
"values": {
"connections": [
{
"node": "createList",
"output": "list",
"data": {}
}
]
}
},
"position": [
2319,
183
]
},
"createList": {
"id": "createList",
"name": "bitbybit.lists.createList",
"customName": "create list",
"async": false,
"drawable": false,
"data": {},
"inputs": {
"listElements": {
"connections": [
{
"node": "toString",
"output": "result",
"data": {}
}
]
}
},
"position": [
1905,
259
]
},
"getSolidSurfaceArea": {
"id": "getSolidSurfaceArea",
"name": "bitbybit.occt.shapes.solid.getSolidSurfaceArea",
"customName": "get solid surface area",
"async": true,
"drawable": false,
"data": {
"genericNodeData": {
"hide": false,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
}
},
"inputs": {
"shape": {
"connections": [
{
"node": "cone",
"output": "result",
"data": {}
}
]
}
},
"position": [
781,
561
]
},
"roundToDecimals2": {
"id": "roundToDecimals2",
"name": "bitbybit.math.roundToDecimals",
"customName": "round to decimals",
"async": false,
"drawable": false,
"data": {
"genericNodeData": {
"hide": false,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
},
"number": 1.123456,
"decimalPlaces": 2
},
"inputs": {
"number": {
"connections": [
{
"node": "getSolidSurfaceArea",
"output": "result",
"data": {}
}
]
}
},
"position": [
1156,
560
]
},
"toString2": {
"id": "toString2",
"name": "bitbybit.text.toString",
"customName": "to string",
"async": false,
"drawable": false,
"data": {
"genericNodeData": {
"hide": false,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
}
},
"inputs": {
"item": {
"connections": [
{
"node": "roundToDecimals2",
"output": "result",
"data": {}
}
]
}
},
"position": [
1537,
558
]
},
"createList2": {
"id": "createList2",
"name": "bitbybit.lists.createList",
"customName": "create list",
"async": false,
"drawable": false,
"data": {},
"inputs": {
"listElements": {
"connections": [
{
"node": "toString2",
"output": "result",
"data": {}
}
]
}
},
"position": [
1906,
592
]
},
"format2": {
"id": "format2",
"name": "bitbybit.text.format",
"customName": "format",
"async": false,
"drawable": false,
"data": {
"genericNodeData": {
"hide": false,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
},
"text": "Area {0} m2",
"values": [
"World"
]
},
"inputs": {
"values": {
"connections": [
{
"node": "createList2",
"output": "list",
"data": {}
}
]
}
},
"position": [
2320,
513
]
},
"pinWithLabel2": {
"id": "pinWithLabel2",
"name": "bitbybit.occt.dimensions.pinWithLabel",
"customName": "pin with label",
"async": true,
"drawable": true,
"data": {
"genericNodeData": {
"hide": false,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
},
"startPoint": [
0,
0,
0
],
"endPoint": [
0,
5,
2
],
"direction": [
0,
0,
1
],
"offsetFromStart": 0,
"label": "Pin",
"labelOffset": 0.3,
"labelSize": 0.3,
"endType": "none",
"arrowSize": 0.3,
"arrowAngle": 30,
"arrowsFlipped": false,
"labelRotation": 0,
"labelFlipHorizontal": false,
"labelFlipVertical": false
},
"inputs": {
"startPoint": {
"connections": [
{
"node": "pointXyz",
"output": "result",
"data": {}
}
]
},
"endPoint": {
"connections": [
{
"node": "pointXyz3",
"output": "result",
"data": {}
}
]
},
"label": {
"connections": [
{
"node": "format2",
"output": "result",
"data": {}
}
]
},
"direction": {
"connections": [
{
"node": "vectorXyz",
"output": "result",
"data": {}
}
]
}
},
"position": [
3856,
-299
]
},
"pointXyz3": {
"id": "pointXyz3",
"name": "bitbybit.point.pointXYZ",
"customName": "point xyz",
"async": false,
"drawable": true,
"data": {
"genericNodeData": {
"hide": true,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
},
"x": 1,
"y": 0,
"z": 0
},
"inputs": {
"y": {
"connections": [
{
"node": "add2",
"output": "result",
"data": {}
}
]
}
},
"position": [
874,
-265
]
},
"add2": {
"id": "add2",
"name": "bitbybit.math.add",
"customName": "add",
"async": false,
"drawable": false,
"data": {
"genericNodeData": {
"hide": false,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
},
"first": 1,
"second": 4
},
"inputs": {
"first": {
"connections": [
{
"node": "numberSlider",
"output": "result",
"data": {}
}
]
}
},
"position": [
307,
-134
]
}
},
"modules": {}
}
Script Source (blockly)
<xml xmlns="https://developers.google.com/blockly/xml"><variables><variable id="height">height</variable><variable id="cone">cone</variable><variable id="volume">volume</variable><variable id="surfaceArea">surfaceArea</variable><variable id="roundedVolume">roundedVolume</variable><variable id="roundedSurfaceArea">roundedSurfaceArea</variable><variable id="volumeText">volumeText</variable><variable id="areaText">areaText</variable><variable id="volumePin">volumePin</variable><variable id="areaPin">areaPin</variable></variables><block type="variables_set" x="50" y="50"><field name="VAR" id="height">height</field><value name="VALUE"><block type="math_number"><field name="NUM">5</field></block></value><next><block type="variables_set"><field name="VAR" id="cone">cone</field><value name="VALUE"><block type="bitbybit.occt.shapes.solid.createCone"><value name="Radius1"><block type="math_number"><field name="NUM">2</field></block></value><value name="Radius2"><block type="math_number"><field name="NUM">1</field></block></value><value name="Height"><block type="variables_get"><field name="VAR" id="height">height</field></block></value><value name="Angle"><block type="math_number"><field name="NUM">360</field></block></value><value name="Center"><block type="bitbybit.point.pointXYZ"><value name="X"><block type="math_number"><field name="NUM">0</field></block></value><value name="Y"><block type="math_number"><field name="NUM">0</field></block></value><value name="Z"><block type="math_number"><field name="NUM">0</field></block></value></block></value><value name="Direction"><block type="bitbybit.vector.vectorXYZ"><value name="X"><block type="math_number"><field name="NUM">0</field></block></value><value name="Y"><block type="math_number"><field name="NUM">1</field></block></value><value name="Z"><block type="math_number"><field name="NUM">0</field></block></value></block></value></block></value><next><block type="variables_set"><field name="VAR" id="volume">volume</field><value name="VALUE"><block type="base_time_await_return"><value name="Promise"><block type="bitbybit.occt.shapes.solid.getSolidVolume"><value name="Shape"><block type="variables_get"><field name="VAR" id="cone">cone</field></block></value></block></value></block></value><next><block type="variables_set"><field name="VAR" id="surfaceArea">surfaceArea</field><value name="VALUE"><block type="base_time_await_return"><value name="Promise"><block type="bitbybit.occt.shapes.solid.getSolidSurfaceArea"><value name="Shape"><block type="variables_get"><field name="VAR" id="cone">cone</field></block></value></block></value></block></value><next><block type="variables_set"><field name="VAR" id="roundedVolume">roundedVolume</field><value name="VALUE"><block type="bitbybit.math.roundToDecimals"><value name="Number"><block type="variables_get"><field name="VAR" id="volume">volume</field></block></value><value name="DecimalPlaces"><block type="math_number"><field name="NUM">2</field></block></value></block></value><next><block type="variables_set"><field name="VAR" id="roundedSurfaceArea">roundedSurfaceArea</field><value name="VALUE"><block type="bitbybit.math.roundToDecimals"><value name="Number"><block type="variables_get"><field name="VAR" id="surfaceArea">surfaceArea</field></block></value><value name="DecimalPlaces"><block type="math_number"><field name="NUM">2</field></block></value></block></value><next><block type="variables_set"><field name="VAR" id="volumeText">volumeText</field><value name="VALUE"><block type="bitbybit.text.format"><value name="Text"><block type="text"><field name="TEXT">Volume {0} m3</field></block></value><value name="Values"><block type="bitbybit.text.toStringEach"><value name="List"><block type="lists_create_with"><mutation items="1"></mutation><value name="ADD0"><block type="variables_get"><field name="VAR" id="roundedVolume">roundedVolume</field></block></value></block></value></block></value></block></value><next><block type="variables_set"><field name="VAR" id="areaText">areaText</field><value name="VALUE"><block type="bitbybit.text.format"><value name="Text"><block type="text"><field name="TEXT">Area {0} m2</field></block></value><value name="Values"><block type="bitbybit.text.toStringEach"><value name="List"><block type="lists_create_with"><mutation items="1"></mutation><value name="ADD0"><block type="variables_get"><field name="VAR" id="roundedSurfaceArea">roundedSurfaceArea</field></block></value></block></value></block></value></block></value><next><block type="variables_set"><field name="VAR" id="volumePin">volumePin</field><value name="VALUE"><block type="bitbybit.occt.dimensions.pinWithLabel"><value name="StartPoint"><block type="bitbybit.point.pointXYZ"><value name="X"><block type="math_number"><field name="NUM">0</field></block></value><value name="Y"><block type="variables_get"><field name="VAR" id="height">height</field></block></value><value name="Z"><block type="math_number"><field name="NUM">0</field></block></value></block></value><value name="EndPoint"><block type="bitbybit.point.pointXYZ"><value name="X"><block type="math_number"><field name="NUM">1</field></block></value><value name="Y"><block type="math_arithmetic"><field name="OP">ADD</field><value name="A"><block type="variables_get"><field name="VAR" id="height">height</field></block></value><value name="B"><block type="math_number"><field name="NUM">3</field></block></value></block></value><value name="Z"><block type="math_number"><field name="NUM">0</field></block></value></block></value><value name="Direction"><block type="bitbybit.vector.vectorXYZ"><value name="X"><block type="math_number"><field name="NUM">1</field></block></value><value name="Y"><block type="math_number"><field name="NUM">0</field></block></value><value name="Z"><block type="math_number"><field name="NUM">0</field></block></value></block></value><value name="OffsetFromStart"><block type="math_number"><field name="NUM">0</field></block></value><value name="Label"><block type="variables_get"><field name="VAR" id="volumeText">volumeText</field></block></value><value name="LabelOffset"><block type="math_number"><field name="NUM">0.3</field></block></value><value name="LabelSize"><block type="math_number"><field name="NUM">0.3</field></block></value></block></value><next><block type="variables_set"><field name="VAR" id="areaPin">areaPin</field><value name="VALUE"><block type="bitbybit.occt.dimensions.pinWithLabel"><value name="StartPoint"><block type="bitbybit.point.pointXYZ"><value name="X"><block type="math_number"><field name="NUM">0</field></block></value><value name="Y"><block type="variables_get"><field name="VAR" id="height">height</field></block></value><value name="Z"><block type="math_number"><field name="NUM">0</field></block></value></block></value><value name="EndPoint"><block type="bitbybit.point.pointXYZ"><value name="X"><block type="math_number"><field name="NUM">1</field></block></value><value name="Y"><block type="math_arithmetic"><field name="OP">ADD</field><value name="A"><block type="variables_get"><field name="VAR" id="height">height</field></block></value><value name="B"><block type="math_number"><field name="NUM">4</field></block></value></block></value><value name="Z"><block type="math_number"><field name="NUM">0</field></block></value></block></value><value name="Direction"><block type="bitbybit.vector.vectorXYZ"><value name="X"><block type="math_number"><field name="NUM">1</field></block></value><value name="Y"><block type="math_number"><field name="NUM">0</field></block></value><value name="Z"><block type="math_number"><field name="NUM">0</field></block></value></block></value><value name="OffsetFromStart"><block type="math_number"><field name="NUM">0</field></block></value><value name="Label"><block type="variables_get"><field name="VAR" id="areaText">areaText</field></block></value><value name="LabelOffset"><block type="math_number"><field name="NUM">0.3</field></block></value><value name="LabelSize"><block type="math_number"><field name="NUM">0.3</field></block></value></block></value><next><block type="bitbybit.draw.drawAnyAsyncNoReturn"><value name="Entity"><block type="variables_get"><field name="VAR" id="cone">cone</field></block></value><next><block type="bitbybit.draw.drawAnyAsyncNoReturn"><value name="Entity"><block type="variables_get"><field name="VAR" id="volumePin">volumePin</field></block></value><next><block type="bitbybit.draw.drawAnyAsyncNoReturn"><value name="Entity"><block type="variables_get"><field name="VAR" id="areaPin">areaPin</field></block></value></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></xml>
Script Source (typescript)
// Import required DTOs and types
const { ConeDto, PinWithLabelDto } = Bit.Inputs.OCCT;
type Point3 = Bit.Inputs.Base.Point3;
type Vector3 = Bit.Inputs.Base.Vector3;
// Get access to OCCT modules
const { solid } = bitbybit.occt.shapes;
const { dimensions } = bitbybit.occt;
const { math, text } = bitbybit;
// Demonstrate volume and surface area calculation
// Parametric height value
const height = 5;
// Create a cone
const coneOptions = new ConeDto();
coneOptions.radius1 = 2;
coneOptions.radius2 = 1;
coneOptions.height = height;
coneOptions.angle = 360;
coneOptions.center = [0, 0, 0] as Point3;
coneOptions.direction = [0, 1, 0] as Vector3;
const cone = await solid.createCone(coneOptions);
// Get volume and surface area
const volume = await solid.getSolidVolume({ shape: cone });
const surfaceArea = await solid.getSolidSurfaceArea({ shape: cone });
// Round to 2 decimal places
const roundedVolume = math.roundToDecimals({ number: volume, decimalPlaces: 2 });
const roundedSurfaceArea = math.roundToDecimals({ number: surfaceArea, decimalPlaces: 2 });
// Format as text with units
const volumeText = text.format({
text: "Volume {0} m3",
values: [text.toString({ item: roundedVolume })]
});
const areaText = text.format({
text: "Area {0} m2",
values: [text.toString({ item: roundedSurfaceArea })]
});
// Create pin labels to display the measurements
const volumePinOptions = new PinWithLabelDto();
volumePinOptions.startPoint = [0, height, 0] as Point3;
volumePinOptions.endPoint = [1, height + 3, 0] as Point3;
volumePinOptions.direction = [1, 0, 0] as Vector3;
volumePinOptions.offsetFromStart = 0;
volumePinOptions.label = volumeText;
volumePinOptions.labelOffset = 0.3;
volumePinOptions.labelSize = 0.3;
const volumePin = await dimensions.pinWithLabel(volumePinOptions);
const areaPinOptions = new PinWithLabelDto();
areaPinOptions.startPoint = [0, height, 0] as Point3;
areaPinOptions.endPoint = [1, height + 4, 0] as Point3;
areaPinOptions.direction = [1, 0, 0] as Vector3;
areaPinOptions.offsetFromStart = 0;
areaPinOptions.label = areaText;
areaPinOptions.labelOffset = 0.3;
areaPinOptions.labelSize = 0.3;
const areaPin = await dimensions.pinWithLabel(areaPinOptions);
// Draw the cone and labels
bitbybit.draw.drawAnyAsync({ entity: cone });
bitbybit.draw.drawAnyAsync({ entity: volumePin });
bitbybit.draw.drawAnyAsync({ entity: areaPin });



