CadQuery/cadquery

GitHub: CadQuery/cadquery

CadQuery 是一个基于 Python 和 OCCT 的参数化 3D CAD 建模框架,用于快速创建与定制复杂几何模型。

Stars: 5473 | Forks: 518

![CadQuery logo](https://static.pigsec.cn/wp-content/uploads/repos/cas/54/54eca787b08c860682339d28cd3795448118f29f3a7988cdcbc7e671e58cabfa.svg) # CadQuery [![Appveyor Build status](https://ci.appveyor.com/api/projects/status/79ox42i6smelx7n8/branch/master?svg=true)](https://ci.appveyor.com/project/jmwright/cadquery-o18bh/branch/master) [![Build Status](https://dev.azure.com/cadquery/conda-packages/_apis/build/status/CadQuery.cadquery?branchName=master)](https://dev.azure.com/cadquery/conda-packages/_build/latest?definitionId=2&branchName=master) [![codecov](https://codecov.io/gh/CadQuery/cadquery/branch/master/graph/badge.svg)](https://codecov.io/gh/CadQuery/cadquery) [![Documentation Status](https://readthedocs.org/projects/cadquery/badge/?version=latest)](https://cadquery.readthedocs.io/en/latest/?badge=latest) [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.4498634.svg)](https://doi.org/10.5281/zenodo.3955118) ### 快速链接 [***文档***](https://cadquery.readthedocs.io/en/latest/) | [***速查表***](https://cadquery.readthedocs.io/en/latest/_static/cadquery_cheatsheet.html) | [***GitHub 讨论区***](https://github.com/CadQuery/cadquery/discussions) | [***Google 群组***](https://groups.google.com/g/cadquery) | [***GUI 编辑器***](https://github.com/CadQuery/CQ-editor) ## 什么是 CadQuery CadQuery 是一个直观、易用的 Python 模块,用于构建参数化的 3D CAD 模型。使用 CadQuery,你可以编写简短的脚本来生成高质量的 CAD 模型。通过一个可定制的脚本,可以轻松地制作出许多不同的对象。 CadQuery 在构建之初就被设计为一个没有任何 GUI 的 Python 库。这使得它非常适合集成到服务器,或创建科学和工程脚本等使用场景。不过,它包含了内置的可视化功能。 此外,还提供其他可视化选项,包括 CQ-Editor 和 JupyterLab。 感兴趣的话,[OCP 仓库](https://github.com/CadQuery/OCP)包含了 CQ 目前使用的 OCCT wrapper。 ### 主要特性 * 使用尽可能接近于向人类描述物体的方式,通过脚本构建 3D 模型。 * 创建可由终端用户轻松定制的参数化模型。 * 除了 STL、VRML、AMF 和 3MF 之外,还能输出高质量(无损)的 CAD 格式,如 STEP 和 DXF。 * 提供非专有的纯文本模型格式,只需一个网络浏览器即可对其进行编辑和执行。 * 提供高级建模功能,如圆角、曲线拉伸、参数化曲线和放样。 * 由独立零件和其他组件构建嵌套的装配体。 ## 入门 要了解有关使用 CadQuery 进行设计的更多信息,请访问[文档](https://cadquery.readthedocs.io/en/latest/intro.html)、[示例](https://cadquery.readthedocs.io/en/latest/examples.html)和[速查表](https://cadquery.readthedocs.io/en/latest/_static/cadquery_cheatsheet.html)。 为了快速开始,你可以使用 apptainer ``` apptainer run oras://ghcr.io/cadquery/cadquery-apptainer:master ipython -i -c"from cadquery.func import *; from cadquery.vis import show; show(box(1,1,1))" ``` 或者 docker/podman。 ``` podman run -i -v /tmp:/tmp -e DISPLAY=$DISPLAY --userns=keep-id --user "$(id -u):$(id -g)" --device /dev/dri -t ghcr.io/cadquery/cadquery-docker:master ipython -i -c"from cadquery.func import *; from cadquery.vis import show; show(box(1,1,1))" ``` CadQuery 库(包含或不包含 CQ-editor)及其依赖项可以使用 conda/mamba/micromamba/pixi 或 pip 进行安装。 请注意,基于 conda 的安装(或 CQ-editor 安装程序)是获得更好支持的选项。 有关详细的 CadQuery [安装说明](https://cadquery.readthedocs.io/en/latest/installation.html),请参阅文档。 ### 通过 Conda 安装 CadQuery 要首先安装 Conda 包管理器,请参阅[安装 Conda 包管理器](https://cadquery.readthedocs.io/en/latest/installation.html#install-the-conda-package-manager),以及 [Miniforge](https://github.com/conda-forge/miniforge) 获取最小安装程序。 为了更快且占用内存更少的 CadQuery 安装过程,推荐使用 ``mamba install`` 而不是 ``conda install``。 ``` # 设置新环境 conda create -n cadquery # 激活新环境 conda activate cadquery # 安装最新发布版本 mamba install -c conda-forge cadquery # 或者安装 dev 版本以获取最新更改 mamba install -c conda-forge -c cadquery cadquery=master ``` ### 通过 Pip 安装 CadQuery CadQuery 包含一系列复杂的依赖项,其中包括 OCP,这是我们针对 OpenCASCADE CAD kernel 的一组绑定。OCP 以二进制 wheels 的形式分发,适用于 Linux、MacOS 和 Windows。但是,存在一些限制。目前仅支持 Python 3.9 到 3.12,并且不支持某些较旧的 Linux 发行版(如 Ubuntu 18.04)。如果 pip 安装方法在你的系统上不起作用,可以尝试 conda 安装方法。 强烈建议在安装 CadQuery 时使用虚拟环境,尽管这并非严格必需。通过 pip 安装 CadQuery 需要最新版本的 pip,可以通过以下命令行(或其微小变体)获取。 ``` python3 -m pip install --upgrade pip ``` 安装最新版本的 pip 后,可以使用以下命令行安装 CadQuery。 ``` pip install cadquery ``` 也可以直接从 CadQuery 的 GitHub 仓库安装最新的更改,但需要注意的是有时可能会发生破坏性的更改。要从 git 仓库安装,请运行以下命令行。 ``` pip install git+https://github.com/CadQuery/cadquery.git ``` ### 内置可视化 CadQuery 具有使用 trame 和 vtk 的内置可视化功能。 ``` from cadquery.func import box, fillet from cadquery.vis import show b = box(1,1,1) show(fillet(b, b.edges("|Z"), 0.1)) ``` 对于非阻塞和持久视图,可以使用。 ``` from cadquery.func import box, fillet from cadquery.fig import show b = box(1,1,1) show(fillet(b, b.edges("|Z"), 0.1)) ``` ### CQ-editor GUI CQ-editor 是一个 IDE,允许用户在 GUI 环境中编辑 CadQuery 模型脚本。它包含以下特性: * 图形调试器,允许你单步调试脚本。 * CadQuery 堆栈检查器。 * 直接从菜单导出为多种格式,包括 STEP 和 STL。 更多关于 CQ-editor 的信息: * [CQ-editor README](https://github.com/CadQuery/CQ-editor/blob/master/README.md) * [安装](https://cadquery.readthedocs.io/en/latest/installation.html#adding-a-nicer-gui-via-cq-editor) CQ editor screenshot ### Jupyter CadQuery 开箱即用地支持 Jupyter。在 notebook 中运行你的 CadQuery 代码,并通过调用 ```display()``` 来可视化模型。 * [JupyterLab 安装](https://cadquery.readthedocs.io/en/latest/installation.html#jupyter)。 ## 获取帮助 你可以在 [cadquery.readthedocs.io](https://cadquery.readthedocs.io/) 找到完整的 CadQuery 文档。 我们还有一个 [Google 群组](https://groups.google.com/forum/#!forum/cadquery),方便你从其他 CadQuery 用户那里获得帮助。我们欢迎你的加入,并鼓励你加入该群组并进行自我介绍。我们也很乐意听到你正在使用 CadQuery 做些什么。 [GitHub 讨论区](https://github.com/CadQuery/cadquery/discussions)是一个提问与 bug 报告或功能请求无关的常规问题的好地方。 ## 专业支持 CadQuery 的一些核心维护者可提供有关 CadQuery 集成、自定义功能开发、培训、代码审查和 CAD 自动化的咨询服务。如果你感兴趣,请通过 **info@cadquery.org** 联系我们。 ## 引用 如果你在科学研究中使用了 CadQuery,请使用我们的 Zenodo DOI:https://doi.org/10.5281/zenodo.3955118。 ## 许可证 CadQuery 根据 [Apache Public License, version 2.0](http://www.apache.org/licenses/LICENSE-2.0) 的条款获得许可。 ### 如何报告 Bug 在提交 bug 报告 [issue](https://github.com/CadQuery/cadquery/issues) 时,请务必回答以下问题: 1. 你正在运行哪个版本的软件? 2. 你在什么操作系统上运行该软件? 3. 复现该 bug 的步骤是什么? ### 如何建议功能或增强特性 如果你希望有一个不存在的功能,可能不止你一个人这么想。肯定还有其他人也有类似的需求。请创建一个 [issue](https://github.com/CadQuery/cadquery/issues),描述你希望看到的功能、为什么需要它,以及它应该如何工作。
标签:3D建模, CAD, OCCT, Python框架, 参数化建模