gumyr / build123d

A python CAD programming library
Apache License 2.0
395 stars 72 forks source link

Allow BuildSketch to accept align to position the origin of the Plane on different locations #277

Open gumyr opened 12 months ago

gumyr commented 12 months ago

Something like the following as described by Discord's drjth:

def plane_from_face(face: Face, align=(Align.CENTER, Align.CENTER)):
    u = (align[0].value - 1) / 2
    v = (align[1].value - 1) / 2
    pl = Plane(face)
    pl.origin = face.position_at(u,v)
    return pl
w, l1, h, w2, l2 = 5, 10, 2, 5, 4
with BuildPart() as p:
    with BuildSketch(Plane.XY):
        Rectangle(w,l1)
    extrude(amount=h)
    with BuildSketch(plane_from_face(p.faces().sort_by(Axis.Z)[-1], align=(Align.CENTER, Align.MAX))):
        Rectangle(w2,l2,align=(Align.CENTER, Align.MAX))
    extrude(amount=h)
gumyr commented 10 months ago

Not using Align, but the https://build123d.readthedocs.io/en/latest/direct_api_reference.html#geometry.Plane.shift_origin method allows the origin of a Plane to be moved to any position contained within the Plane.