CadQuery / cadquery

A python parametric CAD scripting framework based on OCCT
https://cadquery.readthedocs.io
Other
2.93k stars 276 forks source link

Add Workplane.addWire() method for simplifying adding wires to Workplanes #1574

Closed dov closed 2 months ago

dov commented 2 months ago

This PR adds th emethod Workplane.addWire(), which simplifies adding a wire to each of the points in the Workplane stack.

It simplifies workflows like adding rounded rectangle holes into a baseplate as shown in the example below.

If you think this is better suited as a plugin, please let me know.

def my_closed_wire_generator():
     '''Create a square with rounded corners'''
     s = 1
     points = [(-s,-s,0), (s,-s),(s,s),(-s,s)]
     return cq.Wire.makePolygon(points, close=True).fillet(0.3)

wire = my_closed_wire_generator() # Arbitrary routine generating a closed wire

# Create a workplane with four points on the stack
result = cq.Workplane('XY').box(10,10,1).faces('>Z').rect(7, 7, forConstruction=True).vertices()

# Add the wire to each of the points and cut
result =  result.addWire(wire).cutThruAll()

Here's the output:

rounded-square-holes

codecov[bot] commented 2 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 94.54%. Comparing base (3837cc5) to head (8d5ae8f).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #1574 +/- ## ======================================= Coverage 94.54% 94.54% ======================================= Files 28 28 Lines 5848 5850 +2 Branches 1166 1167 +1 ======================================= + Hits 5529 5531 +2 Misses 193 193 Partials 126 126 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

adam-urbanczyk commented 2 months ago

No need to extend the API, just use eachpoint. If you want to make it more user friendly, here is an open issue: https://github.com/CadQuery/cadquery/issues/1395.