gumyr / build123d

A python CAD programming library
Apache License 2.0
510 stars 86 forks source link

2D primitives affected by outside context #218

Closed hiaselhans closed 1 year ago

hiaselhans commented 1 year ago

b3d context and algebra mode don't play too well together. Imagine a helper function/class that uses some 2D primitives using plain algebra mode:

import build123d as bd
def part():
    rect = bd.Rectangle(12,12)
    return bd.extrude(rect, amount=5)

this function works and returns a solid, but it does not work when it is used inside a context:

# this works:
part1 = part()

# this fails:
with bd.BuildPart() as part2:
    a = part()
gumyr commented 1 year ago

This is a known limitation that is documented here: https://build123d.readthedocs.io/en/latest/introduction.html#key-concepts-builder-mode

Both API can be mixed in the same model with the exception that the algebra API can’t be used from within a builder context.

However, this works:

a = part()
with bd.BuildPart() as part3:
    bd.add(a)

Unless you have a suggestion as to how this might work I'm afraid this limitation will have to remain.