Convert DWG and DXF drawings into QElectroTech elements (.elmt) that are ready to use:
symbols you can wire straight away, cabinet front views at a true scale, and a whole
manufacturer library in one batch run.
Python 3.9+, standard library only. DWG input uses LibreDWG's dwg2dxf when it is installed.
dxf2elmt, the converter QElectroTech's element editor uses, turns DXF geometry into an element. dwg2qet adds what a manufacturer CAD library needs before it is usable in a schematic:
| dxf2elmt | dwg2qet | |
|---|---|---|
| DXF geometry (lines, polylines with bulges, arcs, circles, ellipses, splines, texts, blocks, hatches) | ✓ | ✓ |
| DWG input | – | ✓ (LibreDWG) |
| Terminals: found on the drawing, named from the drawing's own labels (1, 2, A1, A2, 13, 14, L, N …) | – | ✓ |
| 10 px grid: scaled and snapped so wires come out straight | – | ✓ |
Label and comment fields (%{label}, %{comment}) |
– | ✓ |
| Element information for the bill of materials: manufacturer, article number, EAN, current rating … | – | ✓ |
Width / height / depth in mm (QElectroTech's own width, height, depth fields) for 2D panel layouts and 3D, also read from the manufacturer's STEP model |
– | ✓ |
Cabinet front view (thumbnail) at a fixed px per mm |
– | ✓ |
| Batch: a CSV manifest into a categorised collection with translated folder names | – | ✓ |
SVG preview of each element, qelectrotech --check-elements validation |
– | ✓ |
git clone https://github.com/DP5000/dwg2qet && cd dwg2qet
python3 dwg2qet.py --help
# DWG files: brew install libredwg (Debian/Ubuntu: apt install libredwg-tools)# schematic symbol: terminals on the 10 px grid, label + comment fields, SVG preview
python3 dwg2qet.py breaker.dwg -o breaker.elmt --preview \
--name en="Circuit breaker C16 1P" --name sl="Odklopnik C16 1p" \
--info manufacturer=ACME --info manufacturer_reference=MCB-C16-1P --info current_rating="16 A"
# cabinet front view, 2 px = 1 mm, dimensions for 3D
python3 dwg2qet.py breaker_front.dxf --mode thumbnail --px-per-mm 2 \
--info width=17.7 --info height=80 --info depth=74.9 --exclude-layer "dim.*"
# front view of a drive, width / height / depth taken from its STEP 3D model
python3 dwg2qet.py MDX61B0015_front.dxf --mode thumbnail --step MDX61B0015.stp \
--info manufacturer=SEW-EURODRIVE --info manufacturer_reference=MDX61B0015-5A3-4-00
# a whole library from a manifest, then let QElectroTech check every file
python3 dwg2qet.py --batch manifest.csv --out-dir ~/qet/elements/ACME --checkThe element editor's File > Import DXF runs <data folder>/binary/dxf2elmt <file> -v and opens the element it prints.
dwg2qet speaks the same interface (-v / --stdout), so a two-line wrapper makes the editor import symbols with terminals:
# macOS: ~/Library/Application Support/QElectroTech/QElectroTech/binary/dxf2elmt (chmod +x)
# Linux: ~/.local/share/QElectroTech/QElectroTech/binary/dxf2elmt
#!/bin/sh
exec python3 /path/to/dwg2qet.py "$@"One row per element. Columns: source, output (relative to --out-dir), optional mode
(symbol / thumbnail), layer, exclude_layer (regex, |-separated), link_type, step (STEP model),
name_<lang>, info_<key>, kind_<key>, category_<lang> (name of the output folder), ident (see below).
See examples/manifest.csv.
| option | |
|---|---|
--mode symbol |
find terminals, snap to the grid, add label/comment (default) |
--mode thumbnail |
front view at --px-per-mm (default 2), no terminals |
--layer, --exclude-layer |
regex layer filters (dimension and attribute layers are usually excluded) |
--terminal x,y |
force terminals (drawing units) when the drawing has no leads |
--pitch |
px between poles (default 20, or 10 when the symbol would get too big) |
--target |
rough symbol height in px for single-pole symbols (default 60) |
--thin-layer |
draw these layers with a thin pen (details of a front view) |
--step |
STEP (AP203/AP214) 3D model of the part: width, height and depth in mm come from it, the file name goes to notes |
--json |
print the conversion report (terminals, size, notes) |
--ident |
identity for the deterministic uuids (default: input file name, mode and layer filters) |
The element and every terminal and text field get a uuid5, built from the drawing's file name (not its
folder), the mode, the layer filters and, in a batch, the output path of the row; terminals add their name
(and their occurrence when two share a name). Making a collection again therefore gives the same uuids, and
the projects that already use an element keep their wires. When a drawing is renamed, keep its uuids with
--ident (or an ident column in the batch manifest) set to the old identity.
- A lead is a straight line end that touches nothing else.
- It is a terminal when it sits on the outline of the drawing and points outwards. That covers a breaker fed from the top and the bottom, and the poles of a 4-pole switch.
- A lead inside the drawing also counts when nothing lies beyond its end and it carries a label of its own that no outline terminal already uses. That covers the A1/A2 coil next to the main contacts.
- Short ticks and marks that sit next to the main leads (trip mechanisms, actuators) are left out.
- Symbols drawn without a lead (lamps, sockets) get one supply terminal on top. Long strips stay
drawings (
thumbnail). - Unnamed terminals are numbered, and repeated names get a prime (
N,N'), because QElectroTech rejects duplicates.
On a manufacturer library of 1,333 schematic symbols and 8,675 front views, every element loads in
QElectroTech 0.200 (--check-elements: 0 failures). The terminals of contactors, auxiliary blocks,
RCDs and breakers match the drawings. Vendor CAD data is not part of this repository. Convert your
own, within its licence.
Drives, PLCs and inverters have no schematic symbol in their DXF. Their manual has a terminal table
instead. terminals2qet.py turns that table into the symbol and, in the same run, the cabinet front view
(dwg2qet) with width / height / depth from the manufacturer's STEP model:
# the symbol
python3 terminals2qet.py examples/terminals/sew_movidrive_b_MDX61B0015-5A3-4-00.json \
-o SEW/schematic/MDX61B0015-5A3-4-00.elmt --check
# the whole device, once SEW's DXF front view and STEP model sit next to the JSON
python3 terminals2qet.py examples/terminals/sew_movidrive_b_MDX61B0015-5A3-4-00.json \
-o SEW/schematic/MDX61B0015-5A3-4-00.elmt --front-out SEW/cabinet/MDX61B0015-5A3-4-00.elmt --check- every terminal on the 10 px grid, named as in the manual (
X13:1), its designation inside the box (DI00), its number outside and its function next to it; - each block framed like a terminal strip; mains at the top, motor and brake at the bottom, control blocks on the side the table gives;
- label and comment fields, element information for the bill of materials, the source of the table;
- the same uuids each time a device is drawn again, so the projects that use it keep their wires.
The table is JSON (blocks with [terminal, name, function] rows, see
examples/terminals/) or CSV (block, terminal, name, side, function).
An AI assistant can copy it from the manual; the drawing itself is always the program's.
The two SEW examples come from SEW's public documentation (MOVITRAC B system manual 01/2024, MOVIDRIVE B
compact operating instructions 11/2017). The front views and STEP models referenced by front_view are SEW's
own CAD downloads (SEW Online Support > CAD data). They are not part of this repository.
collections/ holds element libraries generated with these tools: 288 PV and storage devices
(Sigenergy, Victron, SolarEdge, GoodWe, Dyness, Pylontech, FoxESS, Sungrow, AndSolar, PV modules …), each with
a symbol that has all its terminals and a front view in scale, plus the two SEW-EURODRIVE drives. Every element
names the manufacturer document it was made from. CC-BY 3.0, see collections/README.md.
python3 -m unittest discover -s testsMIT. See LICENSE. QElectroTech is © The QElectroTech Team (GPL-2.0+). dwg2qet only writes files in its format. Thanks to the QElectroTech, LibreDWG and dxf2elmt projects.
Pretvornik risb DWG in DXF v elemente QElectroTech. Simbol dobi priključke na mreži 10 px s
pravimi imeni (1, 2, A1, A2 …), polja za oznako in podatke ter podatke za kosovnico in mere za
2D in 3D. Pogled od spredaj je v merilu (2 px = 1 mm). Iz manifesta CSV pretvori celotno
knjižnico proizvajalca. terminals2qet.py iz tabele priključkov v priročniku nariše simbol
zahtevne naprave (pretvornik, PLC, razsmernik), skupaj s pogledom za omaro in merami iz STEP. V mapi collections/ so gotove zbirke: 288 naprav za PV in hranilnike ter SEW (CC-BY 3.0). Avtor: David Podlesnik (Elektro David Podlesnik s.p.). Licenca MIT.

