Skip to main content

BUild123d Mutables Objects

Project description

Bumo

Build123d mutables objects

Introduction

Bumo is a Python package that work with the Build123d CAD library.

It essentially consists in a new class Builder used to update a CAD model: instead of creating a new instance of a CAD object each time an operation is made, the builder mutates to its new shape.

This slight difference on the behavior allows to:

  • get more intuitive results when altering object attributes or when working with class inheritance;
  • keep track of all the CAD object history, which can be used for various features, such as faces coloration based on operations.

The following instructions assumes you already know the basics of Build123d: if necessary please take a look at the Build123d docs before to continue.

Installation

This package is registred on Pypi, so you can either install it with Poetry:

poetry add bumo

or with pip:

pip install bumo

Getting started

Simple example

Let's start with some basic operations:

import build123d as _
from ocp_vscode import show_object
from bumo import Builder

b = Builder()

b += _.Box(8, 8, 2)
b -= _.Cylinder(2, 15)
b *= _.Rotation(0, 25, 0)
b &= _.Cylinder(4, 8)

show_object(b(), clear=True)

Wich will produce this:

For now there are no big differences here compared to the classical way to use Build123d, but let's analyze these 4 parts anyway:

  1. Imports: respectively, the Build123d CAD library, the ocp-vscode viewer, and Bumo (I have a personal preference for named imports over wildcard imports, but do as you wish);
  2. Builder instantiation;
  3. Applying mutations: respectively, fuse, substract, move, and intersect (note that their counterparts +, -, *, & are not available);
  4. Show: using ocp-vscode here, but any viewer should work (note that we must call the builder (b()) when passing it to the show function).

Parts 1. and 4. will always be the same here, so let's ignore them and focus on the builder-related stuff for the next examples.

Listing mutations

You can print the list of mutations and their properties:

b.info()

This will produce a table like this:

There is one row per muation, and their colors match the faces colors, which is convenient to quicly make a link between the operations and the altered faces.

Column details:

  • Idx: mutation index;
  • Id: mutation id;
  • Type: operation type;
  • F+, F~, F-: amount of added/altered/removed faces on this mutation;
  • E+, E~, E-: amount of added/altered/removed edges on this mutation;

Listing shapes

The info method is accessible from any mutation shapes attribute (faces_altered, edges_removed, etc.), for instance:

b = Builder()
b += _.Box(1, 2, 3)
b.last.faces_added.info()

Will produce:

╒════════╤════════════════╤════════╤════════════════╤═══════════════╕
│ Hash   │ Type           │   Area │ Position       │ Orientation   │
╞════════╪════════════════╪════════╪════════════════╪═══════════════╡
│ 634e76 │ GeomType.PLANE │      6 │ [-0.5, -1, -2] │ [-0, 0, -0]   │
│ 75e78b │ GeomType.PLANE │      6 │ [-0.5, -1, -2] │ [-0, 0, -0]   │
│ fdc160 │ GeomType.PLANE │      3 │ [-0.5, -1, -2] │ [-0, 0, -0]   │
│ 7843d9 │ GeomType.PLANE │      3 │ [-0.5, -1, -2] │ [-0, 0, -0]   │
│ fc164c │ GeomType.PLANE │      2 │ [-0.5, -1, -2] │ [-0, 0, -0]   │
│ f6c299 │ GeomType.PLANE │      2 │ [-0.5, -1, -2] │ [-0, 0, -0]   │
╘════════╧════════════════╧════════╧════════════════╧═══════════════╛

Extended syntax

The example above could also have been written like this:

b = Builder()
b.add(_.Box(8, 8, 2))
b.sub(_.Cylinder(2, 15))
b.move(_.Rotation(0, 25, 0))
b.intersect(_.Cylinder(4, 8))

This syntax allows to store the mutation itself into an object for later use.

Reusing mutations

Mutation objects can be used to retrieve the added, altered, removed and untouched faces or edges on this mutation (for instance when working with fillets and chamfers), and they can be accessed either with:

  • the return value of a mutation (ex. hole = b.sub());
  • querrying a builder index (ex. b[2]);
  • using the last attribute (ex. b.last);
