main
John Lauer Review off-board sensor and mechanical libraries with truthful conversion and supplier limits 4c1d6f7
"""Original nominal PEEK hardware assets; not qualified thread or preload models."""
from pathlib import Path
import math,json,shutil,hashlib
import cadquery as cq
from glb_shape_helpers import add_shape,write_glb
R=Path(__file__).resolve().parents[1]
parts=[('SPE-M3-12-P','Pan-head screw',cq.Solid.makeCylinder(2.75,2).fuse(cq.Solid.makeCylinder(1.5,12,cq.Vector(0,0,2))),{'thread':'M3x0.5','underHeadLengthMm':12,'headDiameterMm':5.5,'headHeightMm':2},'https://www.nbk1560.com/en-US/products/specialscrew/nedzicom/chemicalscrew/SPE-P/'),('SPE-M3-N','Hex nut',cq.Workplane('XY').polygon(6,5.5/math.cos(math.pi/6)).extrude(2.4).val().cut(cq.Solid.makeCylinder(1.5,2.4)),{'thread':'M3x0.5','acrossFlatsMm':5.5,'heightMm':2.4},'https://www.nbk1560.com/en-US/products/specialscrew/nedzicom/chemicalscrew/SPE-N/')]
for mpn,kind,shape,dims,url in parts:
 slug=mpn.lower();p=R/'components'/slug;p.mkdir(exist_ok=True);assert shape.isValid();cq.exporters.export(shape,str(p/(slug+'.step')))
 g={'asset':{'version':'2.0','generator':'Adom nominal PEEK envelope'},'scene':0,'scenes':[{'nodes':[0]}],'nodes':[{'name':mpn+'.Nominal','children':[]}],'buffers':[{'byteLength':0}],'accessors':[]};blob=bytearray();add_shape(g,blob,shape,mpn,(.53,.37,.20),0,'Original nominal envelope; threads, screw recess and chamfers omitted');write_glb(p/(slug+'.glb'),g,blob)
 symbol_name=mpn.replace('-','_')
 sym=f'''(kicad_symbol_lib (version 20231120) (generator "adom")
 (symbol "{symbol_name}" (in_bom yes) (on_board no)
 (property "Reference" "H" (at 0 5.08 0) (effects (font (size 1.27 1.27))))
 (property "Value" "{mpn}" (at 0 -5.08 0) (effects (font (size 1.27 1.27))))
 (property "MPN" "{mpn}" (at 0 0 0) (hide yes) (effects (font (size 1.27 1.27))))
 (property "Manufacturer" "NBK" (at 0 0 0) (hide yes) (effects (font (size 1.27 1.27))))
 (symbol "{symbol_name}_0_1"
 (circle (center 0 0) (radius 2.54) (stroke (width 0.254) (type default)) (fill (type none)))
 (circle (center 0 0) (radius 0.8) (stroke (width 0.254) (type default)) (fill (type none))))))
'''
 (p/(slug+'.kicad_sym')).write_text(sym)
 radius=dims.get('headDiameterMm',5.5/math.cos(math.pi/6))/2

 fp=f'''(footprint "{mpn}_MECHANICAL_ONLY" (version 20240108) (generator "adom") (layer "F.Cu")
 (descr "Nominal off-board {kind.lower()} envelope only; no copper or PCB drill implied")
 (attr board_only exclude_from_pos_files exclude_from_bom)
 (fp_circle (center 0 0) (end {radius:.6f} 0) (stroke (width 0.15) (type default)) (fill none) (layer "F.Fab"))
 (model "{slug}.step" (offset (xyz 0 0 0)) (scale (xyz 1 1 1)) (rotate (xyz 0 0 0))))\n'''
 (p/(slug+'.kicad_mod')).write_text(fp)
 for typ,obj in [('symbol',{'pins':[],'offBoard':True,'role':'mechanical BOM item'}),('footprint',{'pads':[],'pcbDrills':[],'role':'mechanical-envelope-only'})]:(p/(slug+'_'+typ+'.json')).write_text(json.dumps(dict(mpn=mpn,**obj),indent=2)+'\n')
 report={'mpn':mpn,'manufacturer':'NBK','source':url,'status':'original-nominal-envelope-not-qualified','dimensions':dims,'solidValid':True,'stepSha256':hashlib.sha256((p/(slug+'.step')).read_bytes()).hexdigest(),'omitted':['Threads','Screw recess','Chamfers and molding details','Manufacturing tolerances'],'limits':['No preload, creep, retention, insulation or assembly torque qualification','No manufacturer CAD or permission to redistribute it established']};(p/'provenance.json').write_text(json.dumps(report,indent=2)+'\n');shutil.copy2(R/'components/680-125220/LICENSE',p/'LICENSE')
 (p/'README.md').write_text(f'# NBK {mpn}\n\nPEEK {kind.lower()} with {dims["thread"]} nominal thread. [Manufacturer listing]({url}).\n\nThe original STEP/GLB is only a nominal envelope. Threads, drive recesses, chamfers, molding details and tolerances are omitted. Do not use it to manufacture the part or qualify preload, thread engagement, creep, insulation or installation torque.\n\nThe zero-pin symbol represents an off-board mechanical BOM item. The zero-pad footprint is only an envelope; it implies no electrical terminal or PCB drill. Select assembly support and fasteners from the actual drawing and test the complete stack.\n\nExact distributor catalog numbers remain unresolved. The manufacturer sells this ordering code directly in packs; do not substitute unrelated electronic distributor hits or claim zero search results prove nonavailability.\n\nOriginal Adom assets are MIT. Manufacturer material retains its original rights and is not redistributed. This is a local catalog draft, not an approved assembly.\n')
 print(slug,'nominal geometry valid')