main
John Lauer Publish 0.1.0 63d2d8d 9d ago
"""AI-created 3D model of the Abracon AMPLH5030S molded power inductor, from its datasheet.

Source: https://abracon.com/datasheets/AMPLH5030S.pdf (Initial Release 2/27/2024), page 3
"Mechanical Specifications": body 5.60 +/- 0.30 (X) x 5.20 +/- 0.20 (Y) x 2.80 +/- 0.20 (Z) mm;
bottom electrodes 1.30 +/- 0.30 (X) x 3.00 +/- 0.30 (Y) mm at each X end. Simplifications: square
body edges, electrodes as 0.05 mm slabs on the underside plus a 0.6 mm wrap up each end face,
no marking. Origin at the body centre on the board surface (z = 0), X along the pads, mm.

Run: PYTHONPATH=<ocp> python3 make_amplh5030s_step.py <out.step>
"""
import sys
from OCP.BRepPrimAPI import BRepPrimAPI_MakeBox
from OCP.gp import gp_Pnt
from OCP.TDocStd import TDocStd_Document
from OCP.TCollection import TCollection_ExtendedString, TCollection_HAsciiString
from OCP.XCAFDoc import XCAFDoc_DocumentTool, XCAFDoc_ColorType
from OCP.Quantity import Quantity_Color, Quantity_TOC_RGB
from OCP.STEPCAFControl import STEPCAFControl_Writer
from OCP.STEPControl import STEPControl_AsIs
from OCP.Interface import Interface_Static
from OCP.TDataStd import TDataStd_Name

BX, BY, BZ = 5.60, 5.20, 2.80          # body
EX, EY, ET = 1.30, 3.00, 0.05          # electrode footprint + slab thickness
WRAP = 0.60                            # electrode wrap height up the end face
SKIN = 0.03                            # wrap thickness outside the body


def box(x0, y0, z0, x1, y1, z1):
    return BRepPrimAPI_MakeBox(gp_Pnt(x0, y0, z0), gp_Pnt(x1, y1, z1)).Shape()


body = box(-BX / 2, -BY / 2, ET, BX / 2, BY / 2, BZ)
terms = []
for s in (-1, 1):
    xo = s * BX / 2
    xi = s * (BX / 2 - EX)
    terms.append(box(min(xo, xi), -EY / 2, 0, max(xo, xi), EY / 2, ET))                     # underside pad
    terms.append(box(min(xo, xo + s * SKIN), -EY / 2, 0, max(xo, xo + s * SKIN), EY / 2, WRAP))  # end-face wrap

doc = TDocStd_Document(TCollection_ExtendedString("XmlOcaf"))
shapes = XCAFDoc_DocumentTool.ShapeTool_s(doc.Main())
colors = XCAFDoc_DocumentTool.ColorTool_s(doc.Main())
dark = Quantity_Color(0.18, 0.18, 0.19, Quantity_TOC_RGB)
tin = Quantity_Color(0.80, 0.80, 0.78, Quantity_TOC_RGB)
for name, shp, col in [("AMPLH5030S_body", body, dark)] + [(f"AMPLH5030S_electrode_{i}", t, tin) for i, t in enumerate(terms)]:
    lab = shapes.AddShape(shp, False)
    TDataStd_Name.Set_s(lab, TCollection_ExtendedString(name))
    colors.SetColor(lab, col, XCAFDoc_ColorType.XCAFDoc_ColorSurf)

Interface_Static.SetCVal_s("write.step.schema", "AP214IS")
Interface_Static.SetCVal_s("write.step.unit", "MM")
w = STEPCAFControl_Writer()
w.SetColorMode(True); w.SetNameMode(True)
w.Transfer(doc, STEPControl_AsIs)
out = sys.argv[1] if len(sys.argv) > 1 else "AMPLH5030S.step"
assert int(w.Write(out)) == 1, "STEP write failed"
print("wrote", out)