CodeToCAD / CodeToCAD

Create models and simulations in your favorite modeling software using CodeToCAD's automation language!
https://codetocad.github.io/CodeToCAD/docs.html
MIT License
41 stars 9 forks source link

Make Sketching and Part building better: Builder Pattern #194

Closed shehabattia96 closed 1 month ago

shehabattia96 commented 10 months ago

These are observations made while using CodeToCAD:

Related: #154

Resources:

shehabattia96 commented 7 months ago

@jdegenstein suggested PartBuilder used in Build123d. Build Pattern may be a good solution for this problem. https://build123d.readthedocs.io/en/latest/introductory_examples.html#simple-rectangular-plate

shehabattia96 commented 1 month ago

So after comparing a lot of existing Code-CAD solutions, and looking at how they tackle this problem, I honestly don't think there is one good way to do it.

For now, CodeToCAD is going to utilize Landmarks and PresetLandmarks to automatically build and attach parts together.

Parts: To keep building with preset parts, it will look like this:

part = Part("myPart")
part.create_cube(l,w,h, merge_at = PresetLandmark.bottom, merge_to = PresetLandmark.top, operation = Boolean.Union)
part.create_cylinder(r, h, merge_at = PresetLandmark.bottom, merge_to = PresetLandmark.top, operation = Boolean.Union)

Explanation: If the Part does not have existing geometry, a cube will be inserted by default at PresetLandmark.bottom, relative to PresetLandmark.top of origin - in other words, it will sit on top of the plane. If the Part has an existing geometry, the cube will be inserted by default at PresetLandmark.bottom, relative to PresetLandmark.top of the existing geometry - in other words it will stack vertically in the Z axis.

The user will be able to provide a different landmark to control where the new geometry will be merged to. They can choose any Boolean operation between Union|Subtract|Intersect.

Sketchs: To keep building with sketches, it will look like this:

some_profile = Wire("mySketch") # This will create a new wire in this sketch.
some_profile.create_line(length, angle, start_at=PresetLandmark.end)
some_profile.create_arc(*args, start_at=PresetLandmark.end)
some_profile.create_line_to(to=PresetLandmark.start, start_at=PresetLandmark.end)

Explanation: We're going to add PresetLandmark.end and PresetLandmark.start to denote landmarks at the beginning and end of a wire. The user can decide where to append the new wire or edge in an existing wire.