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/*

Metadata

Release files for pyzwcadmech 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyzwcadmech 0.3.0
File Size Uploaded Provenance Actions
pyzwcadmech-0.3.0.tar.gz 11.7 kB Without provenance Details for pyzwcadmech-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pyzwcadmech 0.3.0
File Interpreter ABI Platform Actions
pyzwcadmech-0.3.0-py3-none-any.whl Python 3 none any Details for pyzwcadmech-0.3.0-py3-none-any.whl

Total release size: 20.0 kB

Release files / pyzwcadmech-0.3.0.tar.gz

Download URL pyzwcadmech-0.3.0.tar.gz
Size 11.7 kB
Tags Source
SHA-256 checksum
How to use checksums
fc7964bcbd9e19546c4fa186d1f4cf1906a2b4661bcb3847cf14131e9a6eb98c
BLAKE2b-256 checksum
How to use checksums
a280e91d73db55d848a881f654c1169f6f8a300a5b6f9233031dc402a5d738e5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release files / pyzwcadmech-0.3.0-py3-none-any.whl

Download URL pyzwcadmech-0.3.0-py3-none-any.whl
Size 8.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ad47dc3a7aa5ba8df17642d02b0999b1d9669906f7ac4274a5dc5f70fd1dbd5a
BLAKE2b-256 checksum
How to use checksums
f0fc16d7b823839d61b09c82f64026f5ef338a1ac0361b0d2e628b930bca463a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Security for pyzwcadmech 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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