MCPcopy Index your code
hub / github.com/CadQuery/cadquery / toCAF

Function toCAF

cadquery/occ_impl/assembly.py:446–603  ·  view source on GitHub ↗
(
    assy: AssemblyProtocol,
    coloredSTEP: bool = False,
    mesh: bool = False,
    tolerance: float = 1e-3,
    angularTolerance: float = 0.1,
    binary: bool = True,
)

Source from the content-addressed store, hash-verified

444
445
446def toCAF(
447 assy: AssemblyProtocol,
448 coloredSTEP: bool = False,
449 mesh: bool = False,
450 tolerance: float = 1e-3,
451 angularTolerance: float = 0.1,
452 binary: bool = True,
453) -> Tuple[TDF_Label, TDocStd_Document]:
454
455 # prepare a doc
456 app = XCAFApp_Application.GetApplication_s()
457
458 if binary:
459 BinXCAFDrivers.DefineFormat_s(app)
460 doc = TDocStd_Document(TCollection_ExtendedString("BinXCAF"))
461 else:
462 XmlXCAFDrivers.DefineFormat_s(app)
463 doc = TDocStd_Document(TCollection_ExtendedString("XmlXCAF"))
464
465 app.InitDocument(doc)
466
467 tool = XCAFDoc_DocumentTool.ShapeTool_s(doc.Main())
468 tool.SetAutoNaming_s(False)
469 ctool = XCAFDoc_DocumentTool.ColorTool_s(doc.Main())
470 ltool = XCAFDoc_DocumentTool.LayerTool_s(doc.Main())
471 mtool = XCAFDoc_DocumentTool.MaterialTool_s(doc.Main())
472
473 # used to store labels with unique part-color combinations
474 unique_objs: Dict[Tuple[Color | None, AssemblyObjects], TDF_Label] = {}
475 # used to cache unique, possibly meshed, compounds; allows to avoid redundant meshing operations if same object is referenced multiple times in an assy
476 compounds: Dict[AssemblyObjects, Compound] = {}
477
478 def _toCAF(el: AssemblyProtocol, ancestor: TDF_Label | None) -> TDF_Label:
479
480 # create a subassy if needed
481 if el.children:
482 subassy = tool.NewShape()
483 setName(subassy, el.name, tool)
484
485 # define the current color
486 current_color = el.color if el.color else None
487
488 # define the current material
489 current_material = el.material if el.material else None
490
491 # add a leaf with the actual part if needed
492 if el.obj:
493 # get/register unique parts referenced in the assy
494 key0 = (current_color, el.obj) # (color, shape)
495 key1 = el.obj # shape
496
497 if key0 in unique_objs:
498 lab = unique_objs[key0]
499 else:
500 lab = tool.NewShape()
501 if key1 in compounds:
502 compound = compounds[key1].copy(mesh)
503 else:

Callers 6

test_assy_root_nameFunction · 0.90
test_leaf_node_countFunction · 0.90
test_shallow_assyFunction · 0.90
exportAssemblyFunction · 0.85
exportCAFFunction · 0.85
exportGLTFFunction · 0.85

Calls 1

_toCAFFunction · 0.85

Tested by 3

test_assy_root_nameFunction · 0.72
test_leaf_node_countFunction · 0.72
test_shallow_assyFunction · 0.72