Skip to main content

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

ncti_cad-0.1.1.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

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

ncti_cad-0.1.1-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file ncti_cad-0.1.1.tar.gz.

File metadata

  • Download URL: ncti_cad-0.1.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

Hashes for ncti_cad-0.1.1.tar.gz
Algorithm Hash digest
SHA256 d6c80b6aa266981b933566c2f4b9f638748dade6cf05538b6db51e226c3d0fcf
MD5 f1f1c8fbe28a78ba89e0c19e30fd0545
BLAKE2b-256 64779d269afeb2f43404aabe660e3cf26a29b259ef619dd660d14b40e8bb1daf

See more details on using hashes here.

File details

Details for the file ncti_cad-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: ncti_cad-0.1.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

Hashes for ncti_cad-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 05b14efe35aa850b13a4683d448e4ada6adbb8bdff82008c658f19f7033d2a20
MD5 2da5ffd0c23430d8836f3f0c058a862a
BLAKE2b-256 d742f7fd01c4df47bf59375cff363ae326615a491de0393e72381cea569ebd5f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page