Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing part from assembly by name #360

Open
shimwell opened this issue Dec 13, 2024 · 0 comments
Open

Removing part from assembly by name #360

shimwell opened this issue Dec 13, 2024 · 0 comments

Comments

@shimwell
Copy link
Member

shimwell commented Dec 13, 2024

cadquery.Assemby objects get returned by the functions and these include the plasma

Some use cases don't require the plasma (e.g. meshing for neutronics model) so it would be useful to be able to remove parts from the reactor

In the longer term cadquery assembies might have a .remove method but for now we can make a new assembly and filter by part name

This example makes an assembly with a box and sphere, then makes a new assembly without the box

import warnings
class Assembly(cq.Assembly):
    def remove(self, name:str):
        new_assembly = Assembly()
        part_found=False
        for part in self:
            if part[1].endswith(f'/{name}'):
                part_found = True
                print('removing' , part)
            else:
                print('adding' , part)
                new_assembly.add(part[0], name=part[1], color=part[3], loc=part[2])
        if part_found == False:
            warnings.warn(f'Part with name {name} not found')
        print()
        return new_assembly

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')

Alternatively we could add an argument include_plasma which would avoid monkey patching the class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant