Beispiel #1
0
 def load_iges(self, path):
     """ Load an iges model """
     reader = IGESControl_Reader()
     status = reader.ReadFile(path)
     if status != IFSelect_RetDone:
         raise ValueError("Failed to load: {}".format(path))
     reader.PrintCheckLoad(False, IFSelect_ItemsByEntity)
     reader.PrintCheckTransfer(False, IFSelect_ItemsByEntity)
     ok = reader.TransferRoots()
     return reader.Shape(1)
Beispiel #2
0
def read_iges_file(filename, return_as_shapes=False, verbosity=False):
    """ read the IGES file and returns a compound
    filename: the file path
    return_as_shapes: optional, False by default. If True returns a list of shapes,
                      else returns a single compound
    verbosity: optionl, False by default.
    """
    assert os.path.isfile(filename)

    iges_reader = IGESControl_Reader()
    status = iges_reader.ReadFile(filename)

    _shapes = []

    if status == IFSelect_RetDone:  # check status
        if verbosity:
            failsonly = False
            iges_reader.PrintCheckLoad(failsonly, IFSelect_ItemsByEntity)
            iges_reader.PrintCheckTransfer(failsonly, IFSelect_ItemsByEntity)
        iges_reader.TransferRoots()
        nbr = iges_reader.NbRootsForTransfer()
        for n in range(1, nbr + 1):
            nbs = iges_reader.NbShapes()
            if nbs == 0:
                print("At least one shape in IGES cannot be transfered")
            elif nbr == 1 and nbs == 1:
                aResShape = iges_reader.Shape(1)
                if aResShape.IsNull():
                    print("At least one shape in IGES cannot be transferred")
                else:
                    _shapes.append(aResShape)
            else:
                for i in range(1, nbs + 1):
                    aShape = iges_reader.Shape(i)
                    if aShape.IsNull():
                        print(
                            "At least one shape in STEP cannot be transferred")
                    else:
                        _shapes.append(aShape)
    # if not return as shapes
    # create a compound and store all shapes
    # TODO
    if not return_as_shapes:
        builder = BRep_Builder()
        Comp = TopoDS_Compound()
        builder.MakeCompound(Comp)
        for s in _shapes:
            builder.Add(Comp, s)
        _shapes = Comp
    return _shapes
Beispiel #3
0
def read_iges(file_name):
    iges_reader = IGESControl_Reader()
    status = iges_reader.ReadFile(file_name)

    if status == IFSelect_RetDone:
        failsonly = False
        iges_reader.PrintCheckLoad(failsonly, IFSelect_ItemsByEntity)
        iges_reader.PrintCheckTransfer(failsonly, IFSelect_ItemsByEntity)
        ok = iges_reader.TransferRoots()
        IgesShape = iges_reader.OneShape()
        return IgesShape
    else:
        print("Error: can't read file.")
        sys.exit(0)
Beispiel #4
0
def iges_importer(path_):
    from OCC.IGESControl import IGESControl_Reader
    from OCC.IFSelect import IFSelect_RetDone, IFSelect_ItemsByEntity
    iges_reader = IGESControl_Reader()
    status = iges_reader.ReadFile(path_)

    if status == IFSelect_RetDone:  # check status
        failsonly = False
        iges_reader.PrintCheckLoad(failsonly, IFSelect_ItemsByEntity)
        iges_reader.PrintCheckTransfer(failsonly, IFSelect_ItemsByEntity)
        ok = iges_reader.TransferRoots()
        aResShape = iges_reader.Shape(1)
        return aResShape
    else:
        raise AssertionError("could not import IGES file: {0}".format(path_))
 def read_file(self):
     """
     Read the IGES file and stores the result in a list of TopoDS_Shape
     """
     aReader = IGESControl_Reader()
     status = aReader.ReadFile(self._filename)
     if status == IFSelect_RetDone:
         failsonly = False
         aReader.PrintCheckLoad(failsonly, IFSelect_ItemsByEntity)
         nbr = aReader.NbRootsForTransfer()
         aReader.PrintCheckTransfer(failsonly, IFSelect_ItemsByEntity)
         # ok = aReader.TransferRoots()
         for n in range(1, nbr + 1):
             self.nbs = aReader.NbShapes()
             if self.nbs == 0:
                 print("At least one shape in IGES cannot be transfered")
             elif nbr == 1 and self.nbs == 1:
                 aResShape = aReader.Shape(1)
                 if aResShape.IsNull():
                     print(
                         "At least one shape in IGES cannot be transferred")
                 self._shapes.append(aResShape)
             else:
                 for i in range(1, self.nbs + 1):
                     aShape = aReader.Shape(i)
                     if aShape.IsNull():
                         print(
                             "At least one shape in STEP cannot be transferred"
                         )
                     else:
                         self._shapes.append(aShape)
         return True
     else:
         print("Error: can't read file %s" % self._filename)
         return False
     return False
#!/usr/bin/python
# coding: utf-8

r"""
"""

from __future__ import print_function

import sys

from OCC.IGESControl import IGESControl_Reader
from OCC.IFSelect import IFSelect_RetDone, IFSelect_ItemsByEntity
from OCC.Display.SimpleGui import init_display

iges_reader = IGESControl_Reader()
status = iges_reader.ReadFile('./models/surf114.igs')

if status == IFSelect_RetDone:  # check status
    failsonly = False
    iges_reader.PrintCheckLoad(failsonly, IFSelect_ItemsByEntity)
    iges_reader.PrintCheckTransfer(failsonly, IFSelect_ItemsByEntity)
    ok = iges_reader.TransferRoots()
    aResShape = iges_reader.Shape(1)
else:
    print("Error: can't read file.")
    sys.exit(0)
display, start_display, add_menu, add_function_to_menu = init_display('wx')
display.DisplayShape(aResShape, update=True)
start_display()