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 ¶
Moves putting a leader's text inside its view, toward the view's centre.
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
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.
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.
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
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
453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 | |
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
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 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 | |
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. |