Exemplo n.º 1
0
    def item(self, index: cat_variant) -> any_parameter:
        """
        .. note::
            :class: toggle

            CAA V5 Visual Basic help
                | Item
                | o Func Item(    CATVariant    iIndex) As Parameter
                |
                | Retrieves a parameter  using its index or its name from the from the
                | Parameters collection.
                | Parameters:
                | iIndex
                |    The index or the name of the parameter to retrieve from
                |    the collection of parameters.
                |    As a numeric, this index is the rank of the parameter
                |    in the collection.
                |    The index of the first parameter in the collection is 1, and
                |    the index of the last parameter is Count.
                |    As a string, it is the name you assigned to the parameter using
                |    the
                |
                |  activateLinkAnchor('AnyObject','Name','AnyObject.Name')  property or when
                |  creating the parameter.
                | Examples:
                | This example retrieves the last parameter in the parameters
                | collection:
                |
                | Set lastParameter = parameters.Item(parameters.Count)


        :param cat_variant index:
        :return: any_parameter
        :rtype: any_parameter
        """

        p: any_parameter

        if not self.is_parameter(index):
            raise CATIAApplicationException(
                f'Could not find parameter name "{index}".')

        if isinstance(self.parameters.Item(index).value, bool):
            p = BoolParam(self.parameters.Item(index))

        elif isinstance(self.parameters.Item(index).value, int):
            p = IntParam(self.parameters.Item(index))

        elif isinstance(self.parameters.Item(index).value, str):
            p = StrParam(self.parameters.Item(index))

        elif isinstance(self.parameters.Item(index).value, float):
            p = RealParam(self.parameters.Item(index))

        else:

            raise CATIAApplicationException(
                f'Could not assign parameter name "{index}".')

        return p
Exemplo n.º 2
0
    def paper_size(self, paper_size):

        try:
            self.sheet.PaperSize = paper_size
        except com_error:
            raise CATIAApplicationException(
                'Ensure paper_size is available for the drawing standard.')
Exemplo n.º 3
0
 def part(self):
     """
     :return: Part()
     """
     try:
         return Part(self.document.Part)
     except AttributeError:
         raise CATIAApplicationException('Is document .CATPart?')
Exemplo n.º 4
0
 def drawing_root(self) -> DrawingRoot:
     """
     :return: DrawingRoot
     :rtype: DrawingRoot
     """
     try:
         return DrawingRoot(self.document.DrawingRoot)
     except AttributeError:
         raise CATIAApplicationException('Is document a Drawing?')
Exemplo n.º 5
0
    def __init__(self, document_com_object):

        super().__init__(document_com_object)
        try:
            self.document = document_com_object.ActiveDocument
            self.catia = document_com_object
        except com_error:
            message = "Could not activate document. Is a document open?"
            raise CATIAApplicationException(message)
Exemplo n.º 6
0
def initialise():
    """

    :return:
    """
    documents = catia.documents
    if documents.count > 0:
        raise CATIAApplicationException('Please close all documents before running tests.')

    return catia, documents
Exemplo n.º 7
0
    def export_data(self, file_name: Path, file_type: str, overwrite=False) -> None:
        """
        .. note::
            :class: toggle

            CAA V5 Visual Basic help

            Sub ExportData( CATBSTR  fileName, CATBSTR  format)

            | Exports the data contained in the document to another format.
            | Parameters:
            |   fileName
            |       The name of the exported file
            |   format
            |       The name of the format
            | Example:
            |   This example writes the Doc document in the IGES format under the IGESDoc name.
            |       Doc.ExportData("IGESDoc", "igs")


        :param Path file_name: file_name including full path.
        :param str file_type: file_type is the extension of required file_type.
                              The file_type must be supported by CATIA and the CATIA license.
        :param bool overwrite: Files will not be overwritten unless is True.
        :return:
        """
        current_dfa_setting = self.document.Application.DisplayFileAlerts
        if not isinstance(file_name, Path):
            file_name = Path(file_name)

        if file_name.suffix.lower() != '.' + file_type.lower():
            raise CATIAApplicationException(
                f'Filename "{file_name}" must have the same suffix as filetype "{file_type}".')

        # add filetype to filename if it hasn't been added correctly.
        if not str(file_name).endswith(file_type):
            file_name = Path(f"{file_name}.{file_type}")

        if not file_name.parent.is_dir():
            raise NotADirectoryError(f'Directory: {file_name.parent} is not a directory.')

        if overwrite is False and file_name.is_file():
            raise FileExistsError(f'File: {file_name} already exists. '
                                  f'Set overwrite=True if you want to overwrite.')

        # pycatia prefers full path names :-)
        if not file_name.is_absolute():
            self.logger.warning('To prevent unexpected behaviour, be explicit and use absolute filenames.')

        self.document.ExportData(file_name, file_type)

        self.document.Application.DisplayFileAlerts = current_dfa_setting
Exemplo n.º 8
0
    def open(self, file_name: str) -> Document:
        """
        .. note::
            :class: toggle

            CAA V5 Visual Basic Help (2020-06-11 12:40:47.360445))
                | o Func Open(CATBSTR iFileName) As Document
                |
                |     Opens a document stored in a file. Reads a document stored in a file,
                |     displays it in a new window, adds the document to the documents collection and
                |     the window to the windows collection, and makes both the document and the
                |     window the active ones.
                |
                |     Parameters:
                |
                |         iFileName
                |             The name of the file containing the document
                |
                |     Returns:
                |         The retrieved document
                |     Example:
                |         The following example opens the Doc document contained in the
                |         FileToOpen file.
                |
                |          FileToOpen = "e:\\users\\psr\\Parts\\ThisIsANicePart.CATPart"
                |          Dim Doc As Document
                |          Set Doc = Documents.Open(FileToOpen)

        :param str file_name:
        :return: Document
        :rtype: Document
        """

        if not os.path.isfile(file_name):
            raise FileNotFoundError(f'Could not find file {file_name}.')

        # get the full path to the file
        file_name = os.path.abspath(file_name)

        try:
            self.logger.info(f'Opening document "{file_name}".')
            return Document(self.documents.Open(file_name))
        except com_error:
            raise CATIAApplicationException(
                f'Could not open document "{file_name}". '
                'Check file type and ensure the version of CATIA it was created with is compatible.'
            )
Exemplo n.º 9
0
    def get_hybrid_body_by_name(self, name):
        """

        :return: HybridBody COM object if found otherwise None.
        """

        hybrid_body = None

        for hybrid_body_name in self.get_hybrid_bodies_names():
            if name == hybrid_body_name:
                hybrid_body = self.part.HybridBodies.Item(name)

        if hybrid_body is None:
            raise CATIAApplicationException(
                f'Could not find hybrid_body name "{name}".')

        return hybrid_body
Exemplo n.º 10
0
    def item(self, index: cat_variant) -> Document:
        """
        .. note::
            :class: toggle

            CAA V5 Visual Basic Help (2020-06-11 12:40:47.360445))
                | o Func Item(CATVariant iIndex) As Document
                |
                |     Returns a document using its index or its name from the documents
                |     collection.
                |
                |     Parameters:
                |
                |         iIndex
                |             The index or the name of the document to retrieve frm the
                |             collection of documents. As a numerics, this index is the rank of the document
                |             in the collection. The index of the first document in the collection is 1, and
                |             the index of the last document is Count. As a string, it is the name you
                |             assigned to the document using the
                |
                |         AnyObject.Name property.
                |     Returns:
                |         The retrieved document
                |     Example:
                |         This example retrieves in ThisDoc the fifth document in the collection
                |         and in ThatDoc the document named MyDoc.
                |
                |          Dim ThisDoc As Document
                |          Set ThisDoc = Documents.Item(5)
                |          Dim ThatDoc As Document
                |          Set ThatDoc = Documents.Item("MyDoc")

        :param cat_variant index:
        :return: Document
        :rtype: Document
        """
        try:
            return Document(self.documents.Item(index))
        except com_error:
            raise CATIAApplicationException(f'Could not get item "{index}".')
