Spaces:
Runtime error
Runtime error
File size: 1,088 Bytes
fd4e6a2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | from OCC.Core.STEPControl import STEPControl_Reader
from OCC.Core.BRepGProp import brepgprop_SurfaceProperties, brepgprop_VolumeProperties
from OCC.Core.GProp import GProp_GProps
from OCC.Core.Bnd import Bnd_Box
from OCC.Core.BRepBndLib import brepbndlib_Add
def load_step(file_path):
reader = STEPControl_Reader()
status = reader.ReadFile(file_path)
if status != 1:
raise ValueError("Invalid STEP file")
reader.TransferRoots()
return reader.OneShape()
def compute_properties(shape):
props = GProp_GProps()
# Surface area and volume
brepgprop_SurfaceProperties(shape, props)
surface_area = props.Mass()
brepgprop_VolumeProperties(shape, props)
volume = props.Mass()
# Bounding box
bbox = Bnd_Box()
brepbndlib_Add(shape, bbox)
xmin, ymin, zmin, xmax, ymax, zmax = bbox.Get()
dimensions = {
"x_length": xmax - xmin,
"y_length": ymax - ymin,
"z_length": zmax - zmin
}
return {
"surface_area": surface_area,
"volume": volume,
"bounding_box": dimensions
}
|