1. 製品
  2.   CAD
  3.   Python
  4.   build123d
 
  

2D および 3D CAD 図面用のオープンソース Python ライブラリ

2Dおよび3Dモデルの作成と管理のためのオープンソースのPython CADライブラリ。パラメトリックなレゴブロックを作成し、Pythonアプリ内でセレクターを使用できます。

Build123d ライブラリとは?

Build123d はオープンソースの Python 3D CAD パッケージで、ソフトウェア開発者が独自の Python アプリケーション内で 2D および 3D 図面を作成できるようにします。Build123d ライブラリは標準の Python コンテキスト マネージャーを使用し、図面を処理するための 3 つのビルダーが用意されています。BuildLine ビルダーは 1 次元オブジェクト用、BuildSketch ビルダーは平面の 2 次元オブジェクト用、BuildPart ビルダーは 3 次元オブジェクト用です。ビルダーは、オブジェクトや操作の配置にロケーション コンテキストを使用します。

このライブラリは、フィレット、ミラー、オフセット、スケール、分割、カウンターボアホール、カウンターシンクホール、押し出し、穴、ロフト、回転、スケール、断面、分割など、さまざまな 2D および 3D 操作をサポートしています。上記以外にも、セレクタ、セレクタ演算子、エッジおよびワイヤー演算子、平面演算子、ベクター演算子、頂点演算子など、様々な演算子がライブラリに含まれています。

Build123dライブラリは、Build123d APIの便利な代替手段であり、多くの利点を備えています。最も重要な点は、オブジェクトの設計時にbuild123dがPythonツールボックスのすべてを利用できることです。このライブラリの操作は非常に簡単で、オブジェクトをどこにでも簡単に配置および管理できます。

Previous Next

Build123d を使い始める

Build123d の安定版リリースをインストールする最も簡単な方法は、GitHub を使用することです。スムーズにインストールするには、以下のコマンドを使用してください。

GitHub 経由で Build123d をインストールします

python3 -m pip install git+https://github.com/gumyr/build123d.git#egg=build123d 

コンパイルされた共有ライブラリは、Github リポジトリからダウンロードできます。

Python ライブラリでセレクタを使用する方法

GUI ベースの CAD システムを使用する場合、ユーザーは多くの場合、何らかの操作を行うためにフィーチャをクリックして選択します。セレクタとは、Python のフィルターとソートメソッドを使用して、ユーザーがフィーチャを設計から分離する方法を示す手順であり、通常は一連のカスタム Python 操作として実装されます。vertices()、edges()、wires()、solids()、faces() などがセレクタの例です。オペランドの型は、Axis、SortBy、GeomType です。sorted や filtered などの標準的なリストメソッドは、複雑なセレクタを生成する際に役立ちます。

Python ライブラリでパラメトリックなレゴブロックを作成

オープンソースの Python ライブラリ Build123d を使用すると、ソフトウェア開発者は独自の Python アプリケーション内でパラメトリックなレゴブロックを作成できます。まず、build123d 環境をインポートし、レゴブロックの寸法を定義する必要があります。次に、ビルダー部分に進み、ブロックの内部構造を作成します。構造を作成するために、後で 3D オブジェクトに押し出す 2 次元スケッチを描画する必要があります。次に、ブロックの周囲の長方形を定義し、長方形の壁を作成し、内部グリッドを作成します。その後、内部グリッドを尾根に変換し、中心部分を削除します。次に、内部に中空の円筒のセットを作成し、スケッチを壁として押し出します。壁が完成したら、ブロックの上部を追加し、最後にパイプを追加します。

Python API を使用してレゴ ブロックの寸法と内部グリッドを作成する方法

from build123d import *

pip_count = 6

lego_unit_size = 8
pip_height = 1.8
pip_diameter = 4.8
block_length = lego_unit_size * pip_count
block_width = 16
base_height = 9.6
block_height = base_height + pip_height
support_outer_diameter = 6.5
support_inner_diameter = 4.8
ridge_width = 0.6
ridge_depth = 0.3
wall_thickness = 1.2

// instantiate a BuildPart
with BuildPart() as lego:

//create a sketch builder
with BuildPart() as lego:
    # Draw the bottom of the block
    with BuildSketch() as plan:

//create Perimeter Rectangle
with BuildPart() as lego:
    # Draw the bottom of the block
    with BuildSketch() as plan:
        # Start with a Rectangle the size of the block
        perimeter = Rectangle(width=block_length, height=block_width)
 
 //create the walls of the block
ith BuildPart() as lego:
    # Draw the bottom of the block
    with BuildSketch() as plan:
        # Start with a Rectangle the size of the block
        perimeter = Rectangle(width=block_length, height=block_width)
        # Subtract an offset to create the block walls
        Offset(
            perimeter,
            amount=-wall_thickness,
            kind=Kind.INTERSECTION,
            mode=Mode.SUBTRACT,
        )
//Create Internal Grid
with BuildPart() as lego:
    # Draw the bottom of the block
    with BuildSketch() as plan:
        # Start with a Rectangle the size of the block
        perimeter = Rectangle(width=block_length, height=block_width)
        # Subtract an offset to create the block walls
        Offset(
            perimeter,
            amount=-wall_thickness,
            kind=Kind.INTERSECTION,
            mode=Mode.SUBTRACT,
        )
        # Add a grid of lengthwise and widthwise bars
        with GridLocations(x_spacing=0, y_spacing=lego_unit_size, x_count=1, y_count=2):
            Rectangle(width=block_length, height=ridge_width)
        with GridLocations(lego_unit_size, 0, pip_count, 1):
            Rectangle(width=ridge_width, height=block_width)
 
 
 日本