-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #362 from fusion-energy/adding_utils_to_assembly
added paramak.Assembly class that inherits from cq.Assembly and adds convenient methods
- Loading branch information
Showing
5 changed files
with
101 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Creates an assembly class that inherits from cadquery's assembly class | ||
# and adds a few conveniences methods remove() and names() | ||
|
||
import warnings | ||
import cadquery as cq | ||
|
||
|
||
class Assembly(cq.Assembly): | ||
"""Nested assembly of Workplane and Shape objects defining their relative positions.""" | ||
|
||
elongation=None | ||
triangularity=None | ||
major_radius=None | ||
minor_radius=None | ||
|
||
def remove(self, name: str): | ||
new_assembly = Assembly() | ||
part_found = False | ||
for part in self: | ||
if part[1].endswith(f'/{name}'): | ||
part_found = True | ||
else: | ||
new_assembly.add(part[0], name=part[1], color=part[3], loc=part[2]) | ||
if not part_found: | ||
warnings.warn(f'Part with name {name} not found') | ||
|
||
new_assembly.elongation = self.elongation | ||
new_assembly.triangularity = self.triangularity | ||
new_assembly.major_radius = self.major_radius | ||
new_assembly.minor_radius = self.minor_radius | ||
return new_assembly | ||
|
||
def names(self): | ||
names = [] | ||
for part in self: | ||
names.append(part[1].split('/')[-1]) | ||
return names |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import cadquery as cq | ||
from paramak.assemblies.assembly import Assembly | ||
|
||
def test_remove_and_names(): | ||
|
||
sphere1 = cq.Workplane().moveTo(2, 2).sphere(1) | ||
box1 = cq.Workplane().box(1, 1, 1) | ||
assembly = Assembly() | ||
assembly.add(box1, name="box1", color=cq.Color(0.5, 0.5, 0.5)) | ||
assembly.add(sphere1, name="sphere") | ||
|
||
assembly2 = assembly.remove('sphere') | ||
assembly3 = assembly.remove('box1') | ||
assembly4 = assembly.remove('bosdfsdf') | ||
|
||
assert assembly.names() == ['box1', 'sphere'] | ||
assert assembly2.names() == ['box1'] | ||
assert assembly3.names() == ['sphere'] | ||
assert assembly4.names() == ['box1', 'sphere'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters