Skip to main content

pyzwcadmech Documentation

pyzwcadmech is a lightweight Python wrapper for the ZWCAD MFG COM API. It prefers dynamic COM calls first and uses the ZwmToolKit type library only as a compatibility enhancement when available.

For compatibility with recent changes, the distribution also includes the pyzwcadm package alias, while the primary package name is pyzwcadmech.

1. Requirements

  • OS: Windows
  • Software Dependency: A licensed installation of ZWCAD MFG
  • Python Environment: Python 3.x
  • Third-party Libraries: comtypes
    pip install comtypes
    
  • Type Library Note: ZwmToolKit.tlb is optional. The library first tries to connect to the registered mechanical COM interfaces. If the type library is available, it can improve compatibility for a few complex calls.

2. Directory Structure

Recommended project layout:

your_project_directory/
├── ZwmToolKit.tlb       # Optional COM type library for compatibility enhancement
├── pyzwcadmech/
│   ├── __init__.py
│   └── api.py
└── hello_mech.py

3. Quick Start

from pyzwcadmech import ZwCADMech


def main():
    mech = ZwCADMech()
    mech.open_file("")

    title = mech.get_title()
    if title:
        print("Successfully obtained the title block object!")
        for i in range(title.get_item_count()):
            label, name, value = title.get_item(i)
            print(f"{label}: {value}")

    mech.close()


if __name__ == "__main__":
    main()

How to run the examples:

  • Install dependencies: pip install pyzwcadmech and pip install PyQt5
  • Install ZWCAD MFG on the machine
  • Run a script from examples, for example python pyqt_ZWM_example_en.py
  • In most cases you do not need to manually copy ZwmToolKit.tlb

4. API Reference

4.1 ZwCADMech

mech = ZwCADMech(cad_app=None)
  • cad_app: Optional existing ZWCAD.Application instance
  • mech.app: Native ZWCAD.Application COM object
  • mech.zwm_app: ZwmApp wrapper instance
  • mech.zwm_db: ZwmDb wrapper instance

Shortcut methods delegated to ZwmDb:

  • open_file(filepath: str)
  • save(flag: int = 33)
  • close()
  • get_title() -> ZwmTitle
  • get_bom() -> ZwmBom
  • get_frame() -> ZwmFrame
  • title_edit(), total_bom_edit(), frame_edit(), fjl_edit()

4.2 ZwmTitle

  • get_item_count() -> int
  • get_item(index: int) -> tuple(str, str, str)
  • set_item(key: str, value: str)

4.3 ZwmBom and ZwmBomRow

ZwmBom:

  • get_item_count() -> int
  • get_item(index: int) -> ZwmBomRow
  • set_item(index: int, bom_row: ZwmBomRow)
  • add_item(bom_row: ZwmBomRow)
  • insert_item(index: int, bom_row: ZwmBomRow)
  • delete_item(index: int)
  • create_bom_row() -> ZwmBomRow

ZwmBomRow:

  • get_item_count() -> int
  • get_item(index: int) -> tuple(str, str, str)
  • set_item(key: str, value: str)

4.4 ZwmFrame

ZwmFrame exposes frame properties directly through Python properties, including:

  • width, height, std_name, frame_size_name, orientation, scale1, scale2
  • frame_style_name, title_style_name, bom_style_name, dhl_style_name, fjl_style_name, csl_style_name, ggl_style_name
  • have_dhl, have_fjl, have_btl, have_csl, have_ggl

After editing properties, call mech.zwm_db.build_frame(511) or refresh_frame() to apply the changes.

4.5 ZwmDb

Additional database methods:

  • switch_frame(frame_name: str)
  • get_frame_count() -> int
  • get_frame_name(index: int) -> str
  • get_next_frm_name() -> tuple(ZwmFrame, str)
  • refresh_title(), refresh_bom(), refresh_frame()
  • build_frame(switch_type: int = 511)

5. FAQ

Q: Do I need ZwmToolKit.tlb to use the library?
A: Usually no. pyzwcadmech now prefers dynamic COM calls first. The type library is mainly used to improve compatibility for a few complex interface calls.

Q: I see Failed to load ZwmToolKit.tlb or ModuleNotFoundError.
A: First make sure comtypes is installed and try connecting to ZWCAD MFG directly. If only a few complex calls fail, then add ZwmToolKit.tlb to your project directory or set PYZWCADMECH_TLB_PATH.

Q: I see Failed to create ZwmToolKit.ZwmApp.
A: This usually means either the standard ZWCAD edition is installed instead of the Mechanical edition, or the mechanical COM component is not registered correctly.

Q: get_title() or get_bom() returns None or raises an error.
A: Make sure mech.open_file("") was called successfully and that the current drawing actually contains the corresponding mechanical entities.

6. Packaging and Release

Recommended modern build flow:

python -m pip install --upgrade build twine
python -m build
python -m twine check dist/*
python -m twine upload dist/*

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyzwcadmech-0.3.0.tar.gz (11.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyzwcadmech-0.3.0-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file pyzwcadmech-0.3.0.tar.gz.

File metadata

  • Download URL: pyzwcadmech-0.3.0.tar.gz
  • Upload date:
  • Size: 11.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for pyzwcadmech-0.3.0.tar.gz
Algorithm Hash digest
SHA256 fc7964bcbd9e19546c4fa186d1f4cf1906a2b4661bcb3847cf14131e9a6eb98c
MD5 4b34bd6fe058a2bb0d47842043e068aa
BLAKE2b-256 a280e91d73db55d848a881f654c1169f6f8a300a5b6f9233031dc402a5d738e5

See more details on using hashes here.

File details

Details for the file pyzwcadmech-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: pyzwcadmech-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for pyzwcadmech-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ad47dc3a7aa5ba8df17642d02b0999b1d9669906f7ac4274a5dc5f70fd1dbd5a
MD5 acc00b87abd92ed5d96a6e7480889a45
BLAKE2b-256 f0fc16d7b823839d61b09c82f64026f5ef338a1ac0361b0d2e628b930bca463a

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 files

0.2.0

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page