def toSTEP(shape, filename, verbose=False, tolerance=0.001): ''' Writes STL output of the solid :param filename: Path of the file to write JSON to :type filename: str :param verbose: Choose if you want to see the STEP stats :type verbose: bool :param tolerance: Provides control over quality of exported STEP. :type tolernace: float ''' class Verboseness(): def __enter__(self): if not verbose: import sys, os sys.stdout.flush() self.newstdout = os.dup(1) self.devnull = os.open('/dev/null', os.O_WRONLY) os.dup2(self.devnull, 1) os.close(self.devnull) sys.stdout = os.fdopen(self.newstdout, 'w') def __exit__(self, type, value, traceback): if not verbose: os.dup2(self.newstdout, 1) with Verboseness(): stepWriter = STEPControl.STEPControl_Writer() stepWriter.SetTolerance(tolerance) if shape: status = stepWriter.Transfer(shape, STEPControl.STEPControl_AsIs) if status: stepWriter.Write(filename)
def __init__(self, filename, verbose=False, schema="AP214CD", tolerance=1e-4): logger.info("StepExporter instantiated with filename : %s" % filename) logger.info("StepExporter schema : %s" % schema) logger.info("StepExporter tolerance : %s" % str(tolerance)) if schema not in ["AP203", "AP214CD"]: msg = "Unsupported STEP schema" logger.error(msg) raise AssertionError(msg) check_exporter_filename(filename, step_extensions) check_overwrite(filename) self._filename = filename self._shapes = list() self.verbose = verbose self._stepcontrol_writer = STEPControl.STEPControl_Writer() self._stepcontrol_writer.SetTolerance(tolerance) Interface.Interface_Static_SetCVal("write.step.schema", schema)
def toSTEP(self, filename, verbose=False, tolerance=0.001): ''' Writes STEP output of the solid :param filename: Path of the file to write STEP to :type filename: str :param verbose: Choose if you want to see the STEP stats :type verbose: bool :param tolerance: Provides control over quality of exported STEP. :type tolernace: float ''' with self._Verboseness(verbose): stepWriter = STEPControl.STEPControl_Writer() stepWriter.SetTolerance(tolerance) if self.shape: status = stepWriter.Transfer(self.shape, STEPControl.STEPControl_AsIs) if status: stepWriter.Write(filename)
def pairs(itr): a,b = tee(itr) b.next() return izip(a,b) points = [(0,0,0), (1,1,1), (0,0,-2), (0,2,0)] vertices = [BRepBuilderAPI.BRepBuilderAPI_MakeVertex(gp.gp_Pnt(*p)) for p in points] #print "verts", vertices #edges = [BRepBuilderAPI.BRepBuilderAPI_MakeEdge(v1.Vertex(),v2.Vertex()) # for v1,v2 in pairs(vertices)] v=vertices edges = [BRepBuilderAPI.BRepBuilderAPI_MakeEdge(v[i].Vertex(),v[j].Vertex()) for i,j, in [(0,1),(0,2),(0,3)] ] #print "edges", edges wire = BRepBuilderAPI.BRepBuilderAPI_MakeWire() for e in edges: wire.Add(e.Edge()) print wire step_export = STEPControl.STEPControl_Writer() step_export.Transfer(wire.Shape(), STEPControl.STEPControl_AsIs) step_export.Write("/home/bryan/test_wire.stp")
#!/usr/bin/python # coding: utf-8 r""" """ from viewer import view from OCC import BRepPrimAPI, STEPControl def get_shape(): box = BRepPrimAPI.BRepPrimAPI_MakeBox(10, 20, 30) shape = box.Shape() return shape shape = get_shape() view(shape) writer = STEPControl.STEPControl_Writer() writer.Transfer(shape, STEPControl.STEPControl_AsIs) writer.Write("test.step")
def export_shapes(shapeList, filename): print(shapeList) step_export = STEPControl.STEPControl_Writer() for shape in shapeList: step_export.Transfer(shape,STEPControl.STEPControl_AsIs) step_export.Write(str(filename))