Pythonic COM automation API for GstarCAD on Windows
Project description
pygcadwin
pygcadwin 是一个用于 Windows 上浩辰 CAD / GstarCAD 的 Python COM
自动化库。它通过 GstarCAD 注册的 GStarCAD.Application.* ProgID 连接
到正在运行的 GstarCAD,或按需启动新的 GstarCAD 实例,并提供更接近
Python 使用习惯的绘图、选择、布局、表格和视图截图 API。
这个项目的接口风格参考了
pyautocad,但目标应用是
GstarCAD,并且底层依赖 pywin32。
安装
运行环境:
- Windows
- Python 3.10+
- 已安装并注册 COM 的 GstarCAD
从 GitHub 安装:
pip install git+https://github.com/GstarCAD-AI/pygcadwin.git
本地开发安装:
git clone https://github.com/GstarCAD-AI/pygcadwin.git
cd pygcadwin
pip install -e .
如果需要 Excel / xlsx 表格导入导出功能:
pip install -e ".[tables]"
快速开始
import pygcadwin as gcad
cad = gcad.Gcad(create_if_missing=True, visible=True)
ctx = cad.context
ctx.ensure_layer("Walls")
ctx.create_segment((0, 0), (100, 0), layer="Walls", color=1)
ctx.create_circle((50, 50), 25)
ctx.zoom_extents()
cad.document.save_as(r"C:\tmp\demo.dwg")
cad.close()
也可以用上下文管理器自动释放 COM 引用:
from pygcadwin import Gcad
with Gcad(create_if_missing=True, visible=True) as cad:
cad.context.create_rect((0, 0), (100, 50), layer="Frame", color=3)
cad.context.zoom_extents()
主要功能
- 连接或启动 GstarCAD COM 应用。
- 访问 Application、ActiveDocument、ModelSpace、Layouts。
- 创建线段、圆、圆弧、椭圆、多段线、矩形、文字、填充、标注和表格。
- 选择集、对象遍历、对象查找和布局遍历。
Point2、Vector2、距离计算和 COM VARIANT 数组辅助函数。- CSV / JSON 表格导入导出,Excel 格式通过
tables可选依赖启用。 - 简单的工具调用分发接口,可用于 LLM agent 调用 CAD 操作。
- 视图快照和缩放辅助。
指定 GstarCAD 版本
默认会优先尝试已注册的版本化 ProgID,例如:
GStarCAD.Application.27GStarCAD.Application.26GStarCAD.Application
当同一台机器上安装了多个版本时,可以显式指定:
from pygcadwin import Gcad
cad = Gcad(prog_id="GStarCAD.Application.27")
Agent 工具调用
from pygcadwin import execute_tool
result = execute_tool(
"create_circle",
{"center": [0, 0], "radius": 10, "layer": "A-CIRC"},
)
print(result)
使用 tool_schemas() 可以获取可暴露给工具调用 agent 的操作 schema,
run_actions([...]) 可以顺序执行多步绘图动作。
当前状态
这是第一版公开发布,API 仍处于 alpha 阶段。建议先在测试图纸或临时 DWG 文件中验证脚本行为,再用于正式生产图纸。
许可证
MIT License。详见 LICENSE。
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pygcadwin-0.1.0.tar.gz.
File metadata
- Download URL: pygcadwin-0.1.0.tar.gz
- Upload date:
- Size: 26.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a9208d1f365aea1c37f9d3a170d955a9c761f027eb6668187b0deebba2949e50
|
|
| MD5 |
678b8d8fc4e75d1f3ff4659b82eeda51
|
|
| BLAKE2b-256 |
9f9d07d2a2cde3c43152f7d5b358a90ca71e87663e0f3543b153d0d28075079a
|
Provenance
The following attestation bundles were made for pygcadwin-0.1.0.tar.gz:
Publisher:
publish.yml on GstarCAD-AI/pygcadwin
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pygcadwin-0.1.0.tar.gz -
Subject digest:
a9208d1f365aea1c37f9d3a170d955a9c761f027eb6668187b0deebba2949e50 - Sigstore transparency entry: 1688218400
- Sigstore integration time:
-
Permalink:
GstarCAD-AI/pygcadwin@8920f1fed330e838d2a5d30b6f1aefb1125109d8 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/GstarCAD-AI
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8920f1fed330e838d2a5d30b6f1aefb1125109d8 -
Trigger Event:
release
-
Statement type:
File details
Details for the file pygcadwin-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pygcadwin-0.1.0-py3-none-any.whl
- Upload date:
- Size: 29.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7caf09f2566c3cf49b7fbffcac4e85c560a08ff884b129ecfbe8ef13966e7d0d
|
|
| MD5 |
0f812fe6046675eda1899df3ca651d2c
|
|
| BLAKE2b-256 |
87b7d882dfc3a2f9687af4e41f4bf4439290529267a78d515027d5f5c1868877
|
Provenance
The following attestation bundles were made for pygcadwin-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on GstarCAD-AI/pygcadwin
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pygcadwin-0.1.0-py3-none-any.whl -
Subject digest:
7caf09f2566c3cf49b7fbffcac4e85c560a08ff884b129ecfbe8ef13966e7d0d - Sigstore transparency entry: 1688218431
- Sigstore integration time:
-
Permalink:
GstarCAD-AI/pygcadwin@8920f1fed330e838d2a5d30b6f1aefb1125109d8 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/GstarCAD-AI
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8920f1fed330e838d2a5d30b6f1aefb1125109d8 -
Trigger Event:
release
-
Statement type: