CadQuery Builder¶
The CadQuery rendering engine. Contains all shape classes, bobbin/winding builders, and export logic.
Module Overview¶
OpenMagneticsVirtualBuilder.cadquery_builder ¶
CadQuery rendering engine for OpenMagneticsVirtualBuilder.
Implements all 21 core shape families, bobbin, and winding geometry using the CadQuery Python CAD scripting library. This engine requires no system CAD installation and is suitable for headless / CI environments.
Shape classes are nested inside :class:CadQueryBuilder and follow the
EN 60205 naming convention.
Main Builder Class¶
OpenMagneticsVirtualBuilder.cadquery_builder.CadQueryBuilder ¶
Bases: BuilderBase
Builder for 3D magnetic component geometry using CadQuery.
This class creates 3D geometry for magnetic components including: - Core shapes (E, ETD, PQ, RM, toroidal, etc.) - Coil turns (concentric and toroidal winding styles) - Bobbins
Coordinate System (MAS to CadQuery mapping): - For concentric cores (E, PQ, RM, etc.): - X axis: Core depth direction (perpendicular to winding window) - Y axis: Core width direction (radial, distance from central column) - Z axis: Core height direction (along core axis, vertical) - MAS coordinates[0] (radial) -> Y position - MAS coordinates[1] (height) -> Z position
- For toroidal cores:
- Y axis: Core axis (toroid revolves around Y)
- X axis: Radial direction (negative X = inside the donut hole)
- Z axis: Tangential direction (along circumference at Y=0)
- MAS coordinates[0] (radial) -> distance from Y axis
- MAS coordinates[1] (angular) -> rotation angle around Y axis
Units: - All MAS input values are in meters - Internal geometry is built in millimeters for precision - Output is scaled back to meters before export
get_magnetic_assembly ¶
get_magnetic_assembly(project_name, assembly_data, output_path=None, save_files=True, export_files=True)
Build a magnetic assembly from core, bobbin, and winding data.
Parameters¶
project_name : str Name for the output files. assembly_data : dict Dictionary with optional keys: 'core', 'bobbin', 'windings', 'coil'. output_path : str Directory for output files. save_files : bool Whether to save intermediate files. export_files : bool Whether to export STEP/STL files.
get_svg_drawings ¶
get_svg_drawings(project_name, geometrical_description, planes=None, view_types=None, colors=None, output_path=None, save_files=True, slice_offsets=None)
Generate annotated SVG drawings for a core shape.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_name
|
Name for output files. |
required | |
geometrical_description
|
List of geometrical part descriptions. |
required | |
planes
|
List of ViewPlane values (default: all three). |
None
|
|
view_types
|
List of ViewType values (default: PROJECTION only). |
None
|
|
colors
|
Dict with 'projection_color' and 'dimension_color'. |
None
|
|
output_path
|
Directory for output files. |
None
|
|
save_files
|
Whether to write SVG files to disk. |
True
|
|
slice_offsets
|
Optional dict overriding per-plane slice offsets. |
None
|
Returns:
| Type | Description |
|---|---|
|
Dict of {key: svg_string} where key is e.g. 'xy_projection'. |
get_dxf_drawings ¶
get_dxf_drawings(project_name, geometrical_description, planes=None, view_types=None, colors=None, output_path=None, slice_offsets=None)
Generate DXF drawings for a core shape.
Returns:
| Type | Description |
|---|---|
|
Dict of {key: filepath} where key is e.g. 'xy_projection'. |
get_fcstd_sketches ¶
get_fcstd_sketches(project_name, geometrical_description, planes=None, view_types=None, output_path=None, slice_offsets=None)
Generate FreeCAD macro files (.FCMacro) for a core shape.
Returns:
| Type | Description |
|---|---|
|
Dict of {key: filepath} where key is e.g. 'xy_projection'. |
get_assembly_svg_drawings ¶
get_assembly_svg_drawings(project_name, magnetic_data, planes=None, view_types=None, colors=None, output_path=None, save_files=True, slice_offsets=None, components=None)
Generate annotated SVG drawings for an assembly or individual components.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_name
|
Name for output files. |
required | |
magnetic_data
|
MAS magnetic data dict. |
required | |
planes
|
List of ViewPlane values. |
None
|
|
view_types
|
List of ViewType values. |
None
|
|
colors
|
Color config dict. |
None
|
|
output_path
|
Directory for output files. |
None
|
|
save_files
|
Whether to write SVG files to disk. |
True
|
|
slice_offsets
|
Optional per-plane slice offsets. |
None
|
|
components
|
List of components to draw: 'assembly', 'core', 'bobbin', 'winding'. Default is ['assembly']. |
None
|
Returns:
| Type | Description |
|---|---|
|
Dict of {component_key: svg_string}. |
get_assembly_dxf_drawings ¶
get_assembly_dxf_drawings(project_name, magnetic_data, planes=None, view_types=None, colors=None, output_path=None, slice_offsets=None, components=None)
Generate DXF drawings for assembly or individual components.
Returns:
| Type | Description |
|---|---|
|
Dict of {component_key: filepath}. |
get_assembly_fcstd_sketches ¶
get_assembly_fcstd_sketches(project_name, magnetic_data, planes=None, view_types=None, output_path=None, slice_offsets=None, components=None)
Generate FreeCAD macro files for assembly or individual components.
Returns:
| Type | Description |
|---|---|
|
Dict of {component_key: filepath}. |
get_turn ¶
get_turn(turn_description: TurnDescription, wire_description: WireDescription, bobbin_description: BobbinProcessedDescription, is_toroidal: bool = False) -> cq.Workplane
Create a single turn geometry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
turn_description
|
TurnDescription
|
Turn parameters (coordinates, winding, etc.) |
required |
wire_description
|
WireDescription
|
Wire parameters (type, diameter, etc.) |
required |
bobbin_description
|
BobbinProcessedDescription
|
Bobbin parameters |
required |
is_toroidal
|
bool
|
If True, create toroidal turn; otherwise concentric turn |
False
|
Returns:
| Type | Description |
|---|---|
Workplane
|
CadQuery Workplane with the turn geometry |
get_magnetic ¶
get_magnetic(magnetic_data: dict, project_name: str = 'Magnetic', output_path: str = None, export_files: bool = True)
Build complete magnetic assembly (core + coil).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
magnetic_data
|
dict
|
MAS format magnetic data with 'core' and 'coil' keys |
required |
project_name
|
str
|
Name for the output files |
'Magnetic'
|
output_path
|
str
|
Directory for output files |
None
|
export_files
|
bool
|
Whether to export STEP/STL files |
True
|
Returns:
| Type | Description |
|---|---|
|
Tuple of (step_path, stl_path) or compound if export_files is False |
Enums¶
OpenMagneticsVirtualBuilder.cadquery_builder.WireType ¶
Bases: Enum
Wire types supported.
OpenMagneticsVirtualBuilder.cadquery_builder.ColumnShape ¶
Bases: Enum
Bobbin column shapes.
Data Classes¶
OpenMagneticsVirtualBuilder.cadquery_builder.WireDescription
dataclass
¶
Description of a wire.
OpenMagneticsVirtualBuilder.cadquery_builder.TurnDescription
dataclass
¶
Description of a single turn.
OpenMagneticsVirtualBuilder.cadquery_builder.BobbinProcessedDescription
dataclass
¶
Processed bobbin description.
Utility Functions¶
OpenMagneticsVirtualBuilder.cadquery_builder.set_tessellation_quality ¶
Configure the tessellation quality for STL export.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
segments_per_circle
|
int
|
Number of segments per full circle (default: 20). - 8-12: Very coarse, good for previews - 16-24: Medium quality, good balance - 32-48: High quality, smooth curves - 64+: Very high quality, large files |
20
|
linear_tolerance
|
float
|
Maximum chord deviation in mm (default: 0.1). Smaller values = more accurate but more polygons. |
0.1
|
Example
Coarse quality for fast previews¶
set_tessellation_quality(segments_per_circle=12)
High quality for final renders¶
set_tessellation_quality(segments_per_circle=48, linear_tolerance=0.01)
Source code in src/OpenMagneticsVirtualBuilder/cadquery_builder.py
OpenMagneticsVirtualBuilder.cadquery_builder.resolve_dimensional_value ¶
Extract numeric value from dimensional data (handles dict with 'nominal' or plain value).