SolidWorks 2023 Native Automated Modeling (Recipe-Driven · Proven in Practice)
Package "describe object → JSON modeling recipe → SolidWorks direct draw" into a single command, with programmatic geometry verification.
Repository Layout
| Path | Description |
|---|---|
sw_bridge.py | Core bridge: recipe-driven, one command for modeling→save→export→assertion |
stl_slicer.py | STL ASCII slice verification (programmatic confirmation of contours/holes/slots, no image reading) |
recipes/ | Ready-made recipe examples (including full-chain self-test recipe_best_practices_test.json) |
dfm_check.py + rules/ | Product structure DFM checker: injection molding (16 rules)/3D printing (14 rules) dual-process quantitative rule base, design parameter table check + recipe lint |
skills/sw-dfm-injection/ | Branch skill: injection molding DFM (DVT/volume production, wall thickness/draft/snap/Boss/rib/undercut quantitative rules) |
skills/sw-dfm-proto/ | Branch skill: 3D printing prototype DFM (EVT, minimum feature/overhang/gap/drain hole quantitative rules) |
references/api-pitfalls.md | Complete hard-learned lessons: COM/signature/VARIANT/EquationMgr/ROT pitfalls, must-read before writing new capabilities |
references/recipe-cookbook.md | Recipe syntax details + templates + multi-spec/assertion usage |
references/industry-best-practices.md | Industry paradigm research summary + subsequent refactoring checklist |
docs/case_mcp1085_box.md | Real delivery case: two-layer water pipe inspection box |
config.example.json | Machine-specific configuration template (template path/ProgID/output directory) |
Environment Prerequisites (All Required)
- Windows + Genuine SolidWorks 2023 running. COM can only attach to an interactive session (
GetObject), cannot run headless, nor be launched by script (COM-launched instances cannot register ROT, see api-pitfalls §13). - Python 3.10+,
pip install -r requirements.txt(pywin32 / trimesh / manifold3d / numpy / pillow). - Chinese national standard template paths have built-in defaults; for English version or custom templates, copy
config.example.jsontoconfig.jsonand modify.
Quick Self-Check
python sw_bridge.py --demo block # Build block + export + geometry assertion all-in-one
python sw_bridge.py --demo vase # Spline revolve surface
python stl_slicer.py --stl demo_output/demo_block.STL --level 5 # Slice to view cross-section
Standard Workflow
- Write recipe JSON (syntax and templates in
references/recipe-cookbook.md) - Execute:
python sw_bridge.py --recipe-file recipes/xxx.json - Verify: Recipe built-in
verifyassertions (watertightness/volume/bounding box/golden IoU), failure means entire recipe fails; then usestl_slicer.pyto view cross-sections - Export views: Multiple
viewops export multi-angle PNGs;fmt: stepfor downstream - Structure review (product parts):
python dfm_check.py --design parameter_table.json --process both— injection molding/3D printing dual-process DFM check, FAIL means gate not passed; see branch skills inskills/
Recipe op Overview (Full parameters in cookbook)
| op | Description |
|---|---|
new_part / new_assembly / open | Document operations |
sketch / sketch_end / centerline / spline / line / rect / circle / arc | Sketch (mm) |
extrude / revolve / cut / fillet / chamfer | Features (auto retry degrade on failure) |
set_global_variable / add_equation | Global variables/equations → multi-spec variants via GV mutation |
view / save / export / add_component / import_mesh | View/Save/Export stl·png·step·iges/Assembly/Mesh import |
verify | trimesh assertion layer (watertight/volume/bounding box/golden IoU) |
During execution, graphics refresh/feature tree are automatically frozen (performance wrapper), and finalized with unified ForceRebuild3+ForceRebuildAll.
Hard Rules Quick Reference (Full version in references/api-pitfalls.md)
- API length unit is always meters, write mm in recipes (bridge auto-converts).
FeatureRevolve2has 20 parameters; the 4/5/7 parameter versions generated by the type library are all wrong.- In late binding, Callout/ExportData must pass
VARIANT(VT_DISPATCH, None);CreateSpline2point array must beVT_ARRAY|VT_R8. - Enter/exit sketch use
InsertSketch(True)(Toggle). - Chinese localized names: 前视基准面/草图1/*等轴测 (config can switch to English environment candidate).
- Complex features (>12 params) fail → ultimate fallback: SW record macro →
RunMacro2playback. GetEquationMgris propget-only, must force PROPERTYGET by dispid (see api-pitfalls §12).- For complex API signatures, first check SW's installed type library (makepy) or record macro, don't guess from memory.
Version Compatibility Notes
This package is tested and proven on SW2023 Chinese national standard version (including dispid 66286, ProgID .31, 20-param FeatureRevolve2, and other version-specific details).
Other SW versions share the core workflow, but version-specific constants need to be re-verified using api-pitfalls §12's method (makepy type library/record macro).
Tested / Untested Boundaries
- ✅ Extrude, revolve, spline, rectangle/circle/arc, cut, fillet, chamfer, assembly add component, GV/equations, STL/STEP/IGS/PNG export, mesh import, geometry assertions
- ❌ Sweep/loft/pattern/mate not tested (theoretically same approach, check signatures via type library or macro record first)