Export an assembly to a STEP file with faces tagged with names and colors. This is done as a separate method from the main STEP export because this is not compatible with the fused mode and also flattens the hierarchy of the STEP. Layers are used because some software does not unde
(
assy: AssemblyProtocol,
path: str,
write_pcurves: bool = True,
precision_mode: int = 0,
unit: UnitLiterals = "MM",
outputUnit: Optional[UnitLiterals] = None,
)
| 167 | |
| 168 | |
| 169 | def exportStepMeta( |
| 170 | assy: AssemblyProtocol, |
| 171 | path: str, |
| 172 | write_pcurves: bool = True, |
| 173 | precision_mode: int = 0, |
| 174 | unit: UnitLiterals = "MM", |
| 175 | outputUnit: Optional[UnitLiterals] = None, |
| 176 | ) -> bool: |
| 177 | """ |
| 178 | Export an assembly to a STEP file with faces tagged with names and colors. This is done as a |
| 179 | separate method from the main STEP export because this is not compatible with the fused mode |
| 180 | and also flattens the hierarchy of the STEP. |
| 181 | |
| 182 | Layers are used because some software does not understand the ADVANCED_FACE entity and needs |
| 183 | names attached to layers instead. |
| 184 | |
| 185 | :param assy: assembly |
| 186 | :param path: Path and filename for writing |
| 187 | :param write_pcurves: Enable or disable writing parametric curves to the STEP file. Default True. |
| 188 | If False, writes STEP file without pcurves. This decreases the size of the resulting STEP file. |
| 189 | :param precision_mode: Controls the uncertainty value for STEP entities. Specify -1, 0, or 1. Default 0. |
| 190 | See OCCT documentation. |
| 191 | :param unit: The internal unit of the model's geometry values. Default "MM". |
| 192 | :type unit: UnitLiterals |
| 193 | :param outputUnit: The unit to use in the STEP file header. If None, defaults to the value of ``unit``. |
| 194 | Use this when you want the output file to declare a different unit than the model's internal unit, |
| 195 | for example to export a MM model as a STEP file declaring meters. |
| 196 | :type outputUnit: UnitLiterals or None |
| 197 | """ |
| 198 | |
| 199 | pcurves = 1 |
| 200 | if not write_pcurves: |
| 201 | pcurves = 0 |
| 202 | |
| 203 | # Initialize the XCAF document that will allow the STEP export |
| 204 | app = XCAFApp_Application.GetApplication_s() |
| 205 | doc = TDocStd_Document(TCollection_ExtendedString("XmlOcaf")) |
| 206 | app.InitDocument(doc) |
| 207 | |
| 208 | # Shape and color tools |
| 209 | shape_tool = XCAFDoc_DocumentTool.ShapeTool_s(doc.Main()) |
| 210 | color_tool = XCAFDoc_DocumentTool.ColorTool_s(doc.Main()) |
| 211 | layer_tool = XCAFDoc_DocumentTool.LayerTool_s(doc.Main()) |
| 212 | |
| 213 | def _process_child(child: AssemblyProtocol, assy_label: TDF_Label): |
| 214 | """ |
| 215 | Process a child part which is not a subassembly. |
| 216 | :param child: Child part to process (we should already have filtered out subassemblies) |
| 217 | :param assy_label: The label for the assembly to add this part to |
| 218 | :return: None |
| 219 | """ |
| 220 | |
| 221 | child_items = None |
| 222 | |
| 223 | # We combine these because the metadata could be stored at the parent or child level |
| 224 | combined_names = {**assy._subshape_names, **child._subshape_names} |
| 225 | combined_colors = {**assy._subshape_colors, **child._subshape_colors} |
| 226 | combined_layers = {**assy._subshape_layers, **child._subshape_layers} |