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

There is no function to create a solid from assembly #629

Closed
adam-trhon opened this issue Feb 10, 2021 · 1 comment · Fixed by #726
Closed

There is no function to create a solid from assembly #629

adam-trhon opened this issue Feb 10, 2021 · 1 comment · Fixed by #726
Labels
assembly enhancement New feature or request

Comments

@adam-trhon
Copy link
Contributor

Creating a solid from assembly has following use cases:

  • Exporting the assembly to format that does not support multiple parts, for example stl
  • Using assembly in boolean operations
@adam-urbanczyk adam-urbanczyk added enhancement New feature or request assembly labels Feb 11, 2021
@adam-trhon
Copy link
Contributor Author

I ended up using this (heavily copied from Discord discussion):

def generate_solid_from_assembly(assy, fuse=True, name_filter_re=None):
    result = []
    
    for name,val in assy.traverse():
        if name_filter_re and not re.match(name_filter_re, name):
            continue
        
        shape = val.obj.val()

        # get location
        loc = val.loc
        current = val
        while current.parent:
            loc = current.parent.loc*loc
            current = current.parent
        
        result.append(shape.located(loc))

    result = cq.Compound.makeCompound(result) 

    if fuse:
        result = result.fuse()

    return result

Notes:

  • By default the function fuses the compound. This is slower, but I assume it always returns the right result. Without fusing, the result may behave strange when used in boolean operations. If the user needs to speed up the process, fusing can be disabled by an argument.
  • I think there should be some filtering. This is a necessity when one wants to perform a boolean operation and have the operands positioned using the constraint solver. As I could not figure out anything better, I filter based on names.

Please review and comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
assembly enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants