gumyr / build123d

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

bug when extruding sketch #28

Closed roipoussiere closed 1 year ago

roipoussiere commented 1 year ago

This code:

import build123d as b

with b.BuildPart():
    with b.BuildSketch() as builder:
        b.Rectangle(1, 1)
    b.Add(builder.sketch)
    b.Extrude(amount=1)

fails with:

Traceback (most recent call last):
  File ".../src/test.py", line 7, in <module>
    b.Extrude(amount=1)
  File ".../.venv/lib/python3.10/site-packages/build123d/build_part.py", line 449, in __init__
    plane.zDir * amount * direction,
AttributeError: 'NoneType' object has no attribute 'zDir'
gumyr commented 1 year ago

Normally, the b.Add(builder.sketch) would not be used as it's not required - when BuildSketch exits it automatically passes its contents to BuildPart - however, what is done here is totally acceptable. Therefore, Add has been changed to take this case into consideration and internally add the required plane as the BuildSketch exit() method does.

The code generates the following now: image