I am trying to print the total volume of my model in the terminal, but it is not showing anything. I referred to "https://stackoverflow.com/questions/66929762/extract-volume-from-a-step-file" but was not helpul. Below is my code
from OCC.Display.SimpleGui import init_display
from OCC.Core.STEPControl import STEPControl_Reader
from OCC.Extend.DataExchange import read_step_file
from OCC.Core.GProp import GProp_GProps
from OCC.Core.BRepGProp import brepgprop_VolumeProperties
def open_step_file():
# Open a file dialog to select the STEP file
file_path = filedialog.askopenfilename(
title="Geometry Construction",
filetypes=[("STEP Files", "*.stp")]
)
if file_path:
# Initialize the display
display, start_display, _, _ = init_display()
# Read the STEP file
step_reader = STEPControl_Reader()
step_reader.ReadFile(file_path)
# Transfer the contents of the STEP file to the display
step_reader.TransferRoots()
shape = step_reader.Shape()
display.DisplayShape(shape, update=True)
# Start the display
start_display()
def calculate_total_volume(file_path):
if file_path:
total_volume = 0.0
for shape in file_path:
volume_props = GProp_GProps()
brepgprop_VolumeProperties(shape, volume_props)
total_volume += volume_props.Mass()
print(total_volume)
Can anyone please help me on this?