Skip to content

Commit d34aed6

Browse files
authored
Merge pull request #25 from martinbudden/extrusions
Initial commit of extrusions plugin for code review
2 parents ae61fe2 + d4b4d46 commit d34aed6

File tree

12 files changed

+39628
-0
lines changed

12 files changed

+39628
-0
lines changed

plugins/extrusions/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Extrusions
2+
3+
Aluminium extrusions in a variety of sizes in both standard and v-slot profiles.
4+
Currently e2020, e2040, e2080, and e4040 standard profiles
5+
and v2020, v2040, and v4040 v-slot profiles are available.
6+
7+
## Installation
8+
9+
```
10+
pip install -e "git+https://github.com/CadQuery/cadquery-plugins.git#egg=extrusions&subdirectory=plugins/extrusions"
11+
```
12+
You can also clone the repository of the plugin and run in the repository the following command:
13+
```
14+
python setup.py install
15+
```
16+
17+
## Dependencies
18+
19+
This plugin has no dependencies other than the cadquery library.
20+
21+
## Usage
22+
23+
To use this plugin after it has been installed, just import it and use the extrusion functions.
24+
25+
```python
26+
import cadquery as cq
27+
import extrusions
28+
29+
extrusion = extrusions.e2020(100)
30+
```

plugins/extrusions/__init__.py

Whitespace-only changes.

plugins/extrusions/extrusions.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
"""
2+
Plugin for standard and v-slot aluminium extrusions in a variety of sizes.
3+
4+
Extrusion profiles are derived from Matronics ApS datasheets, eg
5+
http://www.matronics.eu/Data/Longship/Files/Products/vslot-2020_1.DXF
6+
7+
All used datasheets include in their description the text "Can be used for CAD programs"
8+
"""
9+
10+
from typing import Callable, TypeVar, Union, Tuple
11+
12+
# import importlib.resources
13+
import pkg_resources
14+
import cadquery as cq
15+
from cadquery.occ_impl import importers
16+
17+
T = TypeVar("T", bound="Workplane")
18+
19+
20+
def _extrusion(
21+
size: Tuple[float, float],
22+
profile_filename: str,
23+
extrusion_name: str,
24+
) -> Callable:
25+
"""
26+
Return a function that will in turn generate an extrusion.
27+
:param size: size of the extrusion, used for centering
28+
:param profile_filename: filename of the extrusion's profile
29+
:param extrusion_name: a string that will be inserted into a docstring template and assigned
30+
to __doc__ on the returned function
31+
"""
32+
# importlib.resources is favored over pkg_resources, but not yet available in cadquery,
33+
# see https://setuptools.readthedocs.io/en/latest/pkg_resources.html
34+
# When importlib. resources is available, following code should be used instead of pkg_resources
35+
# file = (
36+
# importlib.resources.files("plugins.extrusions")
37+
# .joinpath("profiles/")
38+
# .joinpath(profile_filename)
39+
# )
40+
file = pkg_resources.resource_filename(__name__, "profiles/" + profile_filename)
41+
profile = importers.importDXF(file).wires()
42+
docstring = f"""
43+
Return a {extrusion_name} extrusion with the specified length
44+
:param length: length of the extrusion
45+
:type length: float > 0
46+
:param centered: If True, the extrusion will be centered around the reference point.
47+
If False, the corner of the extrusion will be on the reference point and it will
48+
extend in the positive x, y and z directions. Can also use a 3-tuple to
49+
specify centering along each axis.
50+
"""
51+
52+
def rv(length: float, centered: Union[bool, Tuple[bool, bool, bool]] = False) -> T:
53+
if isinstance(centered, bool):
54+
centered = (centered, centered, centered)
55+
offset = cq.Vector(
56+
0 if centered[0] else size[0] / 2,
57+
0 if centered[1] else size[0] / 2,
58+
-length / 2 if centered[2] else 0,
59+
)
60+
extrusion = profile.toPending()._extrude(length).move(cq.Location(offset))
61+
return cq.Workplane("XY").newObject([extrusion])
62+
63+
rv.__doc__ = docstring
64+
return rv
65+
66+
67+
e2020 = _extrusion([20, 20], "e2020.dxf", "2020")
68+
e2040 = _extrusion([40, 20], "e2040.dxf", "2040")
69+
e2080 = _extrusion([80, 20], "e2080.dxf", "2080")
70+
e4040 = _extrusion([40, 40], "e4040.dxf", "4040")
71+
v2020 = _extrusion([20, 20], "v2020.dxf", "2020 v-slot")
72+
v2040 = _extrusion([40, 20], "v2040.dxf", "2040 v-slot")
73+
v4040 = _extrusion([40, 40], "v4040.dxf", "4040 v-slot")

0 commit comments

Comments
 (0)