Repository navigation
Add assy imprint method - #2128
adam-urbanczyk wants to merge 18 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2128 +/- ##
==========================================
+ Coverage 95.85% 96.20% +0.34%
==========================================
Files 30 30
Lines 9651 11323 +1672
Branches 1460 1877 +417
==========================================
+ Hits 9251 10893 +1642
- Misses 246 274 +28
- Partials 154 156 +2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
paramak's remove() matched parts with endswith('/<name>') on the names
yielded by iterating the assembly. CadQuery/cadquery#2128 changes those
names so direct children of the root no longer carry the root prefix,
which would make remove() silently return the full assembly.
cadquery has had Assembly.remove since 2.6.0 (paramak's floor). It
removes the part in place by its key, keeps nested structure and raises
ValueError for an unknown name. Drop the override and test cadquery's
method on plain assemblies, nested sub-assemblies and a full reactor.
|
this looks useful for a few workflows in cad-to-dagmc where i have functions that take assemblies and imprint them. It might be useful to allow the assembly to know if it has been imprinted or know so that if imprinted assemblies are passed around the receiver does not accidentally imprint them again I was looking into how this improves my upstream codes and got a few keyerrors that might be worth considering |
|
KeyError when a part (or a named sub-shape) is not changed by the imprint import cadquery as cq
a = cq.Assembly()
a.add(cq.Workplane().box(10, 10, 10).val(), name="p0")
a.add(cq.Workplane().transformed(offset=(50, 0, 0)).box(10, 10, 10).val(), name="p1")
a.imprint() # KeyError |
|
Parts with a loc are moved twice and lose their shared faces a = cq.Assembly()
a.add(cq.Workplane().box(10, 10, 10).val(), name="a")
a.add(cq.Workplane().box(10, 10, 10).val(), name="b", loc=cq.Location((10, 0, 0)))
a.imprint()
# "b" now spans x 15..25 (should be 5..15), and the compound has 12 faces instead of 11 |
|
Thanks @shimwell , this is still a draft. I would not yet recommend testing. |
|
Thanks for the update. I tested One case still fails a import cadquery as cq
a = cq.Assembly()
a.add(cq.Workplane().box(10, 10, 10), name="a")
a.add(cq.Workplane().box(10, 10, 10).translate((50, 0, 0)), name="b")
a.imprint() # KeyErrorThe same thing happens with I did a local fix in which appears to help val = d[el] if default is None else d.get(el, el) |
Brings in main up to #255. The conflicts were the tag length check that main added beside the material tag count check, which now counts parts since the remapping helpers are gone, and main's rewrite of the imprinting docs. The overlaps docs said the Gmsh backend writes overlapping solids without an error. Its imprint now refuses the same overlaps as the mesher's, as each one splits a part into several solids. CadQuery 2.8.0, the current release, has no Assembly.imprint, so imprint_assembly falls back to the functional imprint when it is missing. The fallback puts the imprinted solids back in part order and raises the same overlapping solids error, so the gmsh paths behave the same either way. On the legacy imprint, "full" and None glue raise RuntimeError again, as they did before this branch. The requirement goes back to cadquery>=2.8.0, CI tests stable, master and the CadQuery/cadquery#2128 branch, and the imprint_assembly tests run against both implementations. TODOs mark the fallback for removal once a CadQuery release includes Assembly.imprint.
|
This now works for my use cases. Many thanks |
|
Found one more edge case imprinting an assembly with a single part raises an error, is this desired, perhaps it should just pass unless the solid connects back on itself when i guess it should do something (like the 360 degree plasma on paramak) |
|
I added error checks to the bool ops, so now you'll get: ValueError: Bool operation failed: BOPAlgo_AlertTooFewArguments |
lorenzncode
left a comment
There was a problem hiding this comment.
from cadquery import Assembly, Location, Color
from cadquery.func import box
box_bottom = box(1, 1, 1)
box_top = box(1, 1, 1)
assy = Assembly()
assy.add(box_bottom, name="box_bottom")
assy.add(box_top, name="box_top", loc=Location(z=1))
assy["box_bottom"].addSubshape(box_bottom.face("<Z"), name="bottom_face")
myface = assy["box_bottom"]["bottom_face"]
assy.imprint() # KeyErrorI tested with addSubShape to name an unchanged face. imprint raises KeyError in this case.
|
Thanks, should be fixed now. |
jmwright
left a comment
There was a problem hiding this comment.
Thanks @adam-urbanczyk there are just a few comments.
| for obj, name, loc in zip(objs, names, locs): | ||
| obj_imp = op.modified(obj, True) | ||
|
|
||
| # NB: loc.inverted() and not undMoved() due to how imprinting bool op works |
There was a problem hiding this comment.
| # NB: loc.inverted() and not undMoved() due to how imprinting bool op works | |
| # NB: loc.inverted() and not undoMoved() due to how imprinting bool op works |
| """ | ||
| Imprint assembly in-place. | ||
|
|
||
| NB: this function will tranform all non-Shape obj (e.g. Workplane) fields into |
There was a problem hiding this comment.
| NB: this function will tranform all non-Shape obj (e.g. Workplane) fields into | |
| NB: this function will transform all non-Shape obj (e.g. Workplane) fields into |
|
|
||
| For downstream processing including meshing and simulations it might be needed to imprint assembly objects, i.e. to make sure that faces that are geometrically | ||
| connected are also topologically connected. This can be achieved using the :py:meth:`cadquery.Assembly.imprint` method. For complex models imprinting can be very time-consuming so | ||
| it often beneficial to only imprint subassemblies that are known to have common faces, or imprint different subassemblies with different settings. Last, but not least, imprinting handles subshape |
There was a problem hiding this comment.
| it often beneficial to only imprint subassemblies that are known to have common faces, or imprint different subassemblies with different settings. Last, but not least, imprinting handles subshape | |
| it is often beneficial to only imprint subassemblies that are known to have common faces, or imprint different subassemblies with different settings. Last, but not least, imprinting handles subshape |
| names.append(name) | ||
| locs.append(loc) | ||
|
|
||
| result = imprint(*objs, tol=tol, glue=glue, history=hist) |
lorenzncode
left a comment
There was a problem hiding this comment.
from cadquery import Assembly, Location
from cadquery.func import box
box_bottom = box(2, 2, 1)
box_top = box(1, 1, 1)
assy = Assembly()
assy.add(box_bottom, name="box_bottom")
assy.add(box_top, name="box_top", loc=Location(z=1))
assy["box_bottom"].addSubshape(box_bottom.face(">Z"), name="face_at_z1")
assy.imprint()
assy.export("split_face.step") # AssertionError: Invalid subshapeHere STEP export fails after imprint splits a named face.
lorenzncode
left a comment
There was a problem hiding this comment.
from cadquery import Assembly, Location
from cadquery.func import box, compound
box_bottom = box(1, 1, 1)
box_top = box(1, 1, 1)
assy = Assembly()
assy.add(compound(compound(box_bottom)), name="box_bottom")
assy.add(box_top, name="box_top", loc=Location(z=1))
assy.imprint()
# The boxes touch at z=1, so should count as one unique face.
result = assy.toCompound()
assert len(result.Solids()) == 2
face_count = len(result.Faces())
assert face_count == 11, f"Expected 11 unique faces, got {face_count}"The resulting number of faces is unexpected with a nested compound.
Fixes #2075
cq.Assembly.imprint()method with subshape handlingimprint)I added (as it turns out without need)
undoMoveandundoMovedtoShape. Additionally reworked slightly how op history is handling default values. Nice to see that this feature can be used to develop new CQ features.