Include "apply" function in the fluent API
- Dominant language
- Python
- Stars
- 5.8k
- Forks
- 541
- Avg merge
- 3d 2h
- Merged PRs (30d)
- 5
Description
I've been modelling something with a lot of angle-iron sections. I've got a little fed up with writing lots of bits like:
```python
myobj = (myobj
.faces('>X')
.workplane()
.moveTo(corner_x, corner_y)
.hLine(angle_size).vLine(-angle_thickness)
.hLine(-(angle_size-angle_thickness)).vLine(-(angle_size-angle_thickness))
.hLine(-angle_thickness).vLine(angle_size)
.close()
.extrude(angle_length)
)
```
and it occurred to me it would be really useful if there was a way to define a function so that the code could look like this:
```python
def draw_angle_profile(obj, angle_size, angle_thickness, orientation):
if orientation == 'southeast':
return (obj
.hLine(angle_size).vLine(-angle_thickness)
.hLine(-(angle_size-angle_thickness)).vLine(-(angle_size-angle_thickness))
.hLine(-angle_thickness).vLine(angle_size)
.close()
)
# elsewhere...
myobj = (myobj
.faces('>X')
.workplane()
.moveTo(corner_x, corner_y)
.apply(draw_angle_profile, angle_size, angle_thickness, 'southeast')
.extrude(angle_length)
)
```
I know I could do this by breaking the flow, something like this:
```python
myobj = (myobj
.faces('>X')
.workplane()
.moveTo(corner_x, corner_y)
)
myobj = (draw_angle_profile(myobj, angle_size, angle_thickness, 'southeast')
.close()
.extrude(angle_length)
)
```
but having an `apply` function seems a bit cleaner than leaving the string of functions with a last `moveTo`, then having to start a new set of functions. Not the biggest issue in the world, I'll grant you, but it would presumably be very easy to implement...
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.