Exemplo n.º 11
0
    def count_types(self, file_type_list: list_str) -> int:
        """
        Returns the number of documents which presents special file extensions like:
            'catpart', 'catdrawing', 'catproduct', 'catmaterial', 'catalog', 'catfct'


        :param list_str file_type_list: filetype(s) to count. can be list or string.
        :return: int()
        """

        items = self.get_item_names()

        if isinstance(file_type_list, str):
            type_list = [elem.lower() for elem in [file_type_list]]
        elif isinstance(file_type_list, list):
            type_list = [elem.lower() for elem in file_type_list]
        else:
            raise CATIAApplicationException(
                f'File type list {file_type_list} not valid type.')

        return len([
            True for name in items for typ in type_list
            if name.lower().find(typ) > 0
        ])
Exemplo n.º 12
0
from pycatia.enumeration.enumeration_types import cat_text_anchor_position
from pycatia.enumeration.enumeration_types import cat_paper_orientation
from pycatia.enumeration.enumeration_types import cat_paper_size

# A0 sheet size
a0_x = 1189
a0_y = 841

caa = catia()
document = caa.active_document
drawing = document.drawing_root()
sheets = drawing.sheets
sheet = sheets.active_sheet

if cat_paper_orientation[sheet.orientation] != 'catPaperLandscape':
    raise CATIAApplicationException('Sheet orientation is not landscape.')

if cat_paper_size[sheet.paper_size] != 'catPaperA0':
    raise CATIAApplicationException('Sheet size is not A0.')

views = sheet.views
main_view = views.get_item_by_name('Main View')
background_view = views.get_item_by_name('Background View')
background_view.activate()
factory_2d = background_view.factory_2d

# create the outside border at page limits.
# bottom
ob_line_1 = factory_2d.create_line(0, 0, a0_x, 0)
ob_line_2 = factory_2d.create_line(a0_x, 0, a0_x, a0_y)
ob_line_3 = factory_2d.create_line(a0_x, a0_y, 0, a0_y)
Exemplo n.º 13
0
    def item(self, index):
        """

        .. warning::

            The index when not a string must be it's python index (indexs in python start from 0).
            collection. The COM interface index starts at 1.

        .. note::
            CAA V5 Visual Basic help

                | Item
                | o Func Item(    CATVariant    iIndex) As Parameter
                |
                | Retrieves a parameter  using its index or its name from the from the
                | Parameters collection.

                | Parameters:
                | iIndex
                |    The index or the name of the parameter to retrieve from
                |    the collection of parameters.
                |    As a numerics, this index is the rank of the parameter
                |    in the collection.
                |    The index of the first parameter in the collection is 1, and
                |    the index of the last parameter is Count.
                |    As a string, it is the name you assigned to the parameter using
                |    the
                |
                |  activateLinkAnchor('AnyObject','Name','AnyObject.Name')  property or when
                |  creating the parameter.

                | Examples:
                | This example retrieves the last parameter in the parameters
                | collection:
                |
                | Set lastParameter = parameters.Item(parameters.Count)

        """

        if isinstance(index, int):
            index += 1

        parameter = None

        if not self.is_parameter(index):
            raise CATIAApplicationException(
                f'Could not find parameter name "{index}".')

        if isinstance(self.parameters.Item(index).value, bool):
            parameter = BoolParam(self.parameters.Item(index))

        elif isinstance(self.parameters.Item(index).value, int):
            parameter = IntParam(self.parameters.Item(index))

        elif isinstance(self.parameters.Item(index).value, str):
            parameter = StrParam(self.parameters.Item(index))

        elif isinstance(self.parameters.Item(index).value, float):
            parameter = RealParam(self.parameters.Item(index))

        return parameter