Skip to main content

BUild123d Mutables Objects

Project description

Bumo

BUild123d Mutables Objects

An experimental package used to manage Build123d objects by applying mutations on them.

It can be used:

  • just out of curiosity, because it's a new way to build things;
  • as a debug tool, using colors and debug mode;
  • as a more object-oriented approach to build CAD parts.

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

Bumo is not a cad library on its own and does not aim to replace Build123d, you should take a look at the Build123d docs before using it.

Note: In the following examples we will use ocp vscode, but any other viewer should work.

Instantiating the builder

First things first, let's instanciate a Bumo builder and pass a Build123d part into it. Note that we must call the object (obj()) when passing it to the show function.

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

obj = Builder(_.Box(12, 12, 2))

show_object(obj(), clear=True)

Adding mutations

When applying an operation, instead of returning a copy of the modified object, the builder mutates the object:

obj = Builder(_.Box(12, 12, 2))
obj.add(_.Box(8, 8, 4))
obj.sub(_.Cylinder(3, 4))

Note that you can also pass an other builder to a mutation:

obj = Builder(_.Box(12, 12, 2))
obj2 = Builder(_.Box(8, 8, 4))
obj.add(obj2)
obj.sub(_.Cylinder(3, 4))

Changing colors

On each mutation you can pass a specific color instead of the auto-generated-one:

obj = Builder(_.Box(12, 12, 2), "orange")
obj.add(_.Box(8, 8, 4), "green")
obj.sub(_.Cylinder(3, 4), "violet")

Listing mutations

You can print the list of mutations and their properties:

obj.info()

The previous example will produce:

╒═══════╤═══════════╤═════════╤═════════╕
│   Idx │ Id        │ Type    │ Color   │
╞═══════╪═══════════╪═════════╪═════════╡
│     0 │ Builder-0 │ Builder │ orange  │
├───────┼───────────┼─────────┼─────────┤
│     1 │ add-1     │ add     │ green   │
├───────┼───────────┼─────────┼─────────┤
│     2 │ sub-2     │ sub     │ violet  │
╘═══════╧═══════════╧═════════╧═════════╛

Moving objects

You can move objects with move(), all colors will be preserved. Note that you can still use the Build123d * operator before passing the object to the builder.

obj = Builder(_.Box(12, 12, 2))
obj.add(_.Box(8, 8, 4))
obj.move(_.Location([-5, 2, 0]))
obj.sub(_.Rotation(25, 25, 0) * _.Cylinder(2.5, 10))

Alternative syntax

Alternatively you can use the operators +=, -=, &=, *= to add mutations (but passing a color or debug mode will not be possible):

obj = Builder(_.Box(12, 12, 2))
obj += _.Box(8, 8, 4) # fuse
obj -= _.Cylinder(3, 4) # substract
obj &= _.Cylinder(5, 4) # intersect
obj *= _.Rotation(90) # move

Note that their counterpart +, -, &, * are not allowed.

Reusing mutations

Instead of returning a copy of the object, mutations return a Mutation object that can be used to retrieve the altered faces and edges. Mutations can also be accessed by querrying a builder index (ie. obj[n]). This is useful with fillets and chamfers:

obj = Builder(_.Box(12, 12, 2))
obj.add(_.Box(8, 8, 4))
obj.fillet(obj[-1].edges_added(), 0.4)
hole = obj.sub(_.Cylinder(3, 4))
obj.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 a debug attribute to mutations, or passing faces (even removed ones) to the debug method:

obj = Builder(_.Box(12, 12, 2))
obj.add(_.Box(8, 8, 4))
obj.fillet(obj[-1].edges_added(), 0.4)
hole = obj.sub(_.Cylinder(3, 4))
obj.chamfer(hole.edges_added()[0], 0.3, debug=True)
obj.debug(obj[2].faces_altered()[0], "red")
# obj.debug(hole.faces_removed(), "red")

Configuring the builder

You can set builder attributes if necessary:

Builder.default_color = "grey"
Builder.debug_alpha = 0.5
Builder.autocolor = False
Builder.color_palette = ColorPalette.INFERNO

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.2.tar.gz (15.7 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.2-py3-none-any.whl (14.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: bumo-0.1.2.tar.gz
  • Upload date:
  • Size: 15.7 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.2.tar.gz
Algorithm Hash digest
SHA256 ef3cc0e700e63fccaf3a82e56c64b96ba046554d7a5c69bafe94e44b3fa48fd2
MD5 1f626f56114bd1adabec68668775ca71
BLAKE2b-256 17d44fdb04bb5db6439c1cee883b2cb242fdb0af3d6d420c4e93ca105456cda1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: bumo-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 14.8 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 548ac9f55cb8cd456a5e21a3e0a8b9d1b3bf02914310b902072d05e1328c1137
MD5 cc4cf90bbf96c241caa159e47ba87643
BLAKE2b-256 038f9c1815f2ff13ac7c62b5b04617940a0c3e2413b604d990fe1eedc13f7d59

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