alloyer/alloyer-cnc-api
0
1import os2# 禁用GUI,避免服务器图形库报错3os.environ["OCC_NO_GUI"] = "1"4 5from OCC.Core.STEPControl import STEPControl_Reader6from OCC.Core.BRepGProp import brepgprop_VolumeProperties7from OCC.Core.GProp import GProp_GProps8from OCC.Core.Bnd import Bnd_Box9from OCC.Core.BRepBndLib import brepbndlib10 11def step_analyzer(step_path, material="6061", quantity=1):12 reader = STEPControl_Reader()13 reader.ReadFile(step_path)14 reader.TransferRoots()15 shape = reader.OneShape()16 17 # 包围盒 长宽高18 bbox = Bnd_Box()19 brepbndlib.Add(shape, bbox)20 xmin, ymin, zmin, xmax, ymax, zmax = bbox.Get()21 dx = round(xmax - xmin, 2)22 dy = round(ymax - ymin, 2)23 dz = round(zmax - zmin, 2)24 25 # 真实体积26 prop = GProp_GProps()27 brepgprop_VolumeProperties(shape, prop)28 vol = round(prop.Mass() / 1000, 3)29 30 # 统一底价 8.9931 base = 8.9932 total = round(base * quantity, 2)33 34 return {35 "part": {"size_mm": [dx, dy, dz], "volume_cm3": vol},36 "price_usd": {37 "low": round(total * 0.9, 2),38 "mid": total,39 "high": round(total * 1.1, 2)40 },41 "dfm": {"warnings": []}42 }