はじめに

What is CadQuery

CadQueryは、パラメトリック3 D CADモデルを構築するための、直感的で使いやすいPythonライブラリです。次のような目標があります。

  • すでに確立されている標準的なプログラミング言語を使用して、オブジェクトを人間に説明する方法に可能な限り近いスクリプトでモデルを構築します。

  • エンドユーザが非常に簡単にカスタマイズできるパラメトリックモデルを作成します

  • 従来のSTL形式に加えて、STEPやAMFなどの高品質なCAD形式を出力します。

  • Webブラウザのみで編集および実行できる、独自仕様ではないプレーン・テキスト・モデル・フォーマットを提供します。

CadQuery2はオープンソースの OpenCascade モデリングカーネル用のPythonバインディングのセットである OCP に基づいています。

Using CadQuery, you can build fully parametric models with a very small amount of code. For example, this simple script produces a flat plate with a hole in the middle:

thickness = 0.5
width=2.0
result = Workplane("front").box(width,width,thickness).faces(">Z").hole(thickness)
_images/simpleblock.png

That's a bit of a dixie-cup example. But it is pretty similar to a more useful part: a parametric pillow block for a standard 608-size ball bearing:

(length,height,diam, thickness,padding) = ( 30.0,40.0,22.0,10.0,8.0)

result = Workplane("XY").box(length,height,thickness).faces(">Z").workplane().hole(diam)\
        .faces(">Z").workplane() \
        .rect(length-padding,height-padding,forConstruction=True) \
        .vertices().cboreHole(2.4,4.4,2.1)
_images/pillowblock.png

Lots more examples are available in the CadQuery Examples

CadQuery is a library, GUIs are separate

CadQuery is a library, that's intentionally designed to be usable as a GUI-less library. This enables its use in a variety of engineering and scientific applications that create 3D models programmatically.

If you'd like a GUI, you have a couple of options:

Why CadQuery instead of OpenSCAD?

Like OpenSCAD, CadQuery is an open-source, script based, parametric model generator. But CadQuery has several key advantages:

  1. The scripts use a standard programming language, Python, and thus can benefit from the associated infrastructure. This includes many standard libraries and IDEs

  2. More powerful CAD kernel OpenCascade is much more powerful than CGAL. Features supported natively by OCC include NURBS, splines, surface sewing, STL repair, STEP import/export, and other complex operations, in addition to the standard CSG operations supported by CGAL

  3. Ability to import/export STEP and DXF We think the ability to begin with a STEP model, created in a CAD package, and then add parametric features is key. This is possible in OpenSCAD using STL, but STL is a lossy format

  4. Less Code and easier scripting CadQuery scripts require less code to create most objects, because it is possible to locate features based on the position of other features, workplanes, vertices, etc.

  5. Better Performance CadQuery scripts can build STL, STEP, and AMF faster than OpenSCAD.

Where does the name CadQuery come from?

CadQuery is inspired by jQuery, a popular framework that revolutionized web development involving JavaScript.

CadQuery is for 3D CAD what jQuery is for JavaScript. If you are familiar with how jQuery works, you will probably recognize several jQuery features that CadQuery uses:

  • A fluent API to create clean, easy to read code

  • Ability to use the library along side other Python libraries

  • Clear and complete documentation, with plenty of samples.