Repository navigation
Equations and global variables drive a part's dimensions - #250
Merged
Merged
Conversation
list_equations, set_equation and delete_equation (queue item 29). One
value ("Width" = 60mm) can drive several dimensions ("D1@Sketch1" =
"Width" / 2). set_equation adds or changes one, in every configuration
by default, solves and rebuilds, and gives the new value; an expression
SolidWorks can't use fails as equation_refused and changes nothing.
143 tools.
set_equation used Add3, which returns -1 from Python for every input. Live probes found what works on SolidWorks 2026: Add2 adds; writing the Equation(i) property changes an equation in every configuration; the "this configuration" call (option 1, no names) sets one configuration, so named configurations are set one at a time and the active one is shown again. Every call given an array of configuration names fails. The reply now gives each named configuration's value. The demo: one global variable, Size, drives a 13 mm combination wrench (open end at 15 degrees, 12-point box end, flat handle) through 19 equations; Size = 19mm regrows it, an 8 mm size lives in its own configuration, and a bad expression is refused. Passed live and recorded for the demos page and the README. Building it needed: - create_cut_extrude: a Blind cut with both_directions is now mid-plane (it cut one way only). - add_polygon takes an angle; a diameter dimension on a polygon sizes it across flats. COM pitfalls 36-38 record the findings.
… a curved jaw, neck fillets and 51CrV4 steel (local, under review)
…axis, and refuse one that isn't aligned (local, under review)
…cal, under review)
…rV4 from the DIN library (local, under review)
…d or not; the wrench's handle reads its size (local, under review)
…o along or mirror (they didn't work); the wrench letters its handle's middle at every size (local, under review)
…ocal, under review)
…Works doesn't redraw sketch text on rebuild); the wrench re-letters after each size change (local, under review)
…er (local, under review)
…s working direction first (local, under review)
… whole-mm lettering, sketches hidden one by one before framing (local, under review)
…s at the sketch origin first (local, under review)
…estored after), frames before lettering, ends on 'Equations demo done' (local, under review)
…atches what SolidWorks is doing (local, under review)
…LOG (add_sketch_text, set_sketch_text, ellipse angle and axes); recorded GIF
# Conflicts: # openspec/queue.md
# Conflicts: # docs/assets/progress/progress.json # docs/assets/progress/progress.svg # docs/assets/progress/tool-list-size.md # openspec/queue.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Equations and global variables (queue item 29)
Equations and global variables are how a SolidWorks part becomes parametric: one value drives several dimensions, so changing it resizes the part consistently. The server had nothing for them. This adds three tools for equations and two for sketch text (145 in all):
list_equationsname,expression,kind(global_variable,dimension,other) and its solvedvalueset_equationname, or changes the one there is; solves and rebuilds; replies with the value and whether it wasaddedorchangeddelete_equationadd_sketch_textcenter_atcentres it on a point. The text can show a custom property ($PRP:"Name")set_sketch_textname(Width, or a dimension such asD1@Sketch1) andexpression(60mm,"Width" / 2); the server writes"Width" = 60mm, so the quoting is always right.allby default, as SolidWorks' Equations dialog does;thisor a list of names, checked likeset_dimension's. Named configurations are set one at a time, and the reply'svaluesgives each one's value.invalid_input). An expression SolidWorks can't use fails as the newequation_refused: an added equation is deleted again, and a changed one gets its old text back.IEquationMgrcall given an array of configuration names returns -1 from Python, soAdd2adds, writing theEquation(i)property changes an equation everywhere, and the "this configuration" call sets one configuration at a time.center_atmeasures the text's edges and moves it onto the point. SolidWorks doesn't redraw sketch text when an equation changes the part;set_sketch_textwrites it again with the sketch open, which does.The demo: one variable sizes a combination wrench
A 13 mm combination wrench modelled from photos of a real one: an open end at 15° with a curved jaw bottom, a raised 12-point box end, fillets where both heads meet the handle, and 1.8159 (51CrV4) chrome-vanadium steel. Both faces of the handle are lettered "solidworksmcp-python 13 mm", centred, with the size read from
Size. One variable drives 27 equations:Size= 19mm regrows it, and the lettering is rewritten to "19 mm".verify_modelchecks each size against the hand calculation:The GIF's caption changes as each step starts. It's on the demos page and in the README's demo table.
Building it needed these tool changes, in this PR:
create_cut_extrude: a Blind cut withboth_directionsis now mid-plane (it cut one way only).add_polygontakes anangle, and adiameterdimension on a polygon sizes it across flats.add_ellipsetakes anangle, andadd_sketch_dimensionsizes an ellipse'smajor_axisorminor_axis.pythoncom, which the Linux runners don't have.Checks
Unit tests: 4,428 pass at 100% coverage; ruff and mypy are clean; the docs build in strict mode; every link checks out.
Live, all passed 2026-11-18:
test_a_global_variable_drives_the_depth: 30 then 45 mm deep (72,000 mm³); the bad expression refused; delete keeps 45 mm.test_an_equation_in_one_configuration:Long50 mm,Default30 mm.test_a_combination_wrench_sized_by_one_variable: the demo above, recorded.