CAD modeling API wrapper for NCTI
Project description
# ncti-cad-api
一个 **用于 CAD 建模的 Python 库**,
支持通过 **Python 脚本生成三维模型文件**(STL / AMF / NCTI)。
本库不依赖任何 GUI,不会弹出窗口,适合:
- 后端服务
- 自动化建模
- 批量生成模型
- 被其他 Python 软件直接 import 调用
## ✨ 功能简介
建模脚本 → 调用 API → 输出 STL / AMF / NCTI 文件
📦 安装方式
方式一:安装 wheel 文件(推荐)
pip install ncti_cad_api-0.1.0-py3-none-any.whl
⚙️ 使用前配置
本库依赖 NCTI 运行环境,需要告诉库 NCTI DLL 所在目录。
from ncti_cad_api import configure
configure(
dll_dir=r"C:\path\to\ncti\dll", # NCTI 的 dll 目录
# ncti_python_dir=r"C:\path\to\ncti\py" # 如果 ncti_python 不在 site-packages,可选
)
一般只需要配置一次
如果 dll 路径不正确,后续建模会失败
🚀 快速上手示例
1️⃣ 编写建模脚本
# 这是一个示例建模脚本
# 脚本中可以直接使用:
# - doc (当前 CAD 文档)
# - NCTI (NCTI Python 接口)
# 下面内容请替换成你们自己的建模逻辑
# 示例(伪代码):
# doc.RunCommand("create_box 10 10 10")
2️⃣ 调用 API 生成模型
from ncti_cad_api import build_model_file
script = """
# 在这里粘贴或生成你的建模脚本
"""
result = build_model_file(
script_code=script,
out_path=r"D:\out\model.stl",
fmt="stl" # 支持:stl / amf / ncti
)
if result.ok:
print("生成成功:", result.out_path)
else:
print("生成失败:", result.error)
📂 支持的输出格式
格式 说明
stl 常用三角网格模型,适合打印/仿真
amf XML 格式网格
ncti 原生 CAD 模型文件
🧠 API 说明
build_model_file(...)
build_model_file(
script_code: str, # 建模脚本(Python 字符串)
out_path: str, # 输出文件路径
fmt: str = "stl", # 输出格式:stl / amf / ncti
global_scope: dict = None # (可选)注入脚本的变量
)
返回值:
BuildResult(
ok: bool, # 是否成功
out_path: str, # 成功时的输出文件路径
error: str # 失败时的错误信息
)
❗ 常见问题
Q1:生成失败,提示“模型为空 / 无网格数据”
原因:
建模脚本只创建了几何,但没有生成网格
解决:
在脚本中加入“生成网格 / 离散化”的命令
(具体命令取决于你们的 CAD/NCTI 接口)
Q2:提示找不到 DLL / ncti_python
解决:
确认 configure(dll_dir=...) 指向正确的目录
如果 ncti_python 不在系统 site-packages,配置:
configure(
dll_dir=r"...",
ncti_python_dir=r"..."
)
📌 注意事项
本库 不会打开任何界面
本库默认在当前进程中执行建模脚本
建议在 单进程 / 串行任务 中使用(除非确认底层 CAD 是线程安全的)
Project details
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 ncti_cad-0.2.1.tar.gz.
File metadata
- Download URL: ncti_cad-0.2.1.tar.gz
- Upload date:
- Size: 7.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0de1c456c3bb391ab895f8b4f6502b3dead10dc5db246103fb2feeb3d41baac4
|
|
| MD5 |
b7c13591d1d70cc04eb23ceef6428515
|
|
| BLAKE2b-256 |
1d82b9286d813ef0f7d97033bcaf4c92ac0b02881c3390151e5d27c1e2ba6ce2
|
File details
Details for the file ncti_cad-0.2.1-py3-none-any.whl.
File metadata
- Download URL: ncti_cad-0.2.1-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f787e7dfdd63cfee286b85ff77a4563db26088f2538a5e11dd4ae9787b7bbb0e
|
|
| MD5 |
ad43b91942718229eeedbe373e4033f0
|
|
| BLAKE2b-256 |
f0d37ebc3bbce9cafefc5bebeada1a9179c02d7cc5832f0fd824eb6d1980a3be
|