| name | solidworks-auto-modeling |
| description | This skill should be used when the user asks to learn from SolidWorks .swp macro recordings, reverse-engineer SolidWorks macros, translate recorded VBA to VBScript, generate SolidWorks 2025 VBScript automation, create .SLDPRT part scripts, study assembly mates or component patterns, summarize macro files, handle Chinese Windows/SolidWorks naming and GBK encoding, or debug SolidWorks API selection, HoleWizard, pattern, sweep, revolve, extrusion, cut, fillet, chamfer, save/export, width mate, concentric mate, coincident mate, distance mate, mirror, and component insertion issues. |
SolidWorks Auto Modeling
This is an early-stage experimental skill. Basic VBScript part creation and
STEP export are verified locally, but advanced features and assembly workflows
must be treated as evidence-guided work until each operation has a repeatable
validation script. Do not present unverified APIs as guaranteed.
Core Approach
Use recorded SolidWorks .swp macros as machine-specific evidence. Extract the real VBA call signatures, selection order, selection marks, enum values, mate definitions, pattern parameters, and save/export behavior that worked on the user's SolidWorks version.
Use VBScript plus cscript.exe as the default automation path for fragile SolidWorks part modeling on Windows. Prefer this for long COM calls because VBScript late binding usually handles SolidWorks Variant parameters, long argument lists, and selection state more reliably than Python win32com in this workflow.
When an API call is unknown or unstable, do not guess. Record the operation in SolidWorks as a macro, extract the VBA source, and translate the exact call signature to VBScript. Keep enum values as integers when late binding fails to resolve names or strings.
For assembly work, treat recorded .swp macros as evidence for mate order, selected entities, component insertion, component patterns, and mirror operations. Do not trust transform-only placement as a finished assembly. Rebuild reliable assemblies with real mates, local component patterns, mirrors, and final component-count checks.
For general .swp macro learning rules, read references/swp-macro-reverse-engineering.md.
For detailed verified APIs, pitfalls, and examples, read references/solidworks-vbs-reference.md.
For a worked assembly case study, read references/solidworks-assembly-macro-lessons.md.
For current validation status, read docs/verified-capabilities.md.
For planned validation work, read docs/roadmap.md.
Part Automation Workflow
- Run
scripts/sw_preflight.py before live automation. Use --connect only
after confirming it is safe to open or reuse the user's SolidWorks session.
- Parse the requested part into parameters in SI units: lengths in meters, angles in radians.
- Choose the closest verified template or API sequence:
- Sketch: rectangles, circles, lines, centerlines, polygons, points, slots, dimensions.
- Features: boss extrude, cut extrude, revolve, sweep, fillet, chamfer.
- HoleWizard: counterbore, countersink, tapped holes.
- Patterns: linear and circular through
CreateDefinition.
- Generate a
.vbs script using a validated structure. Start from assets/minimal-part-template.vbs when no closer template exists.
- Avoid Chinese or non-ASCII paths inside the VBS save path. Save to an ASCII temporary path first; move the result afterward if the final target contains Chinese characters.
- Convert the final
.vbs file to GBK/ANSI on Chinese Windows before running it:
python scripts/convert_vbs_to_gbk.py path\to\script.vbs --in-place.
- Run with
cscript.exe //nologo path\to\script.vbs.
- Check every important return value: feature objects, selection success, save status, and output file existence.
- If SolidWorks behavior differs from expectation, use macro recording to discover the real signature and update the script.
For a quick live validation of the default VBS route, run:
python scripts/validate_sw_vbs_basic.py
It creates a throwaway block part and STEP file under C:\temp.
Macro Learning Workflow
Use this workflow for any recorded SolidWorks macro.
- Summarize each
.swp file before reading it deeply:
python scripts/swp_macro_summary.py path\to\macro.swp
The summarizer also accepts already-extracted .bas, .vba, .vb, and
.txt VBA source files when oletools is unavailable.
- Classify macro blocks:
- component insertion:
OpenDoc6, AddComponent5;
- mate creation:
CreateMateData, CreateMate;
- part features:
FeatureExtrusion2, FeatureCut4, FeatureRevolve2, HoleWizard5;
- component patterns:
CreateDefinition(swFmLocalLPattern), ModifyDefinition;
- mirror operations:
Mirror... tokens and mirrored ReferencePattern features;
- noise: view rotation, zoom, mouse wheel, repeated transient transforms.
- Extract the smallest useful seed operation first: one sketch feature, one hole, one connector mate, one component insertion, or one pattern seed.
- Convert recorded assembly behavior into real mates:
- concentric mates for aligned cylindrical axes;
- width mates for centered movable connector placement;
- coincident mates for pipe end/contact placement;
- distance mates for known offsets;
- parallel/perpendicular mates to preserve orientation.
- Use feature/component patterns and mirror features for repeated geometry instead of manually placing every repeated item.
- Verify output with return values, file existence, component counts, mate health, and visual inspection when available.
- Ask before opening or connecting to a live SolidWorks process if the user may be working in the same session.
When handling lean-pipe rack macros, use references/solidworks-assembly-macro-lessons.md only as a case study. Do not hard-code rack-specific counts or dimensions unless the user's current task is that rack.
VBScript Rules
- Use meters:
10 mm = 0.01, N mm = N / 1000.
- Use radians:
360 deg = 6.283185307179586.
- Clear selection before each selection step:
model.ClearSelection2 True.
- Select planes by name with
SelectByID2; select faces and edges by SelectByRay when possible.
- Use
CreateCenterLine for revolve axes.
- Use
Empty for Variant-array-like optional arguments where Nothing fails.
- Use integer
CreateDefinition values, such as 17 for sweep, 6 for linear pattern, 5 for circular pattern.
- Do not rely on feature tree names such as
Sketch1 or localized equivalents unless unavoidable.
- Use multiline
If ... Then ... End If; avoid colon-chained one-line control flow in VBS.
- Close documents through
swApp.CloseDoc model.GetTitle, not model.CloseDoc.
- For Chinese plane names, prefer
ChrW() construction when source encoding might corrupt strings.
Macro Reverse Engineering
Use this when a call fails, has many parameters, or is not already verified.
- In SolidWorks, choose Tools -> Macro -> Record.
- Perform the operation manually once.
- Stop and save the
.swp macro.
- Extract VBA with
python -m oletools.olevba macro.swp when oletools is available.
- Copy the exact method name, argument count, selection marks, enum values, and object order.
- Translate to VBScript:
- Replace VBA constants with integer enum values if needed.
- Replace unsupported object construction with late-bound alternatives.
- Preserve argument count exactly for long COM methods.
For large recordings, use scripts/swp_macro_summary.py first. Read the full extracted VBA only after the summary identifies useful feature, mate, pattern, mirror, or save blocks.
Output Expectations
When generating scripts, include:
- Parameter block at the top for dimensions and output paths.
- Explicit SolidWorks startup/connection,
Visible = True, new part creation, and active document check.
- Selection checks after
SelectByID2 or SelectByRay.
- Feature checks after every creation call.
- Final rebuild, save, and close.
- A short run command and any required GBK conversion note.
- A verification note covering cscript exit status, output file existence, and
any visual or export review that was performed.
If SolidWorks is not available in the current environment, still produce the script and state that it must be verified on the user's Windows SolidWorks machine.
Bundled Resources
assets/minimal-part-template.vbs - minimal verified VBS part template.
references/swp-macro-reverse-engineering.md - general .swp macro learning and translation workflow.
references/solidworks-vbs-reference.md - verified part modeling API notes.
references/solidworks-assembly-macro-lessons.md - lean-pipe rack assembly macro case study, width mate pattern, local pattern parameters, and final rack component counts.
scripts/swp_macro_summary.py - offline .swp macro summarizer for component, mate, pattern, transform, and save signals.
scripts/sw_preflight.py - local Windows/SolidWorks/cscript environment checker.
scripts/convert_vbs_to_gbk.py - UTF-8 to GBK converter for generated VBScript files on Chinese Windows.
scripts/validate_sw_vbs_basic.py - live SolidWorks VBS validation runner for part creation and STEP export.
examples/validation/basic_part_and_step_validation.vbs - throwaway live validation VBScript.