Skip to content

bernhard-42/cadquery-massembly

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MAssembly for CadQuery

Intro

CadQuery provides numerical solver based assemblies.

MAssembly is derived from cadquery.Assembly, however, allows to define mates which will be used to manually assemble the objects.

Mate definitions

  • Method mate:

    def mate(
        self, query: str, name: str, origin: bool = False, transforms: Union[Dict, OrderedDict] = None
    ) -> "MAssembly":
    
    def mate(
        self, id: str, mate: Mate, name: str, origin: bool = False, transforms: Union[Dict, OrderedDict] = None
    ) -> "MAssembly":
  • Example:

    from collections import OrderedDict as odict
    
    hexapod = create_hexapod()
    
    hexapod.mate("bottom?top", name="bottom", origin=True)
    hexapod.mate(
        "top?bottom", name="top", origin=True, transforms=odict(rx=180, tz=-(height + 2 * tol))
    )

    Full code see 2-hexapod.py

Mate visualisation

  • Visualize mates in CQ-Editor (Note: show_mates needs show_objectas parameter and lengthdetermines the size of the visualised mate)

    from cadquery_massembly.cq_editor import show_mates
    
    show_object(hexapod, name="hexapod")
    show_mates(hexapod, show_object, length=5)
  • Visualize mates in Jupyter CadQuery

    show(hexapod, render_mates=True)

Final assembly

  • Method assemble

    def assemble(self, object_name: str, target: Union[str, Location]) -> Optional["MAssembly"]:
  • Example

    check_mates = False
    if check_mates:
        show_object(hexapod, name="hexapod")
        show_mates(hexapod, show_object, length=5)
    else:
        # Assemble the parts
        for leg in leg_names:
            hexapod.assemble(f"leg_{leg}_lower_hole", f"leg_{leg}_hole")
            hexapod.assemble(f"leg_{leg}_hinge", f"{leg}_hole")
        
        #   ...
    
        show_object(hexapod, name="hexapod")

    Full code see 2-hexapod.py

Installation

pip install git+https://github.com/bernhard-42/cadquery-massembly

Visualisation

CQ-Editor

  • Check mates view (check_mates = True)

    cq-editor-mates

  • Assembled view (check_mates = False)

    cq-editor-assembled

Jupyter Cadquery

Details see jupyter-cadquery

  • Check mates view

    jupyter-cadquery-mates

  • Assembled view

    jupyter-cadquery-assembled

Jupyter CadQuery additionally supports animating the object

hexapod-crawling