solidworks_mcp.adapters.solidworks.hole_library¶
solidworks_mcp.adapters.solidworks.hole_library ¶
The Hole Wizard library: standards, hole types and sizes, read from a file.
SolidWorks keeps the Hole Wizard's hole types and sizes in the Toolbox
library, swbrowser.sldedb, a SQLite file. This module reads it read-only
(no COM, no SolidWorks needed) so list_hole_sizes can show what exists and
create_hole can refuse a size that doesn't, before asking SolidWorks.
Per standard prefix (ISO, AI = ANSI inch, AM = ANSI metric,
DIN, JIS) the library has two type tables, <P>_Type_Holes (simple
and tapped holes) and <P>_TYPE_BS (bolts and screws, which counterbores
and countersinks are sized for). Each row names a hole type, its
HoleWizard5 fastener index (SWconst_Enum_Value), the size table it
reads (DataTable: +DATA_HW_DrillSizes is <P>_DATA_HW_DrillSizes)
and a bit mask of the hole kinds it serves (ValidHoleTypes). Size tables
have SIZE, enabled and dimension columns that vary by table.
:class:HoleLibrary holds the rules; :class:SqliteHoleLibrary reads the
file and :class:MemoryHoleLibrary serves the mock adapter and tests.
Attributes¶
DEFAULT_FASTENERS
module-attribute
¶
DEFAULT_FASTENERS: dict[tuple[str, str], tuple[str, int]] = {('drill', 'iso'): ('Drill sizes', 143), ('clearance', 'iso'): ('Screw Clearances', 144), ('counterbore', 'iso'): ('Cap (4762)', 139), ('countersink', 'iso'): ('CTSK Flat (7046-1)', 141), ('tapped', 'iso'): ('Tapped hole', 147), ('drill', 'ansi_inch'): ('All Drill sizes', 18), ('clearance', 'ansi_inch'): ('Screw Clearances', 22), ('counterbore', 'ansi_inch'): ('Cap', 9), ('countersink', 'ansi_inch'): ('Flat Head (82)', 15), ('tapped', 'ansi_inch'): ('Tapped hole', 27), ('drill', 'ansi_metric'): ('Drill sizes', 39), ('clearance', 'ansi_metric'): ('Screw Clearances', 40), ('counterbore', 'ansi_metric'): ('Cap (B18.3.1M)', 33), ('countersink', 'ansi_metric'): ('Flat Head (B18.6.7M)', 36), ('tapped', 'ansi_metric'): ('Tapped hole', 43), ('drill', 'din'): ('Drill sizes', 72), ('clearance', 'din'): ('Screw Clearances', 73), ('counterbore', 'din'): ('Cap (912)', 67), ('countersink', 'din'): ('CTSK Flat (EN ISO 7046-1)', 69), ('tapped', 'din'): ('Tapped hole', 76), ('drill', 'jis'): ('Drill sizes', 160), ('clearance', 'jis'): ('Screw Clearances', 161), ('counterbore', 'jis'): ('Cap (1176)', 156), ('countersink', 'jis'): ('Flat CTSK (1111p2)', 158), ('tapped', 'jis'): ('Tapped hole', 164)}
HOLE_KIND_BITS
module-attribute
¶
STANDARD_PREFIXES
module-attribute
¶
STANDARD_PREFIXES: dict[str, str] = {'iso': 'ISO', 'ansi_inch': 'AI', 'ansi_metric': 'AM', 'din': 'DIN', 'jis': 'JIS'}
_NOT_DIMENSIONS
module-attribute
¶
Classes¶
HoleLibrary ¶
Bases: ABC
The rules over a library's rows; subclasses supply the rows.
A row of a type table is {"name", "code", "valid", "enabled", "table"};
a size row is {"size", "enabled", "dimensions"}.
Methods:¶
dimensions ¶
One size's dimensions as the library stores them.
Raises:
| Type | Description |
|---|---|
HoleSizeError
|
When the type has no such size. |
Source code in src/solidworks_mcp/adapters/solidworks/hole_library.py
find_type ¶
The hole type named fastener (case and spacing ignored).
Raises:
| Type | Description |
|---|---|
HoleSizeError
|
When the standard has no such type for the kind. |
Source code in src/solidworks_mcp/adapters/solidworks/hole_library.py
hole_types ¶
The enabled Hole Wizard types serving hole_type, library order.
A row whose index is 0 or -1 isn't a Hole Wizard type. Names can repeat (JIS); the first row with a real index wins.
Source code in src/solidworks_mcp/adapters/solidworks/hole_library.py
match_size ¶
The table's spelling of size.
Exact (case and spaces ignored) first; then, for a bare diameter, the
size with the same number (6 -> Ø6.0); then a size with its
pitch (M6x1.0) as the table's row for M6 when that row's pitch
is the one given (the ISO tables list coarse threads without it).
Raises:
| Type | Description |
|---|---|
HoleSizeError
|
When the type has no such size; names the nearest. |
Source code in src/solidworks_mcp/adapters/solidworks/hole_library.py
resolve ¶
The hole type, index and size create_hole asks SolidWorks for.
With no fastener, a simple hole uses "Screw Clearances" for a
screw size and the drill table for a bare diameter; the other kinds
use :data:DEFAULT_FASTENERS.
Raises:
| Type | Description |
|---|---|
HoleSizeError
|
For an unknown hole type or size. |
Source code in src/solidworks_mcp/adapters/solidworks/hole_library.py
size_rows
abstractmethod
¶
sizes ¶
The enabled sizes of a hole type, in the table's order.
Source code in src/solidworks_mcp/adapters/solidworks/hole_library.py
type_rows
abstractmethod
¶
HoleLibraryError ¶
Bases: Exception
The library can't be found or read; the message says where it looked.
HoleSizeError ¶
Bases: InputRefused
A hole type or size the library doesn't have; names the nearest ones.
HoleType
dataclass
¶
One Hole Wizard hole type of a standard.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The library's name for it, e.g. "Screw Clearances". |
code |
int
|
Its |
table |
str
|
The size table it reads, without the prefix's |
InputRefused ¶
Bases: ValueError
The adapter checked an input against the document and refused it.
An expected answer, not a fault: a section line that misses its view, a
point with nothing to dimension. It is logged as one line, without a
traceback, and the tools classify it as invalid_input.
MemoryHoleLibrary ¶
MemoryHoleLibrary(types: dict[str, list[dict[str, Any]]], sizes: dict[tuple[str, str], list[dict[str, Any]]])
Bases: HoleLibrary
A library held in memory: the mock adapter's and the tests'.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
types
|
dict[str, list[dict[str, Any]]]
|
|
required |
sizes
|
dict[tuple[str, str], list[dict[str, Any]]]
|
|
required |
Source code in src/solidworks_mcp/adapters/solidworks/hole_library.py
ResolvedHole
dataclass
¶
What create_hole asks SolidWorks for.
Attributes:
| Name | Type | Description |
|---|---|---|
fastener |
str
|
The hole type's name. |
code |
int
|
Its |
size |
str
|
The size exactly as the library writes it. |
warning |
str | None
|
Set when the size couldn't be checked. |
SqliteHoleLibrary ¶
Bases: HoleLibrary
The installed library, read read-only and immutable.
Table names come from the library's own rows; each is checked against
the file's own table list and reflected, never taken from a caller, and
rows are read with the reflected table's select(): no SQL is built as
text.
Rows are read once per table, and the file is closed after each read, so
SolidWorks (or Toolbox Settings) can always replace it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
The |
required |
Source code in src/solidworks_mcp/adapters/solidworks/hole_library.py
Methods:¶
size_rows ¶
One size table's rows, its dimension columns as numbers.
Source code in src/solidworks_mcp/adapters/solidworks/hole_library.py
type_rows ¶
Both type tables of a standard, holes first.
Source code in src/solidworks_mcp/adapters/solidworks/hole_library.py
Functions:¶
_bare_diameter ¶
The diameter a bare drill size gives (6, Ø6, 6.0 mm).
Source code in src/solidworks_mcp/adapters/solidworks/hole_library.py
_fold ¶
_language_files ¶
<lang>/<language>/swbrowser.sldedb for each language, English first.
Source code in src/solidworks_mcp/adapters/solidworks/hole_library.py
_metric ¶
M<n> rows with a diameter and one more column.
Source code in src/solidworks_mcp/adapters/solidworks/hole_library.py
_number ¶
A stored dimension as a float when it reads as one.
_registry_subkeys ¶
A registry key's subkey names; none off Windows or when it's missing.
Source code in src/solidworks_mcp/adapters/solidworks/hole_library.py
_registry_value ¶
One registry string; None off Windows or when it's missing.
Source code in src/solidworks_mcp/adapters/solidworks/hole_library.py
_registry_years ¶
Installed SOLIDWORKS <year> registry keys, newest first.
Source code in src/solidworks_mcp/adapters/solidworks/hole_library.py
_sizes ¶
Size rows from (size, dimensions) pairs, all enabled.
candidate_paths ¶
Where the library may be, first hit wins (design decision 3).
The SOLIDWORKS_MCP_HOLE_LIBRARY setting; then, for each installed
SolidWorks year (newest first), the Toolbox data folder from the
registry (HKCU, then HKLM) with each lang folder, English first;
then the install folder's template.
Source code in src/solidworks_mcp/adapters/solidworks/hole_library.py
default_fastener ¶
The default hole type's name and index for a kind and size.
Source code in src/solidworks_mcp/adapters/solidworks/hole_library.py
describe ¶
describe(library: HoleLibrary, standard: str, hole_type: str, fastener: str | None = None, size: str | None = None) -> dict[str, Any]
What list_hole_sizes returns.
No size: the hole types of the kind (only fastener's when given),
each with its enabled sizes. With size: that size's dimensions, in
the hole type fastener names or the default one for the kind.
Raises:
| Type | Description |
|---|---|
HoleSizeError
|
For an unknown hole type or size. |
Source code in src/solidworks_mcp/adapters/solidworks/hole_library.py
find_library ¶
The installed library.
Raises:
| Type | Description |
|---|---|
HoleLibraryError
|
Naming every place looked and the setting. |
Source code in src/solidworks_mcp/adapters/solidworks/hole_library.py
is_screw_size ¶
Whether a simple hole's size names a screw (clearance), not a drill.
M6 (metric), #10 and fractions such as 1/4 (inch) name
screws; a bare diameter (6, Ø6, 6 mm) names a drill.
Source code in src/solidworks_mcp/adapters/solidworks/hole_library.py
load ¶
The library at path, one per path and modification time.
Source code in src/solidworks_mcp/adapters/solidworks/hole_library.py
nearest_sizes ¶
Up to five sizes closest in number to size, in table order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sizes
|
list[str]
|
The table's sizes, in its order. |
required |
size
|
str
|
The size asked for. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
The nearest sizes; the first five when |
Source code in src/solidworks_mcp/adapters/solidworks/hole_library.py
sample_library ¶
A few real ISO and ANSI inch hole types and sizes (SolidWorks 2026).
The mock adapter's library: the default hole types of each kind, with their dimensions copied from the installed library.
Source code in src/solidworks_mcp/adapters/solidworks/hole_library.py
663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 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 | |
size_number ¶
The number in a size, for ordering nearest sizes.
M6 -> 6, Ø6.6 -> 6.6, #10 -> 10, 1/4 -> 0.25,
1-1/2 -> 1.5, M6x1.0 -> 6.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
str
|
A size as written in a table or by a caller. |
required |
Returns:
| Type | Description |
|---|---|
float | None
|
The number, or |
Source code in src/solidworks_mcp/adapters/solidworks/hole_library.py
unchecked ¶
unchecked(standard: str, hole_type: str, size: str, fastener: str | None, reason: str) -> ResolvedHole
The defaults to try when the library can't be read, with a warning.
A named fastener is used only when it is the default for the kind,
as its index is otherwise unknown.
Raises:
| Type | Description |
|---|---|
HoleSizeError
|
For a |