コード例 #1
0
 def LoadFile(self,filename):
    extension = os.path.basename(filename).split(".").pop().lower()
    start_time = time.time()
    if extension =="step" or extension == "stp":
        from OCC.Utils.DataExchange.STEP import STEPImporter
        stepReader = STEPImporter(str(filename))
        stepReader.read_file()
        shape = stepReader.get_shapes()
    elif extension == "stl":
        from OCC import TopoDS, StlAPI
        shape = TopoDS.TopoDS_Shape()
        stl_reader = StlAPI.StlAPI_Reader()
        stl_reader.Read(shape,str(filename))
    elif extension =="iges" or extension =="igs":
        from OCC import IGESControl
        i  = IGESControl.IGESControl_Controller()
        i.Init()
        iges_reader = IGESControl.IGESControl_Reader()
        iges_reader.ReadFile(str(filename))
        iges_reader.TransferRoots()
        shape = iges_reader.OneShape()
    elif extension == "brep":
        from OCC import TopoDS, BRep, BRepTools
        shape = TopoDS.TopoDS_Shape()
        builder = BRep.BRep_Builder()
        BRepTools.BRepTools().Read(shape,str(filename),builder)
    else:
        return True
    self.canva._display.DisplayShape(shape)
    end_time = time.time()
    self.SetTitle("CAD Viewer - pythonOCC %s:%s"%(VERSION,filename))
    duration = end_time-start_time
    print "%s STEP file loaded and displayed in %f seconds."%(filename,duration)
コード例 #2
0
 def LoadFile(self, filename):
     extension = os.path.basename(filename).split(".").pop().lower()
     start_time = time.time()
     if extension =="step" or extension == "stp":
         stepReader = STEPControl.STEPControl_Reader()
         stepReader.ReadFile(str(filename))
         numTranslated = stepReader.TransferRoots()
         shape = stepReader.OneShape()
     elif extension == "stl":
         shape = TopoDS.TopoDS_Shape()
         stl_reader = StlAPI.StlAPI_Reader()
         stl_reader.Read(shape,str(filename))
     elif extension =="iges" or extension =="igs":
         i  = IGESControl.IGESControl_Controller()
         i.Init()
         iges_reader = IGESControl.IGESControl_Reader()
         iges_reader.ReadFile(str(filename))
         iges_reader.TransferRoots()
         shape = iges_reader.OneShape()
     elif extension == "brep":
         shape = TopoDS.TopoDS_Shape()
         builder = BRep.BRep_Builder()
         BRepTools.BRepTools().Read(shape,str(filename),builder)
     else:
         return True
     self.canva._3dDisplay.EraseAll()
     self.canva._3dDisplay.DisplayShape(shape)
     wx.SafeYield()
     self.canva._3dDisplay.View_Iso()
     self.canva._3dDisplay.FitAll()
     end_time = time.time()
     self.SetTitle("pythonOCC Interactive Console %s:%s"%(VERSION,filename))
     duration = end_time-start_time
     print "%s STEP file loaded and displayed in %f seconds."%(filename,duration)
コード例 #3
0
ファイル: iges.py プロジェクト: bmjjr/OCCDataExchange
    def write_file(self):
        r"""Write file

        Returns
        -------
        bool

        """
        IGESControl.IGESControl_Controller().Init()
        iges_writer = IGESControl.IGESControl_Writer("write.iges.unit", self._brepmode)
        for shape in self._shapes:
            iges_writer.AddShape(shape)
        iges_writer.ComputeModel()

        write_status = iges_writer.Write(self._filename)

        if write_status == IFSelect.IFSelect_RetDone:
            logger.info("IGES file write successful.")
        else:
            msg = "An error occurred while writing the IGES file"
            logger.error(msg)
            raise ValueError(msg)