Ejemplo n.º 1
0
 def write_file(self):
     r"""Write file"""
     mesh = BRepMesh_IncrementalMesh(
         self._shape, self._line_deflection, self._is_relative,
         self._angular_deflection, self._in_parallel)
     mesh.Perform()
     stl_writer = StlAPI.StlAPI_Writer()
     stl_writer.SetASCIIMode(self._ascii_mode)
     stl_writer.Write(self._shape, self._filename)
     logger.info("Wrote STL file")
Ejemplo n.º 2
0
    def toSTL(self, filename, ascii=False, deflection=0.01):
        '''
    Writes STL output of the solid

    :param filename: Path of the file to write JSON to
    :type filename: str
    :param ascii: choose between ASCII or Binary STL format
    :type ascii: bool
    :param deflection: Provides control over quality of exported STL. Higher the deflection value, lower the accuracy of exported STL, smaller the size of resulting file. Lower the deflection value, more accurate the exported STL, bigger the size of resulting file.
    :type deflection: float
    '''
        stl_writer = StlAPI.StlAPI_Writer()
        stl_writer.SetASCIIMode(ascii)
        stl_writer.SetDeflection(deflection)
        stl_writer.Write(self.shape, filename)
Ejemplo n.º 3
0
def shape_to_file(shape, pth, filename, format='iges'):
    '''write a Shape to a .iges .brep .stl or .step file'''
    _pth = os.path.join(pth, filename)
    assert not os.path.isdir(_pth), 'wrong path, filename'
    _file = "%s.%s" % (_pth, format)

    _formats = ['iges', 'igs', 'step', 'stp', 'brep', 'stl']
    assert format in _formats, '%s is not a readable format, should be one of %s ' % (
        format, _formats)

    if format in ['iges', 'igs']:
        i = IGESControl_Controller()
        i.Init()
        writer = IGESControl_Writer()
        writer.AddShape(shape)
        writer.Write(_file)
        return _file

    elif format in ['step', 'stp']:
        i = STEPControl_Controller()
        i.Init()
        writer = STEPControl_Writer()
        writer.Transfer(shape, STEPControl_AsIs)
        writer.Write(_file)
        return _file

    elif format == 'brep':
        from OCC import TopoDS, BRep, BRepTools
        #shape = TopoDS.TopoDS_Shape()
        builder = BRep.BRep_Builder()
        BRepTools.BRepTools().Write(shape, _file)

    elif format == 'stl':
        from OCC import TopoDS, StlAPI
        #shape = TopoDS.TopoDS_Shape()
        stl_reader = StlAPI.StlAPI_Writer()
        stl_reader.Read(shape, _file)

    else:
        raise TypeError(
            'format should be one of [iges,igs], [step,stp], brep, stl\ngot %s'
            % (format))
Ejemplo n.º 4
0
'''
xform = gp_Trsf()
xform.SetValues(
  1.5, 0, 0, 0,
  0, 1, 0, 0,
  0, 0, 1, 0,
  Precision_Angular(), Precision_Confusion()
);
brep = BRepBuilderAPI_GTransform(shape, gp_GTrsf(xform), False)
'''

# This options works as desired
xform = gp_GTrsf()
xform.SetVectorialPart(gp_Mat(
    1.5,
    0,
    0,
    0,
    1,
    0,
    0,
    0,
    1,
))
brep = BRepBuilderAPI_GTransform(shape, xform, False)
brep.Build()
shape = brep.Shape()

stl_writer = StlAPI.StlAPI_Writer()
stl_writer.Write(shape, 'scaled-cylinder.stl')
Ejemplo n.º 5
0
def toSTL(shape, filename, ascii=False, deflection=0.001):
    stl_writer = StlAPI.StlAPI_Writer()
    stl_writer.SetASCIIMode(ascii)
    stl_writer.SetDeflection(deflection)
    stl_writer.Write(shape, filename)