stepfile_compare / app /utils /step_utils.py
xryv's picture
v1
fd4e6a2
Raw History Blame Contribute Delete
1.09 kB
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
}