def add_geom(self, geom, obj, geom_repr=None): from ada.concepts.transforms import Placement from ada.core.vector_utils import vector_length from .utils import transform_shape name = obj.name if obj.name is not None else next(shp_names) Interface_Static_SetCVal("write.step.product.name", name) # Transform geometry res = obj.placement.absolute_placement() if vector_length(res - Placement().origin) > 0: geom = transform_shape(geom, transform=tuple(res)) try: if geom_repr == ElemType.SHELL: stat = self.writer.Transfer( geom, STEPControl_ShellBasedSurfaceModel) else: stat = self.writer.Transfer(geom, STEPControl_AsIs) except BaseException as e: logging.info(f"Passing {obj} due to {e}") return None if int(stat) > int(IFSelect_RetError): raise Exception("Some Error occurred") item = stepconstruct_FindEntity(self.fp, geom) if not item: logging.debug("STEP item not found for FindEntity") else: item.SetName(TCollection_HAsciiString(name))
def AddShape(self, shp, name="shape"): Interface_Static_SetCVal('write.step.product.name', name) status = self.writer.Transfer(shp, STEPControl_AsIs) if int(status) > int(IFSelect_RetError): raise Exception('Some Error occurred') # This portion is not working as I hoped item = stepconstruct_FindEntity(self.fp, shp) if not item: raise Exception('Item not found')
def add_geom(geo, o): name = o.name if o.name is not None else next(shp_names) Interface_Static_SetCVal("write.step.product.name", name) stat = writer.Transfer(geo, STEPControl_AsIs) if int(stat) > int(IFSelect_RetError): raise Exception("Some Error occurred") item = stepconstruct_FindEntity(fp, geo) if not item: logging.debug("STEP item not found for FindEntity") else: item.SetName(TCollection_HAsciiString(name))
def Add(self, shape, name="name"): """ STEPControl_AsIs translates an Open CASCADE shape to its highest possible STEP representation. STEPControl_ManifoldSolidBrep translates an Open CASCADE shape to a STEP manifold_solid_brep or brep_with_voids entity. STEPControl_FacetedBrep translates an Open CASCADE shape into a STEP faceted_brep entity. STEPControl_ShellBasedSurfaceModel translates an Open CASCADE shape into a STEP shell_based_surface_model entity. STEPControl_GeometricCurveSet translates an Open CASCADE shape into a STEP geometric_curve_set entity. """ Interface_Static_SetCVal('write.step.product.name', name) self.stp.Transfer(shape, STEPControl_AsIs) item = stepconstruct_FindEntity(self.app, shape) item.SetName(TCollection_HAsciiString(name))
def Add(self, shape, name="name"): """ STEPControl_AsIs translates an Open CASCADE shape to its highest possible STEP representation. STEPControl_ManifoldSolidBrep translates an Open CASCADE shape to a STEP manifold_solid_brep or brep_with_voids entity. STEPControl_FacetedBrep translates an Open CASCADE shape into a STEP faceted_brep entity. STEPControl_ShellBasedSurfaceModel translates an Open CASCADE shape into a STEP shell_based_surface_model entity. STEPControl_GeometricCurveSet translates an Open CASCADE shape into a STEP geometric_curve_set entity. """ Interface_Static_SetCVal('write.step.product.name', name) status = self.writer.Transfer(shape, STEPControl_AsIs) if int(status) > int(IFSelect_RetError): raise Exception('Some Error occurred') # This portion is not working as I hoped item = stepconstruct_FindEntity(self.fp, shape) if not item: raise Exception('Item not found') item.SetName(TCollection_HAsciiString(name))
writer = STEPControl_Writer() fp = writer.WS().TransferWriter().FinderProcess() Interface_Static_SetCVal('write.step.schema', schema) Interface_Static_SetCVal('write.step.unit', 'M') Interface_Static_SetCVal('write.step.assembly', str(assembly_mode)) my_box1 = BRepPrimAPI_MakeBox(10., 20., 30.).Shape() my_box2 = BRepPrimAPI_MakeBox(20., 1., 30.).Shape() components = [my_box1, my_box2] comp_names = ['PartA', 'PartB'] for i, comp in enumerate(components): Interface_Static_SetCVal('write.step.product.name', comp_names[i]) status = writer.Transfer(comp, STEPControl_AsIs) if int(status) > int(IFSelect_RetError): raise Exception('Some Error occurred') # This portion is not working as I hoped item = stepconstruct_FindEntity(fp, comp) if not item: raise Exception('Item not found') item.SetName(TCollection_HAsciiString(comp_names[i])) status = writer.Write('step_export_with_name.stp') if int(status) > int(IFSelect_RetError): raise Exception('Something bad happened') read_step_file_with_names_colors('step_export_with_name.stp')