b = Builder()
b.add(_.Box(12, 12, 2))
b.add(_.Box(8, 8, 4))
b.fillet(b.last.edges_added(), 0.4)
hole = b.sub(_.Cylinder(3, 4))
b.chamfer(hole.edges_added()[0], 0.3)

Using the debug mode

You can turn one or several mutations in debug mode, so all the other faces will be translucent, either by:

  • passing DEBUG to the mode argument of a mutation method (ex: b.add(..., mode=DEBUG));
  • passing DEBUG to mutation assignment operator (ex: b += ..., DEBUG);
  • passing faces (even removed ones) to the debug method (ex: b.debug(...)).
from bumo import Builder, DEBUG

b += _.Box(12, 12, 2)
b += _.Box(8, 8, 4)
# b += _.Box(8, 8, 4), DEBUG
b.fillet(b.last.edges_added, 0.4)
hole = b.sub(_.Cylinder(3, 4))
b.chamfer(hole.edges_added[0], 0.3, mode=DEBUG)
b.debug(b[2].faces_altered[0])
# b.debug(hole.faces_removed())

Changing colors

By default, mutations are colored using a color palette. Using the same mode used earlier, you can pass a specific color instead of the auto-generated-one:

b = Builder()
b += _.Box(12, 12, 2), "orange"
b += _.Box(8, 8, 4), "green"
b += _.Cylinder(3, 4), "violet"

Mutation with builders

If necessary it is possible to pass an other builder to a mutation:

b = Builder()
b.add(_.Box(12, 12, 2))

obj2 = Builder()
obj2.add(_.Box(8, 8, 4))

b.add(obj2)
b.sub(_.Cylinder(3, 4))

Configuring the builder

You can configure Bumo according to your needs:

from bumo import config

config.DEBUG_ALPHA = 0.5
config.COLOR_PALETTE = ColorPalette.INFERNO

Options are:

  • COLOR_PALETTE: The color palette to use when auto_color is enabled (ColorPalette.VIRIDIS);
  • DEBUG_ALPHA: The alpha value used for translucent shapes in debug mode (0.2);
  • DEFAULT_COLOR: The default color to be used when a color is passed to a mutation (Color("orange"));
  • DEFAULT_DEBUG_COLOR: The default color to be used when using the debug mode (default: Color("red"));
  • INFO_COLOR: Set to False to disable terminal colors in the info table (default: True);
  • INFO_TABLE_FORMAT = The table format used in the info table (default: "fancy_outline");
  • COLUMNS_MUTATIONS: The columns to display in mutations info tables, among: idx, label, type, color_hex, color_name, f+, f~, f-, e+, e~, e- (default: ["idx", "label", "type", "f+", "f~", "f-", "e+", "e~", "e-"]);
  • COLUMNS_SHAPES: The columns to display in shapes info tables, among: hash, type, area, color_hex, color_name. (default: ["hash", "type", "area", "position", "orientation"]).

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

bumo-0.1.3.tar.gz (19.1 kB view details)

Uploaded Source

Built Distribution

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

bumo-0.1.3-py3-none-any.whl (18.0 kB view details)

Uploaded Python 3

File details

Details for the file bumo-0.1.3.tar.gz.

File metadata

  • Download URL: bumo-0.1.3.tar.gz
  • Upload date:
  • Size: 19.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.10.12 Linux/6.8.0-51-generic

File hashes

Hashes for bumo-0.1.3.tar.gz
Algorithm Hash digest
SHA256 ed5d7190fd463427616fdac03a97bb6757eea382ad01822dc283845eab17a448
MD5 2876c118a3adee0ccd23782885fa326b
BLAKE2b-256 d36a05181bdfca0877760532d9e3e21787e0e85274725c995c6f5a93ccd43ffc

See more details on using hashes here.

File details

Details for the file bumo-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: bumo-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 18.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.10.12 Linux/6.8.0-51-generic

File hashes

Hashes for bumo-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 1dd6e702d3b37c540c74323701b286748e4abc980a5365bb5b9b9304b5e8b2f0
MD5 3260174e7dbde747311bd9672d94aee0
BLAKE2b-256 2085ba897b0bcdc5882f23982a6408583929259d2d0b13d0e55141b0e74921b4

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