{"id":32588559,"url":"https://github.com/cadquery/assembly-mesh-plugin","last_synced_at":"2025-10-29T23:59:20.826Z","repository":{"id":274671173,"uuid":"923671671","full_name":"CadQuery/assembly-mesh-plugin","owner":"CadQuery","description":"A plugin to convert CadQuery assemblies with tagged faces to a mesh","archived":false,"fork":false,"pushed_at":"2025-10-07T11:16:05.000Z","size":467,"stargazers_count":10,"open_issues_count":2,"forks_count":4,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-10-07T13:21:15.421Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CadQuery.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-01-28T17:00:40.000Z","updated_at":"2025-10-06T19:33:35.000Z","dependencies_parsed_at":null,"dependency_job_id":"4d1a4144-fc4a-450d-b122-e9a1918288cb","html_url":"https://github.com/CadQuery/assembly-mesh-plugin","commit_stats":null,"previous_names":["cadquery/assembly-mesh-plugin"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/CadQuery/assembly-mesh-plugin","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CadQuery%2Fassembly-mesh-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CadQuery%2Fassembly-mesh-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CadQuery%2Fassembly-mesh-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CadQuery%2Fassembly-mesh-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CadQuery","download_url":"https://codeload.github.com/CadQuery/assembly-mesh-plugin/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CadQuery%2Fassembly-mesh-plugin/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":281719938,"owners_count":26549881,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-29T02:00:06.901Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-10-29T23:59:19.618Z","updated_at":"2025-10-29T23:59:20.814Z","avatar_url":"https://github.com/CadQuery.png","language":"Python","readme":"![Project Logo](docs/images/logo.png)\n\nCadQuery plugin to create a mesh of an assembly with corresponding data.\n\nThis plugin makes use of CadQuery tags to collect surfaces into [Gmsh](https://gmsh.info/) physical groups. The\ntagged faces are matched to their corresponding surfaces in the mesh via their position in the CadQuery solid(s) vs the Gmsh surface ID. There are a few challenges with mapping tags to surfaces to be aware of.\n\n1. Each tag can select multiple faces/surfaces at once, and this has to be accounted for when mapping tags to surfaces.\n2. Tags are present at the higher level of the Workplane class, but are do not propagate to lower-level classes like Face.\n3. OpenCASCADE does not provide a built-in mechanism for tagging low-level entities without the use of an external data structure or framework.\n\n## Installation\n\nYou can install via [PyPI](https://pypi.org/project/assembly-mesh-plugin/)\n\n```\npip install assembly-mesh-plugin\n```\n\n## Usage\n\n**PLEASE NOTE:** This plugin currently needs to be run in an Anaconda/Mamba environment because of a crash with the PyPI packages when passing OpenCASCADE objects to Gmesh in memory.\n\nThe plugin needs to be imported in order to monkey-patch its method into CadQuery:\n\n```python\nimport assembly_mesh_plugin\n```\n\nYou can then tag faces in each of the assembly parts and create your assembly. To export the assembly to a mesh file, you do the following.\n\n```python\nyour_assembly.saveToGmsh(mesh_path=\"tagged_mesh.msh\")\n```\n\nNormal tag names lead to a physical group with the assembly part name prefixed. So a tag name of `inner-bottom` on an assembly part with the name `steel_plate` will be `steel_plate_inner-bottom`\n\nBy prefixing a tag with the `~` character, the part name is ignored, which allows for tagging of a multi-material\nphysical group. For instance, tagging multiple faces with `~contact-with-casing` will produce a physical group with the name `contact-with-casing` that includes all those faces, even if they belong to different parts/solids.\n\nBelow is a simple example.\n\n```python\nimport cadquery as cq\nimport assembly_mesh_plugin\n\nshell = cq.Workplane(\"XY\").box(50, 50, 50)\nshell = shell.faces(\"\u003eZ\").workplane().rect(21, 21).cutThruAll()\nshell.faces(\"\u003eX[-2]\").tag(\"inner-right\")\nshell.faces(\"\u003cX[-2]\").tag(\"~in_contact\")\n\n# Create the insert\ninsert = cq.Workplane(\"XY\").box(20, 20, 50)\ninsert.faces(\"\u003cX\").tag(\"~in_contact\")\ninsert.faces(\"\u003eX\").tag(\"outer-right\")\n\nassy = cq.Assembly()\nassy.add(shell, name=\"shell\")\nassy.add(insert, name=\"insert\")\n\nassy.saveToGmsh(mesh_path=\"tagged_mesh.msh\")\n```\n\nThe resulting `.msh` file should have three physical groups named for tags in it. The `in_contact` group should include the faces from both the shell and the insert.\n\nIf you want more control over the mesh generation and export, you can use the `getTaggedGmsh` method and then finalize the mesh yourself.\n\n```python\nimport cadquery as cq\nimport assembly_mesh_plugin\nimport gmsh\n\nshell = cq.Workplane(\"XY\").box(50, 50, 50)\nshell = shell.faces(\"\u003eZ\").workplane().rect(21, 21).cutThruAll()\nshell.faces(\"\u003eX[-2]\").tag(\"inner-right\")\nshell.faces(\"\u003cX[-2]\").tag(\"~in_contact\")\n\n# Create the insert\ninsert = cq.Workplane(\"XY\").box(20, 20, 50)\ninsert.faces(\"\u003cX\").tag(\"~in_contact\")\ninsert.faces(\"\u003eX\").tag(\"outer-right\")\n\nassy = cq.Assembly()\nassy.add(shell, name=\"shell\")\nassy.add(insert, name=\"insert\")\n\n# Get a Gmsh object back with all the tagged faces as physical groups\ngmsh_object = assy.getTaggedGmsh()\n\n# Generate the mesh and write it to the file\ngmsh_object.model.mesh.field.setAsBackgroundMesh(2)\ngmsh_object.model.mesh.generate(3)\ngmsh_object.write(\"tagged_mesh.msh\")\ngmsh_object.finalize()\n```\n\n## Tests\n\nThese tests are also run in Github Actions, and the meshes which are generated can be viewed as artifacts on the successful `tests` Actions there.\n\n* [sample_coils.py](tests/sample_coils.py) contains generators for sample assemblies for use in testing the basic operation of this plugin. This file also contains the code to tag all faces of interest.\n* [smoke_test.py](tests/smoke_test.py) runs two tests currently. The first is for a simple cross-section of a coil (image below), which makes it easier to verify basic operation. The second is for a planar coil, which forces the use of more advanced selectors, but is not as complex as a coil with a non-planar sweep path. This planar-coil test is not complete yet.\n\nOnce the test has been run (using the pytest command), two mesh files (.msh extension) be created in the root of the repository.\n\n* tagged_cross_section.msh\n* tagged_planar_coil.msh\n\nThese mesh files will have many physical groups since each surface gets its own physical group, but it should also contain physical groups corresponding to the tags that were created for the faces in the assembly parts.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcadquery%2Fassembly-mesh-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcadquery%2Fassembly-mesh-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcadquery%2Fassembly-mesh-plugin/lists"}