solidworks_mcp.adapters.solidworks.dimension_layout¶
solidworks_mcp.adapters.solidworks.dimension_layout ¶
Overlap-free placement of drawing dimensions (pure geometry, no COM).
Rule enforced: nothing on the sheet may overlap. A dimension's text box must not intersect another dimension's text, be crossed by another dimension's lines, sit on any view's geometry, touch an obstacle (title block, view captions, note blocks) or leave the working area of the frame. A dimension's lines must not cross another view, and its extension lines must not run across its own view to the far side.
InsertModelAnnotations3 places imported dimensions where they sit in the
model sketch, which on a drawing view lands them inside the view outline, on
top of the part and of each other (measured live on SW 2025).
:func:plan_layout moves each dimension outside its view, following the
A3 drafting standard
(drawing_standard.py): horizontal dimensions in rows above/below the part, rows 7 mm
apart; vertical dimensions in columns left/right, 9 mm apart; the first row
8 mm from the outline, on the side its extension lines start from. Others
(diameters, radii, angles) keep their leader on the feature and step their
text outward from it. Rows are filled shortest span first, so the extension lines of longer
outer dimensions clear the inner text. Every candidate position is checked
against everything already placed; the first free one wins.
All coordinates are sheet metres; boxes and segments are (x0, y0, x1, y1).
Attributes¶
Classes¶
DimensionGeometry
dataclass
¶
DimensionGeometry(key: str, view: str, text_box: Box, position: tuple[float, float], lines: list[Segment] = list(), orientation: str | None = None, span: float = 0.0)
One drawing dimension as read from IAnnotation::GetDisplayData.
Attributes:
| Name | Type | Description |
|---|---|---|
key |
str
|
Stable identifier (view name + index). |
view |
str
|
Owning view name. |
text_box |
Box
|
Current text box on the sheet. |
position |
tuple[float, float]
|
|
lines |
list[Segment]
|
Every line segment of the dimension (extension + dimension lines). |
orientation |
str | None
|
|
span |
float
|
Distance between the extension lines (0 when unknown). |
Functions:¶
_candidates ¶
Ordered (side, dx, dy) moves to try for one dimension.
A linear dimension only goes to the side its extension lines start from; on the far side they would cross its own view. Rows and columns are tried from the innermost out, so dimensions that do not touch share a row; the caller's checks push one outward when its text or lines would collide.
Source code in src/solidworks_mcp/adapters/solidworks/dimension_layout.py
_grown ¶
_inside_candidates ¶
_inside_candidates(dim: DimensionGeometry, outline: Box, anchor: tuple[float, float]) -> list[tuple[str, float, float]]
Moves putting a leader's text inside its view, toward the view's centre.
anchor is where the leader meets the part (:func:leader_anchor).
Source code in src/solidworks_mcp/adapters/solidworks/dimension_layout.py
_leader_inside ¶
A leader whose text sits clear inside its own view (see :func:clear_inside).
Source code in src/solidworks_mcp/adapters/solidworks/dimension_layout.py
_leader_to ¶
The leader from anchor to the nearest point of the text box.
Source code in src/solidworks_mcp/adapters/solidworks/dimension_layout.py
_projected_segments ¶
Approximate a moved dimension's new dimension and extension lines.
The extension lines still start where they did on the part and now reach the moved dimension line. A leader stays fixed to the feature it points at and runs from there to the moved text; moving it with the text, as before, hid a diameter leader drawn across the part and two neighbouring dimensions (measured live on SW 2026).
Source code in src/solidworks_mcp/adapters/solidworks/dimension_layout.py
_side_order ¶
The sides to try for a linear dimension, best first.
Each extension line starts on the side nearer its origin. When they start on both halves of the view, both sides are possible and both cross the view; the side where the extension lines cross less of it comes first (Added in 2.2.0).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
origins
|
list[float]
|
Where the extension lines start, along the measuring axis. |
required |
low
|
float
|
The view's low edge on that axis (bottom or left). |
required |
high
|
float
|
The view's high edge (top or right). |
required |
near
|
str
|
The side name past |
required |
far
|
str
|
The side name past |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
list[str]: One or two side names, the one to try first first. |
Example
_side_order([0.356, 0.336], 0.3266, 0.3634, "above", "below") ['above', 'below']
Source code in src/solidworks_mcp/adapters/solidworks/dimension_layout.py
_starts_on_both_halves ¶
Whether the extension lines start on both halves of the view.
Seen live on SW 2026 (2.2.0): a section's auto-dimension can attach one extension line to a point in the top half and the other to a point in the bottom half. Then the dimension crosses its view on whichever side it goes, so that crossing is the drawing's, not a misplaced dimension.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dim
|
DimensionGeometry
|
A linear dimension. |
required |
outline
|
Box
|
Its view's outline. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
|
bool
|
and another above it (left and right for a vertical dimension). |
Source code in src/solidworks_mcp/adapters/solidworks/dimension_layout.py
attach_boxes ¶
Grow each dimension's text box by what hangs off it, such as a GD&T frame.
A frame attached to a dimension moves with it, so its box is given relative to the dimension's position and counts as part of its text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dims
|
list[DimensionGeometry]
|
Dimensions as read; updated in place. |
required |
attached
|
dict[str, Box]
|
Dimension key -> box relative to that dimension's position. |
required |
Source code in src/solidworks_mcp/adapters/solidworks/dimension_layout.py
box_overlap ¶
Return True when two boxes intersect (after growing each by pad).
Source code in src/solidworks_mcp/adapters/solidworks/dimension_layout.py
classify ¶
Work out orientation, span and extension-line coordinates.
SolidWorks returns a linear dimension's two extension lines first. Both vertical means a horizontal dimension (their x values are the span ends); both horizontal means a vertical one.
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
tuple[str | None, float, list[float]]
|
orientation, span, and the two extension-line coordinates. |
Source code in src/solidworks_mcp/adapters/solidworks/dimension_layout.py
clear_inside ¶
True when box sits well inside outline and clear of points.
Source code in src/solidworks_mcp/adapters/solidworks/dimension_layout.py
crosses_other_view ¶
Return the first other view any of lines runs across or along.
A dimension's extension lines start on its own view's geometry, so its own
outline is exempt. On any other view, more than :data:MIN_CROSSING of a
line inside that outline (grown by :data:EDGE_TOLERANCE, so a line lying
along its edge counts) is a crossing; a line ending at the edge is not.
Measured live on SW 2026: a front view's height dimension parked beyond
the side view drew its extension lines along the side view's top and
bottom edges, straight across it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lines
|
list[Segment]
|
The dimension's line segments. |
required |
own_view
|
str
|
The view the dimension belongs to. |
required |
outlines
|
dict[str, Box]
|
View name -> view outline. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
str | None: The crossed view's name, or |
Source code in src/solidworks_mcp/adapters/solidworks/dimension_layout.py
crosses_own_view ¶
True when an extension line runs across its own view to the far side and the dimension had a side where it would not.
Measured live on SW 2026: a height dimension moved from the left of the
top view to its right drew both extension lines straight across the view.
When the extension lines start on both halves of the view
(:func:_starts_on_both_halves), every side crosses it, so the crossing
isn't reported; the planner puts such a dimension on the side where the
lines cross least (:func:_side_order). Fixed in 2.2.0: before, that
case was an overlap no pass could clear.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dim
|
DimensionGeometry
|
The dimension. |
required |
outline
|
Box
|
Its view's outline. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
|
Source code in src/solidworks_mcp/adapters/solidworks/dimension_layout.py
describe_conflicts ¶
describe_conflicts(dims: list[DimensionGeometry], outlines: dict[str, Box], overlaps: list[dict[str, str]]) -> list[dict[str, Any]]
The geometry behind each dimension that is still in conflict, in mm.
arrange_dimensions reports this with an error, so a failure can be
diagnosed from the reply alone: which way the dimension runs, where its
lines and text are, where its extension lines start, and its view's
outline. Added in 2.2.0, to diagnose a section dimension whose extension
line crossed its own view in some runs only.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dims
|
list[DimensionGeometry]
|
Every dimension, as read back after arranging. |
required |
outlines
|
dict[str, Box]
|
View name -> outline. |
required |
overlaps
|
list[dict[str, str]]
|
:func: |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
list[dict[str, Any]]: One entry per dimension named in |
list[dict[str, Any]]
|
in the order first named: |
list[dict[str, Any]]
|
|
list[dict[str, Any]]
|
|
Example
describe_conflicts(dims, outlines, find_overlaps(dims, outlines)) # doctest: +SKIP [{'key': 'Section View A-A#0', 'orientation': 'h', ...}]
Source code in src/solidworks_mcp/adapters/solidworks/dimension_layout.py
extension_origins ¶
Where each extension line starts on the part, across the dimension.
An extension line runs from the part to just past the dimension line, so its start is the end farther from the text: a y for a horizontal dimension, an x for a vertical one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dim
|
DimensionGeometry
|
The dimension. |
required |
Returns:
| Type | Description |
|---|---|
list[float]
|
list[float]: One coordinate per extension line; empty for a leader. |
Source code in src/solidworks_mcp/adapters/solidworks/dimension_layout.py
feature_points ¶
feature_points(dims: list[DimensionGeometry], view: str, outline: Box, skip: str | None = None) -> list[tuple[float, float]]
Points inside a view where its dimensions start: its features.
Every line end of the view's dimensions (but skip's) that lies inside
the outline: extension lines start on holes and edges, leaders on the
feature they point at.
Source code in src/solidworks_mcp/adapters/solidworks/dimension_layout.py
find_annotation_overlaps ¶
find_annotation_overlaps(notes: dict[str, Box], dims: list[DimensionGeometry], outlines: dict[str, Box], sheet: Box | None = None, obstacles: dict[str, Box] | None = None) -> list[dict[str, str]]
Check sheet notes and captions against everything else on the sheet.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
notes
|
dict[str, Box]
|
Label -> measured text box of each note or caption. |
required |
dims
|
list[DimensionGeometry]
|
Dimensions with their real geometry. |
required |
outlines
|
dict[str, Box]
|
View outlines. |
required |
sheet
|
Box | None
|
Working area of the frame. |
None
|
obstacles
|
dict[str, Box] | None
|
Named boxes notes may not touch (title block). |
None
|
Returns:
| Type | Description |
|---|---|
list[dict[str, str]]
|
list[dict[str, str]]: |
list[dict[str, str]]
|
( |
Source code in src/solidworks_mcp/adapters/solidworks/dimension_layout.py
find_overlaps ¶
find_overlaps(dims: list[DimensionGeometry], outlines: dict[str, Box], sheet: Box | None = None, obstacles: dict[str, Box] | None = None) -> list[dict[str, str]]
List every rule violation among dimensions as they currently sit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dims
|
list[DimensionGeometry]
|
Dimensions with their real (read-back) geometry. |
required |
outlines
|
dict[str, Box]
|
View name -> view outline box. |
required |
sheet
|
Box | None
|
Working area of the frame, when known. |
None
|
obstacles
|
dict[str, Box] | None
|
Named boxes nothing may touch (title block, captions, notes). |
None
|
Returns:
| Type | Description |
|---|---|
list[dict[str, str]]
|
list[dict[str, str]]: |
Source code in src/solidworks_mcp/adapters/solidworks/dimension_layout.py
581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 | |
inside ¶
Return True when box lies entirely within area.
Source code in src/solidworks_mcp/adapters/solidworks/dimension_layout.py
leader_anchor ¶
Where a leader (diameter, radius) meets the part: the line end farthest from the text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dim
|
DimensionGeometry
|
The dimension. |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, float] | None
|
tuple[float, float] | None: The anchor, or |
Source code in src/solidworks_mcp/adapters/solidworks/dimension_layout.py
length_inside ¶
Length of the part of a segment that lies inside a box (Liang-Barsky).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seg
|
Segment
|
The segment. |
required |
box
|
Box
|
The box. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
0.0 when the segment misses the box. |
Source code in src/solidworks_mcp/adapters/solidworks/dimension_layout.py
plan_layout ¶
plan_layout(dims: list[DimensionGeometry], outlines: dict[str, Box], sheet: Box | None = None, obstacles: dict[str, Box] | None = None, fixed: set[str] | None = None, inside_first: set[str] | None = None) -> tuple[dict[str, tuple[float, float]], list[str]]
Choose a move for every dimension so the overlap rule holds.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dims
|
list[DimensionGeometry]
|
Dimensions with their current geometry. |
required |
outlines
|
dict[str, Box]
|
View name -> view outline. |
required |
sheet
|
Box | None
|
Working area of the frame, when known. |
None
|
obstacles
|
dict[str, Box] | None
|
Named boxes nothing may touch. |
None
|
fixed
|
set[str] | None
|
Keys of dimensions that stay where they are: their real text and lines are obstacles. Used to re-plan only what a first pass left in conflict. |
None
|
inside_first
|
set[str] | None
|
Leader dimensions to try inside their own view first,
near the feature (a hole note with its GD&T frame), before
outside it; see :func: |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
dict[str, tuple[float, float]]
|
|
list[str]
|
(left in place and reported by the caller's final check). |
Source code in src/solidworks_mcp/adapters/solidworks/dimension_layout.py
719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 | |
segment_hits_box ¶
Liang-Barsky clip: True when the segment passes through the box.
Source code in src/solidworks_mcp/adapters/solidworks/dimension_layout.py
shift_box ¶
shown_length ¶
Characters a dimension's text shows: each SolidWorks code is one symbol.
IDisplayData::GetTextAtIndex returns codes such as <MOD-DIAM>
for the Ø sign; counted as typed, they make the text look three times
wider than it is drawn.
Source code in src/solidworks_mcp/adapters/solidworks/dimension_layout.py
text_box ¶
Sheet box of a text run anchored at its lower-left corner and turned.
IDisplayData gives each text's lower-left corner, length, height and
angle. A vertical dimension's text is turned 90 degrees, so it runs up the
sheet from that corner and lies to its left (measured live on SW 2026).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
float
|
Lower-left corner x. |
required |
y
|
float
|
Lower-left corner y. |
required |
width
|
float
|
Text length along its baseline. |
required |
height
|
float
|
Text height. |
required |
angle
|
float
|
Baseline angle in radians, counter-clockwise. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Box |
Box
|
The axis-aligned box around the turned text. |