Spaces:
Runtime error
Runtime error
Download app/utils/step_utils.py from Newuserrr/stepfile_compare: direct link, hf CLI and curl.
- Browser
- Download file 1.09 kB
-
https://huggingface.co/spaces/Newuserrr/stepfile_compare/resolve/main/app/utils/step_utils.py
- Command line
-
hf download hf://spaces/Newuserrr/stepfile_compare/app/utils/step_utils.py
-
curl -L -o step_utils.py https://huggingface.co/spaces/Newuserrr/stepfile_compare/resolve/main/app/utils/step_utils.py
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 | |
| } | |