From 47bccacd2979f3228360da92c46227537314d2f0 Mon Sep 17 00:00:00 2001 From: evereux Date: Thu, 6 Jun 2024 09:39:26 +0100 Subject: [PATCH 1/8] added test for documents.read() --- tests/in/test_document.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/in/test_document.py b/tests/in/test_document.py index 9325be31..f66ef42b 100644 --- a/tests/in/test_document.py +++ b/tests/in/test_document.py @@ -195,6 +195,12 @@ def test_open_document(): assert document.name == cat_part_measurable.name assert f'PartDocument(name="{document.name}")' == document.__repr__() +def test_read_document(): + + documents = caa.documents + document = documents.read(cat_part_measurable) + + assert type(document) == PartDocument def test_part(): with CATIADocHandler(cat_part_measurable) as caa: From 7e41254695b28a678e1316cfe5d5acc779316e18 Mon Sep 17 00:00:00 2001 From: evereux Date: Thu, 6 Jun 2024 10:27:14 +0100 Subject: [PATCH 2/8] updated tests to handle path objects --- pycatia/in_interfaces/documents.py | 37 +++++++++++++++++------------- tests/in/test_application.py | 4 ++-- tests/in/test_document.py | 8 ++++--- 3 files changed, 28 insertions(+), 21 deletions(-) diff --git a/pycatia/in_interfaces/documents.py b/pycatia/in_interfaces/documents.py index 88e16ac0..a4c2105b 100644 --- a/pycatia/in_interfaces/documents.py +++ b/pycatia/in_interfaces/documents.py @@ -1,6 +1,7 @@ #! /usr/bin/python3.9 from typing import Iterator import os +from pathlib import Path import warnings from pywintypes import com_error @@ -116,7 +117,7 @@ def count_types(self, file_type_list: list_str) -> int: return len([True for name in items for typ in type_list if name.lower().find(typ) > 0]) - def new_from(self, file_name: str) -> Document: + def new_from(self, file_name: Path) -> Document: """ .. note:: :class: toggle @@ -145,15 +146,18 @@ def new_from(self, file_name: str) -> Document: | Dim Doc As Document | Set Doc = Documents.NewFrom(FileToRead) - :param str file_name: + :param Path file_name: :rtype: Document """ - if not os.path.isfile(file_name): - raise FileNotFoundError(f'Could not find file {file_name}.') + # legacy support for < 0.7.1 where file_name could be a string. + if isinstance(file_name, str): + if not os.path.isfile(file_name): + raise FileNotFoundError(f'Could not find file {file_name}.') + else: + if not file_name.is_file: + raise FileNotFoundError(f'Could not find file {file_name}.') - # get the full path to the file - file_name = os.path.abspath(file_name) return Document(self.documents.NewFrom(file_name)) @@ -221,7 +225,7 @@ def num_open(self) -> int: warnings.warn(warning_string) return self.documents.Count - def open(self, file_name: str) -> Document: + def open(self, file_name: Path) -> Document: """ .. note:: :class: toggle @@ -249,15 +253,16 @@ def open(self, file_name: str) -> Document: | Dim Doc As Document | Set Doc = Documents.Open(FileToOpen) - :param str file_name: + :param Path file_name: :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) + # legacy support for < 0.7.1 where file_name could be a string. + if isinstance(file_name, str): + if not os.path.isfile(file_name): + raise FileNotFoundError(f'Could not find file {file_name}.') + else: + if not file_name.is_file: + raise FileNotFoundError(f'Could not find file {file_name}.') try: self.logger.info(f'Opening document "{file_name}".') @@ -267,7 +272,7 @@ def open(self, file_name: str) -> Document: f'Could not open document "{file_name}". ' 'Check file type and ensure the version of CATIA it was created with is compatible.') - def read(self, file_name: str) -> Document: + def read(self, file_name: Path) -> Document: """ .. note:: :class: toggle @@ -305,7 +310,7 @@ def read(self, file_name: str) -> Document: # return Document(self.documents.Read(file_name)) read_doc_com = self.documents.Read(file_name) - extension = file_name.split('.')[-1] + extension = file_name.suffix[1:] types = [document_types[k]['type'] for k in (document_types) if document_types[k]['extension'] == extension] document_type = types[0] return document_type(read_doc_com) diff --git a/tests/in/test_application.py b/tests/in/test_application.py index ecd27ee3..fda4a6ba 100644 --- a/tests/in/test_application.py +++ b/tests/in/test_application.py @@ -10,7 +10,7 @@ def test_application(): def test_refresh(): documents = caa.documents - documents.open(str(cat_part_measurable)) + documents.open(cat_part_measurable) document = caa.active_document caa.refresh_display = False @@ -24,7 +24,7 @@ def test_refresh(): def test_visible(): documents = caa.documents - documents.open(str(cat_part_measurable)) + documents.open(cat_part_measurable) document = caa.active_document caa.visible = False diff --git a/tests/in/test_document.py b/tests/in/test_document.py index f66ef42b..ddee0169 100644 --- a/tests/in/test_document.py +++ b/tests/in/test_document.py @@ -21,9 +21,9 @@ def test_activate_document(): documents = caa.documents - documents.open(str(cat_part_measurable)) + documents.open(cat_part_measurable) document_part = caa.active_document - documents.open(str(cat_product)) + documents.open(cat_product) document_product = caa.active_document assert document_part.name == os.path.basename(cat_part_measurable) @@ -160,7 +160,7 @@ def test_item(): def test_new_from(): documents = caa.documents - document = documents.new_from(str(cat_part_measurable)) + document = documents.new_from(cat_part_measurable) assert document.name is not os.path.basename(cat_part_measurable) @@ -202,6 +202,8 @@ def test_read_document(): assert type(document) == PartDocument + document.close + def test_part(): with CATIADocHandler(cat_part_measurable) as caa: document = caa.document From c9d1feda087c4cdc462f4073047c961fa02ff258 Mon Sep 17 00:00:00 2001 From: evereux Date: Thu, 6 Jun 2024 10:27:39 +0100 Subject: [PATCH 3/8] updated changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d7f2f066..dc972b22 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## 0.7.1 * fixed Documents.read() method which was broken by changes made in 0.6.9. +* updated Documents.open() so that filename should now be a Path object. +* updated Documents.new_from() so that filename should now be a Path object. +* updated Documents.open() so that filename should now be a Path object. + ## 0.7.0 * fixed the following Class methods so that the Reference.com_object is passed to From 683d0a9c01b458db01a5e4f9933ba5eba9deb4da Mon Sep 17 00:00:00 2001 From: evereux Date: Thu, 6 Jun 2024 14:03:22 +0100 Subject: [PATCH 4/8] updated examples to better show how to initialise documents --- examples/example__assembly_convertor__001.py | 11 ++-------- examples/example__bom_custom_001.py | 11 ++-------- examples/example__constraints_001.py | 12 +++-------- examples/example__document__001.py | 4 ++-- examples/example__document__003.py | 15 +++++++------ examples/example__drafting__001.py | 11 +++------- examples/example__human_modelling__001.py | 13 +++--------- examples/example__hybrid_bodies__001.py | 12 +++-------- .../example__hybrid_shape_factory__001.py | 12 +++-------- .../example__hybrid_shape_factory__002.py | 13 ++---------- .../example__hybrid_shape_factory__003.py | 12 ++--------- .../example__hybrid_shape_factory__004.py | 18 ++++++---------- .../example__hybrid_shape_factory__005.py | 12 +++-------- .../example__hybrid_shape_factory__006.py | 14 ++++--------- ...ybrid_shape_factory__shape_factory__001.py | 17 ++++----------- ...mple__hybrid_sketch__shape_factory__001.py | 12 ++--------- examples/example__inertia__001.py | 12 +++++------ examples/example__material__001.py | 5 +++-- examples/example__parameters__001.py | 16 ++++---------- examples/example__parameters__002.py | 18 +++++----------- examples/example__product__001.py | 15 ++++--------- examples/example__product__002.py | 13 +++--------- examples/example__product__003.py | 13 +++--------- examples/example__product__004.py | 15 ++++--------- examples/example__product__005.py | 14 +++---------- examples/example__product__006.py | 11 ++-------- examples/example__selection__001.py | 16 +++++--------- examples/example__selection__002.py | 10 ++++----- examples/example__selection__003.py | 21 +++++++------------ examples/example__shape_factory__001.py | 12 ++--------- examples/example__shape_factory__002.py | 6 +++--- examples/example__space_analysis__001.py | 17 +++++---------- examples/example__space_analysis__002.py | 17 +++++---------- examples/example__space_analysis__003.py | 20 ++++++------------ .../example__specs_and_geom_window__001.py | 12 +++-------- examples/example__visual_properties__001.py | 1 - 36 files changed, 129 insertions(+), 334 deletions(-) diff --git a/examples/example__assembly_convertor__001.py b/examples/example__assembly_convertor__001.py index e1ac8166..0d3788b2 100644 --- a/examples/example__assembly_convertor__001.py +++ b/examples/example__assembly_convertor__001.py @@ -33,21 +33,14 @@ from pycatia import catia from pycatia.product_structure_interfaces.assembly_convertor import AssemblyConvertor -from pycatia.product_structure_interfaces.product import Product from pycatia.product_structure_interfaces.product_document import ProductDocument # file_type can be "TXT", "HTML" or "XLS". file_type = "XLS" caa = catia() -document = ProductDocument(caa.active_document.com_object) -product = Product(document.product.com_object) -# Note: It's not necessary to explicitly use the ProductDocument or the Product class -# with the com_object. It's perfectly fine to write it like this: -# document = caa.active_document -# product = document.product -# But declaring 'document' and 'product' this way, your linter can't resolve the -# product reference, see https://github.com/evereux/pycatia/issues/107#issuecomment-1336195688 +product_document = ProductDocument(caa.active_document.com_object) +product = product_document.product bom = product.get_item("BillOfMaterial") assembly_convertor = AssemblyConvertor(bom.com_object) diff --git a/examples/example__bom_custom_001.py b/examples/example__bom_custom_001.py index f5372611..c2042b6a 100644 --- a/examples/example__bom_custom_001.py +++ b/examples/example__bom_custom_001.py @@ -25,19 +25,12 @@ from datetime import datetime from pycatia import catia -from pycatia.product_structure_interfaces.product import Product from pycatia.product_structure_interfaces.product_document import ProductDocument caa = catia() -document = ProductDocument(caa.active_document.com_object).product -product = Product(document.com_object) +product_document: ProductDocument = caa.active_document +product = product_document.product products = product.products -# Note: It's not necessary to explicitly use the ProductDocument or the Product class -# with the com_object. It's perfectly fine to write it like this: -# document = caa.active_document -# product = document.product -# But declaring 'document' and 'product' this way, your linter can't resolve the -# product reference, see https://github.com/evereux/pycatia/issues/107#issuecomment-1336195688 part_numbers = [] prd_dict = {} diff --git a/examples/example__constraints_001.py b/examples/example__constraints_001.py index de0ca31f..369d5400 100644 --- a/examples/example__constraints_001.py +++ b/examples/example__constraints_001.py @@ -24,18 +24,12 @@ from pycatia import catia from pycatia.enumeration.enumeration_types import cat_constraint_type -from pycatia.product_structure_interfaces.product import Product from pycatia.product_structure_interfaces.product_document import ProductDocument caa = catia() -document = ProductDocument(caa.active_document.com_object).product -product = Product(document.com_object) -# Note: It's not necessary to explicitly use the ProductDocument or the Product class -# with the com_object. It's perfectly fine to write it like this: -# document = caa.active_document -# product = document.product -# But declaring 'document' and 'product' this way, your linter can't resolve the -# product reference, see https://github.com/evereux/pycatia/issues/107#issuecomment-1336195688 +# if the active document is a CATProduct this will return a ProductDocument +product_document: ProductDocument = caa.active_document +product = product_document.product products = product.products constraints = product.constraints() diff --git a/examples/example__document__001.py b/examples/example__document__001.py index ffadcb69..2b579799 100644 --- a/examples/example__document__001.py +++ b/examples/example__document__001.py @@ -21,12 +21,12 @@ sys.path.insert(0, os.path.abspath("..\\pycatia")) ########################################################## - +from pathlib import Path import time from pycatia import CATIADocHandler -catia_part = r"tests\cat_files\part_measurable.CATPart" +catia_part = Path(os.getcwd(), r"tests\cat_files\part_measurable.CATPart") with CATIADocHandler(catia_part) as caa: document = caa.document diff --git a/examples/example__document__003.py b/examples/example__document__003.py index 349bcc9b..f11a704e 100644 --- a/examples/example__document__003.py +++ b/examples/example__document__003.py @@ -26,27 +26,26 @@ from pathlib import Path from pycatia import catia -from pycatia.in_interfaces.document import Document +from pycatia.mec_mod_interfaces.part_document import PartDocument # path to file to open. -file_name = r"tests\cat_files\part_measurable.CATPart" +file_name = Path(os.getcwd(), r"tests\cat_files\part_measurable.CATPart") caa = catia() # open document documents = caa.documents -documents.open(file_name) +part_document: PartDocument = documents.open(file_name) -document = caa.active_document -assert isinstance(document, Document) +assert isinstance(part_document, PartDocument) # _Full_ path of new file. This uses current working directory. new_file_name = Path(os.getcwd(), "new_part.CATPart") # save document as new name. -document.save_as(new_file_name, overwrite=True) +part_document.save_as(new_file_name, overwrite=True) # to export to another support file_format (license permitting). new_export_file_name = Path("c:\\temp\\new_export_part.stp") -document.export_data(new_export_file_name, "stp", overwrite=True) +part_document.export_data(new_export_file_name, "stp", overwrite=True) # close document -document.close() +part_document.close() diff --git a/examples/example__drafting__001.py b/examples/example__drafting__001.py index 4f05b781..95f8338e 100644 --- a/examples/example__drafting__001.py +++ b/examples/example__drafting__001.py @@ -36,14 +36,9 @@ a0_y = 841 caa = catia() -document = DrawingDocument(caa.active_document.com_object) -drawing = DrawingRoot(document.drawing_root.com_object) -# Note: It's not necessary to explicitly use the DrawingDocument or the DrawingRoot class -# with the com_object. It's perfectly fine to write it like this: -# document = caa.active_document -# drawing = document.drawing_root -# But declaring 'document' and 'drawing_root' this way, your linter can't resolve the -# product reference, see https://github.com/evereux/pycatia/issues/107#issuecomment-1336195688 +# if the active document is a CATDrawing this will return a DrawingDocument +drawing_document: DrawingDocument = caa.active_document +drawing = DrawingRoot(drawing_document.drawing_root.com_object) sheets = drawing.sheets sheet = sheets.active_sheet diff --git a/examples/example__human_modelling__001.py b/examples/example__human_modelling__001.py index fdd47a66..d5b59d04 100644 --- a/examples/example__human_modelling__001.py +++ b/examples/example__human_modelling__001.py @@ -22,20 +22,13 @@ from pycatia import catia from pycatia.enumeration.enumeration_types import swk_anthro_sex from pycatia.enumeration.enumeration_types import swk_posture_spec -from pycatia.product_structure_interfaces.product import Product from pycatia.product_structure_interfaces.product_document import ProductDocument from pycatia.dnb_human_modeling_interfaces.swk_hmi_workbench import SWKHmiWorkbench caa = catia() -document = ProductDocument(caa.active_document.com_object) -product = Product(document.product.com_object) -# Note: It's not necessary to explicitly use the ProductDocument or the Product class -# with the com_object. It's perfectly fine to write it like this: -# document = caa.active_document -# product = document.product -# But declaring 'document' and 'product' this way, your linter can't resolve the -# product reference, see https://github.com/evereux/pycatia/issues/107#issuecomment-1336195688 - +# if the active document is a CATProduct this will return a ProductDocument +product_document: ProductDocument = caa.active_document +product = product_document.product human_work_bench = SWKHmiWorkbench(product.get_technological_object("HumanWorkbench")) gender = swk_anthro_sex.index("Female") diff --git a/examples/example__hybrid_bodies__001.py b/examples/example__hybrid_bodies__001.py index e71cb88a..cb2d2aab 100644 --- a/examples/example__hybrid_bodies__001.py +++ b/examples/example__hybrid_bodies__001.py @@ -29,19 +29,13 @@ from pycatia import catia from pycatia.mec_mod_interfaces.body import Body -from pycatia.mec_mod_interfaces.part import Part from pycatia.mec_mod_interfaces.part_document import PartDocument caa = catia() -document = PartDocument(caa.active_document.com_object) -part = Part(document.part.com_object) +# if the active document is a CATPart this will return a PartDocument +part_document: PartDocument = caa.active_document +part = part_document.part bodies = part.bodies -# Note: It's not necessary to explicitly use the PartDocument or the Part class -# with the com_object. It's perfectly fine to write it like this: -# document = caa.active_document -# part = document.part -# But declaring 'document' and 'part' this way, your linter can't resolve the -# product reference, see https://github.com/evereux/pycatia/issues/107#issuecomment-1336195688 # Warning: if you have several bodies with the same name the first will always be chosen. body_cube_1_item = bodies.get_item_by_name("Body.Cube.1") diff --git a/examples/example__hybrid_shape_factory__001.py b/examples/example__hybrid_shape_factory__001.py index fa6706a2..ce4cf75a 100644 --- a/examples/example__hybrid_shape_factory__001.py +++ b/examples/example__hybrid_shape_factory__001.py @@ -27,19 +27,13 @@ from pycatia import catia from pycatia.in_interfaces.reference import Reference -from pycatia.mec_mod_interfaces.part import Part from pycatia.mec_mod_interfaces.part_document import PartDocument caa = catia() -document = PartDocument(caa.active_document.com_object) -part = Part(document.part.com_object) +# if the active document is a CATPart this will return a PartDocument +part_document: PartDocument = caa.active_document +part = part_document.part bodies = part.bodies -# Note: It's not necessary to explicitly use the PartDocument or the Part class -# with the com_object. It's perfectly fine to write it like this: -# document = caa.active_document -# part = document.part -# But declaring 'document' and 'part' this way, your linter can't resolve the -# product reference, see https://github.com/evereux/pycatia/issues/107#issuecomment-1336195688 # initialise the hybrid shape factory. this is used to determine the shape type later. hsf = part.hybrid_shape_factory diff --git a/examples/example__hybrid_shape_factory__002.py b/examples/example__hybrid_shape_factory__002.py index 0ea90287..a3d34106 100644 --- a/examples/example__hybrid_shape_factory__002.py +++ b/examples/example__hybrid_shape_factory__002.py @@ -24,7 +24,6 @@ ########################################################## from pycatia import catia -from pycatia.mec_mod_interfaces.part import Part from pycatia.mec_mod_interfaces.part_document import PartDocument from pycatia.scripts.csv_tools import create_points @@ -36,16 +35,8 @@ documents = caa.documents # create a new part. -documents.add("Part") - -document = PartDocument(caa.active_document.com_object) -part = Part(document.part.com_object) -# Note: It's not necessary to explicitly use the PartDocument or the Part class -# with the com_object. It's perfectly fine to write it like this: -# document = caa.active_document -# part = document.part -# But declaring 'document' and 'part' this way, your linter can't resolve the -# product reference, see https://github.com/evereux/pycatia/issues/107#issuecomment-1336195688 +part_document: PartDocument = documents.add("Part") +part = part_document.part # full path name to csv file. file = r"tests\Sample_Point_CSV_File1_small.csv" diff --git a/examples/example__hybrid_shape_factory__003.py b/examples/example__hybrid_shape_factory__003.py index cc132b3d..760708f7 100644 --- a/examples/example__hybrid_shape_factory__003.py +++ b/examples/example__hybrid_shape_factory__003.py @@ -23,20 +23,12 @@ from pycatia import catia from pycatia.in_interfaces.reference import Reference -from pycatia.mec_mod_interfaces.part import Part from pycatia.mec_mod_interfaces.part_document import PartDocument caa = catia() documents = caa.documents -documents.add("Part") -document = PartDocument(caa.active_document.com_object) -part = Part(document.part.com_object) -# Note: It's not necessary to explicitly use the PartDocument or the Part class -# with the com_object. It's perfectly fine to write it like this: -# document = caa.active_document -# part = document.part -# But declaring 'document' and 'part' this way, your linter can't resolve the -# product reference, see https://github.com/evereux/pycatia/issues/107#issuecomment-1336195688 +part_document: PartDocument = documents.add("Part") +part = part_document.part hybrid_bodies = part.hybrid_bodies hsf = part.hybrid_shape_factory diff --git a/examples/example__hybrid_shape_factory__004.py b/examples/example__hybrid_shape_factory__004.py index 4556922c..11ff8a78 100644 --- a/examples/example__hybrid_shape_factory__004.py +++ b/examples/example__hybrid_shape_factory__004.py @@ -32,18 +32,12 @@ from pycatia.hybrid_shape_interfaces.hybrid_shape_point_coord import ( HybridShapePointCoord, ) -from pycatia.mec_mod_interfaces.part import Part from pycatia.mec_mod_interfaces.part_document import PartDocument caa = catia() -document = PartDocument(caa.active_document.com_object) -part = Part(document.part.com_object) -# Note: It's not necessary to explicitly use the PartDocument or the Part class -# with the com_object. It's perfectly fine to write it like this: -# document = caa.active_document -# part = document.part -# But declaring 'document' and 'part' this way, your linter can't resolve the -# product reference, see https://github.com/evereux/pycatia/issues/107#issuecomment-1336195688 +# if the active document is a CATPart this will return a PartDocument +part_document: PartDocument = caa.active_document +part = part_document.part hbs = part.hybrid_bodies hb_construction_lines = hbs.item("construction_geometry") @@ -53,11 +47,11 @@ hs = hss.item(shape_index) # clear the selection on each loop. - document.selection.clear() + part_document.selection.clear() # add the shape to the selection. - document.selection.add(hs) + part_document.selection.add(hs) # create the selected element by getting the first item in the document selection. - selected_elem = document.selection.item(1) + selected_elem = part_document.selection.item(1) # test part only has HybridShapeLinePtPt if selected_elem.type == "HybridShapeLinePtPt": diff --git a/examples/example__hybrid_shape_factory__005.py b/examples/example__hybrid_shape_factory__005.py index 731ce5b8..391a717e 100644 --- a/examples/example__hybrid_shape_factory__005.py +++ b/examples/example__hybrid_shape_factory__005.py @@ -23,19 +23,13 @@ ########################################################## from pycatia import catia -from pycatia.mec_mod_interfaces.part import Part from pycatia.mec_mod_interfaces.part_document import PartDocument caa = catia() -document = PartDocument(caa.active_document.com_object) -part = Part(document.part.com_object) +# if the active document is a CATPart this will return a PartDocument +part_document: PartDocument = caa.active_document +part = part_document.part bodies = part.bodies -# Note: It's not necessary to explicitly use the PartDocument or the Part class -# with the com_object. It's perfectly fine to write it like this: -# document = caa.active_document -# part = document.part -# But declaring 'document' and 'part' this way, your linter can't resolve the -# product reference, see https://github.com/evereux/pycatia/issues/107#issuecomment-1336195688 hsf = part.hybrid_shape_factory hbs = part.hybrid_bodies diff --git a/examples/example__hybrid_shape_factory__006.py b/examples/example__hybrid_shape_factory__006.py index f2a14ca7..6d59899d 100644 --- a/examples/example__hybrid_shape_factory__006.py +++ b/examples/example__hybrid_shape_factory__006.py @@ -22,21 +22,15 @@ sys.path.insert(0, os.path.abspath("..\\pycatia")) ########################################################## from pycatia import catia -from pycatia.mec_mod_interfaces.part import Part -from pycatia.hybrid_shape_interfaces.hybrid_shape_factory import HybridShapeFactory +from pycatia.mec_mod_interfaces.part_document import PartDocument import pythoncom from pycatia.scripts.vba import vba_nothing caa = catia() -document = caa.active_document -part = Part(document.part.com_object) -# Note: It's not necessary to explicitly use the PartDocument or the Part class -# with the com_object. It's perfectly fine to write it like this: -# document = caa.active_document -# part = document.part -# But declaring 'document' and 'part' this way, your linter can't resolve the -# product reference, see https://github.com/evereux/pycatia/issues/107#issuecomment-1336195688 +# if the active document is a CATPart this will return a PartDocument +part_document: PartDocument = caa.active_document +part = part_document.part hybrid_bodies = part.hybrid_bodies construction_geometry = hybrid_bodies.item("ConstructionGeometry") diff --git a/examples/example__hybrid_shape_factory__shape_factory__001.py b/examples/example__hybrid_shape_factory__shape_factory__001.py index 8643106a..76ba21a3 100644 --- a/examples/example__hybrid_shape_factory__shape_factory__001.py +++ b/examples/example__hybrid_shape_factory__shape_factory__001.py @@ -23,26 +23,17 @@ from pycatia import catia from pycatia.in_interfaces.reference import Reference -from pycatia.mec_mod_interfaces.part import Part from pycatia.mec_mod_interfaces.part_document import PartDocument -from pycatia.product_structure_interfaces.product import Product from pycatia.product_structure_interfaces.product_document import ProductDocument caa = catia() documents = caa.documents -documents.add("Part") +part_document: PartDocument = documents.add("Part") product_document = ProductDocument(caa.active_document.com_object) -product = Product(product_document.product.com_object) - -part_document = PartDocument(caa.active_document.com_object) -part = Part(part_document.part.com_object) -# Note: It's not necessary to explicitly use the PartDocument or the Part class -# with the com_object. It's perfectly fine to write it like this: -# document = caa.active_document -# part = document.part -# But declaring 'part_document' and 'part' this way, your linter can't resolve the -# product reference, see https://github.com/evereux/pycatia/issues/107#issuecomment-1336195688 +product = product_document.product + +part = part_document.part hybrid_shape_factory = part.hybrid_shape_factory part_shape_factory = part.shape_factory diff --git a/examples/example__hybrid_sketch__shape_factory__001.py b/examples/example__hybrid_sketch__shape_factory__001.py index b9606d4f..b1e0c0e0 100644 --- a/examples/example__hybrid_sketch__shape_factory__001.py +++ b/examples/example__hybrid_sketch__shape_factory__001.py @@ -24,21 +24,13 @@ from pycatia import catia from pycatia.enumeration.enumeration_types import cat_constraint_type from pycatia.in_interfaces.reference import Reference -from pycatia.mec_mod_interfaces.part import Part from pycatia.mec_mod_interfaces.part_document import PartDocument from pycatia.sketcher_interfaces.geometry_2D import Geometry2D caa = catia() documents = caa.documents -documents.add("Part") -document = PartDocument(caa.active_document.com_object) -part = Part(document.part.com_object) -# Note: It's not necessary to explicitly use the PartDocument or the Part class -# with the com_object. It's perfectly fine to write it like this: -# document = caa.active_document -# part = document.part -# But declaring 'document' and 'part' this way, your linter can't resolve the -# product reference, see https://github.com/evereux/pycatia/issues/107#issuecomment-1336195688 +part_document: PartDocument = documents.add("Part") +part = part_document.part hsf = part.hybrid_shape_factory diff --git a/examples/example__inertia__001.py b/examples/example__inertia__001.py index a6028635..c3da6c28 100644 --- a/examples/example__inertia__001.py +++ b/examples/example__inertia__001.py @@ -28,7 +28,7 @@ ########################################################## from pycatia import catia -from pycatia.mec_mod_interfaces.part import Part +from pycatia.mec_mod_interfaces.part_document import PartDocument from pycatia.space_analyses_interfaces.inertia import Inertia __author__ = '[ptm] by plm-forum.ru' @@ -36,11 +36,9 @@ # initialise the catia automation application caa = catia() -documents = caa.documents - -# get the active document -document = caa.active_document -part = Part(document.part.com_object) +# if the active document is a CATPart this will return a PartDocument +part_document: PartDocument = caa.active_document +part = part_document.part part.update() # get the Bodies() collection @@ -52,7 +50,7 @@ # body_by_name = bodies.get_item_by_name('AnotherPartBody') # initialise the spa workbench -spa_workbench = document.spa_workbench() +spa_workbench = part_document.spa_workbench() # create a reference to measure. reference = part.create_reference_from_object(part) diff --git a/examples/example__material__001.py b/examples/example__material__001.py index 9228b711..cc48a02b 100644 --- a/examples/example__material__001.py +++ b/examples/example__material__001.py @@ -24,6 +24,8 @@ sys.path.insert(0, os.path.abspath("..\\pycatia")) ########################################################## +from pathlib import Path + from pycatia import catia from pycatia.cat_mat_interfaces.material_document import MaterialDocument from pycatia.cat_mat_interfaces.material_manager import MaterialManager @@ -35,8 +37,7 @@ ########################################################## # MATERIAL MANAGER ON MATERIAL CATALOGS ########################################################## -material_documents = caa.documents.open(r"tests/cat_files/Catalog.CATMaterial") -material_document = MaterialDocument(caa.active_document.com_object) +material_document: MaterialDocument = caa.documents.open(Path(os.getcwd(), r"tests/cat_files/Catalog.CATMaterial")) material_families = material_document.families materials = material_families.item(1).materials diff --git a/examples/example__parameters__001.py b/examples/example__parameters__001.py index 2284ba71..1db97298 100644 --- a/examples/example__parameters__001.py +++ b/examples/example__parameters__001.py @@ -21,35 +21,27 @@ sys.path.insert(0, os.path.abspath("..\\pycatia")) ########################################################## +from pathlib import Path from pycatia import catia -from pycatia.mec_mod_interfaces.part import Part from pycatia.mec_mod_interfaces.part_document import PartDocument # from pycatia.knowledge_interfaces import BoolParam caa = catia() documents = caa.documents -documents.open(r"tests/cat_files/part_measurable.CATPart") - -document = PartDocument(caa.active_document.com_object) -part = Part(document.part.com_object) +part_document: PartDocument = documents.open(Path(os.getcwd(), r"tests/cat_files/part_measurable.CATPart")) +part = part_document.part bodies = part.bodies -# Note: It's not necessary to explicitly use the PartDocument or the Part class -# with the com_object. It's perfectly fine to write it like this: -# document = caa.active_document -# part = document.part -# But declaring 'document' and 'part' this way, your linter can't resolve the -# product reference, see https://github.com/evereux/pycatia/issues/107#issuecomment-1336195688 # gets part parameters part_parameters = part.parameters # create parameter to activate pocket part_parameters.create_boolean("Activate_Pocket", True) +pocket_activity = part_parameters.item("Activate_Pocket") # find and assign parameters -pocket_activity = part_parameters.item("Activate_Pocket") # gets RootParameterSet inside of parameters root_parameter_set = part_parameters.root_parameter_set diff --git a/examples/example__parameters__002.py b/examples/example__parameters__002.py index 29c0a088..ba35cf72 100644 --- a/examples/example__parameters__002.py +++ b/examples/example__parameters__002.py @@ -23,24 +23,16 @@ from pycatia import catia from pycatia.knowledge_interfaces.length import Length -from pycatia.mec_mod_interfaces.part import Part from pycatia.mec_mod_interfaces.part_document import PartDocument -from pycatia.product_structure_interfaces.product import Product +from pycatia.product_structure_interfaces.product_document import ProductDocument # from pycatia.knowledge_interfaces import BoolParam caa = catia() -documents = caa.documents - -document = PartDocument(caa.active_document.com_object) -product = Product(document.product.com_object) -part = Part(document.part.com_object) -# Note: It's not necessary to explicitly use the PartDocument or the Part class -# with the com_object. It's perfectly fine to write it like this: -# document = caa.active_document -# part = document.part -# But declaring 'document' and 'part' this way, your linter can't resolve the -# product reference, see https://github.com/evereux/pycatia/issues/107#issuecomment-1336195688 +part_document: PartDocument = caa.active_document +part = part_document.part +product_document: ProductDocument = ProductDocument(caa.active_document.com_object) +product = product_document.product # gets the parameters collection parameters = part.parameters diff --git a/examples/example__product__001.py b/examples/example__product__001.py index a2293661..2d5c46b2 100644 --- a/examples/example__product__001.py +++ b/examples/example__product__001.py @@ -71,7 +71,6 @@ from pywinauto.controls.win32_controls import ListBoxWrapper from pycatia import catia -from pycatia.product_structure_interfaces.product import Product from pycatia.product_structure_interfaces.product_document import ProductDocument lang = 'EN' # only EN and DE currently supported, more translations welcomed. @@ -128,16 +127,10 @@ def get_window_text(window_text_translations: dict, lang): window_text = get_window_text(text_translations, lang) caa = catia() -document = ProductDocument(caa.active_document.com_object) -product = Product(document.product.com_object) -# Note: It's not necessary to explicitly use the ProductDocument or the Product class -# with the com_object. It's perfectly fine to write it like this: -# document = caa.active_document -# product = document.product -# But declaring 'document' and 'product' this way, your linter can't resolve the -# product reference, see https://github.com/evereux/pycatia/issues/107#issuecomment-1336195688 - -selection = document.selection +product_document: ProductDocument = caa.active_document +product = product_document.product + +selection = product_document.selection selection.clear() selection.add(product) caa.start_command(window_text['graph_tree_cmd']) diff --git a/examples/example__product__002.py b/examples/example__product__002.py index aae96193..018b5c7a 100644 --- a/examples/example__product__002.py +++ b/examples/example__product__002.py @@ -21,6 +21,7 @@ sys.path.insert(0, os.path.abspath("..\\pycatia")) ########################################################## +from pathlib import Path from pycatia import catia from pycatia.enumeration.enumeration_types import cat_work_mode_type @@ -29,16 +30,8 @@ caa = catia() documents = caa.documents -documents.open(r"tests\cat_files\product_top.CATProduct") - -document = ProductDocument(caa.active_document.com_object) -product = Product(document.product.com_object) -# Note: It's not necessary to explicitly use the ProductDocument or the Product class -# with the com_object. It's perfectly fine to write it like this: -# document = caa.active_document -# product = document.product -# But declaring 'document' and 'product' this way, your linter can't resolve the -# product reference, see https://github.com/evereux/pycatia/issues/107#issuecomment-1336195688 +product_document: ProductDocument = documents.open(Path(os.getcwd(), r"tests\cat_files\product_top.CATProduct")) +product = product_document.product # Change the work mode to Design Mode. # This is useful for CATIA configurations that work with a cache otherwise methods on children may fail diff --git a/examples/example__product__003.py b/examples/example__product__003.py index 3de9da93..6c2dac58 100644 --- a/examples/example__product__003.py +++ b/examples/example__product__003.py @@ -22,6 +22,7 @@ sys.path.insert(0, os.path.abspath("..\\pycatia")) ########################################################## +from pathlib import Path from pycatia import catia from pycatia.enumeration.enumeration_types import cat_work_mode_type @@ -30,16 +31,8 @@ caa = catia() documents = caa.documents -documents.open(r"tests\cat_files\product_top.CATProduct") - -document = ProductDocument(caa.active_document.com_object) -product = Product(document.product.com_object) -# Note: It's not necessary to explicitly use the ProductDocument or the Product class -# with the com_object. It's perfectly fine to write it like this: -# document = caa.active_document -# product = document.product -# But declaring 'document' and 'product' this way, your linter can't resolve the -# product reference, see https://github.com/evereux/pycatia/issues/107#issuecomment-1336195688 +product_document: ProductDocument = documents.open(Path(os.getcwd(), r"tests\cat_files\product_top.CATProduct")) +product = product_document.product # Change the work mode to Design Mode. # This is useful for CATIA configurations that work with a cache otherwise methods on children may fail diff --git a/examples/example__product__004.py b/examples/example__product__004.py index 8c52399b..a6549a49 100644 --- a/examples/example__product__004.py +++ b/examples/example__product__004.py @@ -21,22 +21,15 @@ sys.path.insert(0, os.path.abspath("..\\pycatia")) ########################################################## +from pathlib import Path from pycatia import catia -from pycatia.product_structure_interfaces.product import Product from pycatia.product_structure_interfaces.product_document import ProductDocument caa = catia() documents = caa.documents -documents.open(r"tests\cat_files\product_top.CATProduct") -document = ProductDocument(caa.active_document.com_object) -product = Product(document.product.com_object) -# Note: It's not necessary to explicitly use the ProductDocument or the Product class -# with the com_object. It's perfectly fine to write it like this: -# document = caa.active_document -# product = document.product -# But declaring 'document' and 'product' this way, your linter can't resolve the -# product reference, see https://github.com/evereux/pycatia/issues/107#issuecomment-1336195688 +product_document: ProductDocument = documents.open(Path(os.getcwd(), r"tests\cat_files\product_top.CATProduct")) +product = product_document.product products = product.products @@ -44,4 +37,4 @@ print(product.position.get_components()) # print(product.name, position.get_components()) -document.close() +product_document.close() diff --git a/examples/example__product__005.py b/examples/example__product__005.py index d7f928a7..47723dcd 100644 --- a/examples/example__product__005.py +++ b/examples/example__product__005.py @@ -21,24 +21,16 @@ sys.path.insert(0, os.path.abspath("..\\pycatia")) ########################################################## +from pathlib import Path from pycatia import catia from pycatia.enumeration.enumeration_types import cat_work_mode_type -from pycatia.product_structure_interfaces.product import Product from pycatia.product_structure_interfaces.product_document import ProductDocument caa = catia() documents = caa.documents -documents.open(r"tests/cat_files/product_top.CATProduct") -document = ProductDocument(caa.active_document.com_object) -product = Product(document.product.com_object) -# Note: It's not necessary to explicitly use the ProductDocument or the Product class -# with the com_object. It's perfectly fine to write it like this: -# document = caa.active_document -# product = document.product -# But declaring 'document' and 'product' this way, your linter can't resolve the -# product reference, see https://github.com/evereux/pycatia/issues/107#issuecomment-1336195688 - +product_document: ProductDocument = documents.open(Path(os.getcwd(), r"tests/cat_files/product_top.CATProduct")) +product = product_document.product # Change the work mode to Design Mode. # This is useful for CATIA configurations that work with a cache otherwise # methods on children may fail due to the document not being loaded. diff --git a/examples/example__product__006.py b/examples/example__product__006.py index d68f9777..8058dc94 100644 --- a/examples/example__product__006.py +++ b/examples/example__product__006.py @@ -23,19 +23,12 @@ ########################################################## from pycatia import catia -from pycatia.product_structure_interfaces.product import Product from pycatia.product_structure_interfaces.product_document import ProductDocument from pycatia.space_analyses_interfaces.inertia import Inertia caa = catia() -document = ProductDocument(caa.active_document.com_object) -product = Product(document.product.com_object) -# Note: It's not necessary to explicitly use the ProductDocument or the Product class -# with the com_object. It's perfectly fine to write it like this: -# document = caa.active_document -# product = document.product -# But declaring 'document' and 'product' this way, your linter can't resolve the -# product reference, see https://github.com/evereux/pycatia/issues/107#issuecomment-1336195688 +product_document: ProductDocument = caa.active_document +product = product_document.product inertia_com = product.get_technological_object("Inertia") inertia = Inertia(inertia_com) diff --git a/examples/example__selection__001.py b/examples/example__selection__001.py index 5dec0e7a..0e4e047b 100644 --- a/examples/example__selection__001.py +++ b/examples/example__selection__001.py @@ -55,22 +55,16 @@ def close_inertia_window(): caa = catia() -document = ProductDocument(caa.active_document.com_object) -product = Product(document.product.com_object) -# Note: It's not necessary to explicitly use the ProductDocument or the Product class -# with the com_object. It's perfectly fine to write it like this: -# document = caa.active_document -# product = document.product -# But declaring 'document' and 'product' this way, your linter can't resolve the -# product reference, see https://github.com/evereux/pycatia/issues/107#issuecomment-1336195688 - -selection = document.selection +product_document: ProductDocument = caa.active_document +product = product_document.product + +selection = product_document.selection selection.clear() c = True while c is True: input("Selection product to measure.\nPress when selection made.") - selection = document.selection + selection = product_document.selection caa.start_command(inertia_cmd_name) parameters = product.parameters diff --git a/examples/example__selection__002.py b/examples/example__selection__002.py index 7c63137f..08dddcbe 100644 --- a/examples/example__selection__002.py +++ b/examples/example__selection__002.py @@ -23,18 +23,18 @@ sys.path.insert(0, os.path.abspath('..\\pycatia')) ########################################################## -from pycatia.mec_mod_interfaces.part import Part +from pycatia.mec_mod_interfaces.part_document import PartDocument from pycatia import catia caa = catia() -documents = caa.documents -document = caa.active_document -part = Part(document.part.com_object) +# if the active document is a CATPart this will return a PartDocument +part_document: PartDocument = caa.active_document +part = part_document.part hybrid_bodies = part.hybrid_bodies hsf = part.hybrid_shape_factory # create selection object -selection = document.selection +selection = part_document.selection filter_type = ("Vertex",) diff --git a/examples/example__selection__003.py b/examples/example__selection__003.py index c696d4d9..cd29e8be 100644 --- a/examples/example__selection__003.py +++ b/examples/example__selection__003.py @@ -22,7 +22,7 @@ sys.path.insert(0, os.path.abspath('..\\pycatia')) ########################################################## -from pycatia.mec_mod_interfaces.part import Part +from pycatia.mec_mod_interfaces.part_document import PartDocument from pycatia import catia from pycatia.enumeration.enumeration_types import cat_measurable_name from pycatia.enumeration.enumeration_types import cat_selection_filter @@ -33,21 +33,16 @@ caa = catia() documents = caa.documents -document = caa.active_document -part_document = Part(document.part.com_object) -# Note: It's not necessary to explicitly use the ProductDocument or the Product class -# with the com_object. It's perfectly fine to write it like this: -# document = caa.active_document -# product = document.product -# But declaring 'document' and 'product' this way, your linter can't resolve the -# product reference, see https://github.com/evereux/pycatia/issues/107#issuecomment-1336195688 - -selection = document.selection +# if the active document is a CATPart this will return a PartDocument +part_document: PartDocument = caa.active_document +part = part_document.part + +selection = part_document.selection selection.clear() -hsf = part_document.hybrid_shape_factory +hsf = part.hybrid_shape_factory -spa = document.spa_workbench() +spa = part_document.spa_workbench() # promt user select any object mb = caa.message_box('Select any HybridShape, or PartBody.\n' diff --git a/examples/example__shape_factory__001.py b/examples/example__shape_factory__001.py index 9dacc3fa..9f2c9138 100644 --- a/examples/example__shape_factory__001.py +++ b/examples/example__shape_factory__001.py @@ -26,20 +26,12 @@ from pycatia import catia from pycatia.in_interfaces.reference import Reference from pycatia.mec_mod_interfaces.body import Body -from pycatia.mec_mod_interfaces.part import Part from pycatia.mec_mod_interfaces.part_document import PartDocument caa = catia() documents = caa.documents -documents.add("Part") -document = PartDocument(caa.active_document.com_object) -part = Part(document.part.com_object) -# Note: It's not necessary to explicitly use the PartDocument or the Part class -# with the com_object. It's perfectly fine to write it like this: -# document = caa.active_document -# part = document.part -# But declaring 'document' and 'part' this way, your linter can't resolve the -# product reference, see https://github.com/evereux/pycatia/issues/107#issuecomment-1336195688 +part_document: PartDocument = documents.add("Part") +part = part_document.part shape_factory = part.shape_factory diff --git a/examples/example__shape_factory__002.py b/examples/example__shape_factory__002.py index f2c7668b..3e239fca 100644 --- a/examples/example__shape_factory__002.py +++ b/examples/example__shape_factory__002.py @@ -25,9 +25,9 @@ from pycatia.mec_mod_interfaces.part_document import PartDocument caa = catia() -documents = caa.documents -doc = PartDocument(caa.active_document.com_object) -part = doc.part +# if the active document is a CATPart this will return a PartDocument +part_document: PartDocument = caa.active_document +part = part_document.part part.in_work_object = part.main_body mirror_reference = part.create_reference_from_object(part.origin_elements.plane_zx) diff --git a/examples/example__space_analysis__001.py b/examples/example__space_analysis__001.py index 512f8889..727ccab0 100644 --- a/examples/example__space_analysis__001.py +++ b/examples/example__space_analysis__001.py @@ -21,24 +21,17 @@ sys.path.insert(0, os.path.abspath("..\\pycatia")) ########################################################## +from pathlib import Path from pycatia import catia -from pycatia.mec_mod_interfaces.part import Part from pycatia.mec_mod_interfaces.part_document import PartDocument # initialise the catia automation application caa = catia() documents = caa.documents -documents.open(r"tests/cat_files/part_measurable.CATPart") - -document = PartDocument(caa.active_document.com_object) -part = Part(document.part.com_object) -# Note: It's not necessary to explicitly use the PartDocument or the Part class -# with the com_object. It's perfectly fine to write it like this: -# document = caa.active_document -# part = document.part -# But declaring 'document' and 'part' this way, your linter can't resolve the -# product reference, see https://github.com/evereux/pycatia/issues/107#issuecomment-1336195688 +# if the active document is a CATPart this will return a PartDocument +part_document: PartDocument = documents.open(Path(os.getcwd(), r"tests/cat_files/part_measurable.CATPart")) +part = part_document.part # get the Bodies() collection bodies = part.bodies @@ -54,7 +47,7 @@ # >>> Body(name="AnotherPartBody") # initialise the spa workbench -spa_workbench = document.spa_workbench() +spa_workbench = part_document.spa_workbench() # create a reference to measure. reference = part.create_reference_from_object(body) diff --git a/examples/example__space_analysis__002.py b/examples/example__space_analysis__002.py index 80936945..b91307ed 100644 --- a/examples/example__space_analysis__002.py +++ b/examples/example__space_analysis__002.py @@ -22,26 +22,19 @@ sys.path.insert(0, os.path.abspath("..\\pycatia")) ########################################################## +from pathlib import Path from pycatia import catia from pycatia.mec_mod_interfaces.hybrid_body import HybridBody -from pycatia.mec_mod_interfaces.part import Part from pycatia.mec_mod_interfaces.part_document import PartDocument caa = catia() documents = caa.documents # this should be the path to your file. -documents.open(r"tests\cat_files\part_measurable.CATPart") - -document = PartDocument(caa.active_document.com_object) -part = Part(document.part.com_object) -# Note: It's not necessary to explicitly use the PartDocument or the Part class -# with the com_object. It's perfectly fine to write it like this: -# document = caa.active_document -# part = document.part -# But declaring 'document' and 'part' this way, your linter can't resolve the -# product reference, see https://github.com/evereux/pycatia/issues/107#issuecomment-1336195688 -spa_workbench = document.spa_workbench() +# if the active document is a CATPart this will return a PartDocument +part_document: PartDocument = documents.open(Path(os.getcwd(), r"tests\cat_files\part_measurable.CATPart")) +part = part_document.part +spa_workbench = part_document.spa_workbench() hybrid_bodies = part.hybrid_bodies hybrid_body_item = hybrid_bodies.get_item_by_name("construction_points") diff --git a/examples/example__space_analysis__003.py b/examples/example__space_analysis__003.py index 3b62128a..5975d0ea 100644 --- a/examples/example__space_analysis__003.py +++ b/examples/example__space_analysis__003.py @@ -25,27 +25,19 @@ sys.path.insert(0, os.path.abspath("..\\pycatia")) ########################################################## - import csv +from pathlib import Path from pycatia import catia -from pycatia.mec_mod_interfaces.part import Part from pycatia.mec_mod_interfaces.part_document import PartDocument caa = catia() documents = caa.documents -documents.open(r"tests/cat_files/part_measurable.CATPart") -document = PartDocument(caa.active_document.com_object) -part = Part(document.part.com_object) -# Note: It's not necessary to explicitly use the PartDocument or the Part class -# with the com_object. It's perfectly fine to write it like this: -# document = caa.active_document -# part = document.part -# But declaring 'document' and 'part' this way, your linter can't resolve the -# product reference, see https://github.com/evereux/pycatia/issues/107#issuecomment-1336195688 - -spa_workbench = document.spa_workbench() -selected = document.search_for_items(["Point"]) +part_document: PartDocument = documents.open(Path(os.getcwd(), r"tests/cat_files/part_measurable.CATPart")) +part = part_document.part + +spa_workbench = part_document.spa_workbench() +selected = part_document.search_for_items(["Point"]) # export the points to a csv file. csv_file_name = "__junk__\\exported_points.csv" diff --git a/examples/example__specs_and_geom_window__001.py b/examples/example__specs_and_geom_window__001.py index 85aa9d1d..9b0dfcd8 100644 --- a/examples/example__specs_and_geom_window__001.py +++ b/examples/example__specs_and_geom_window__001.py @@ -63,18 +63,12 @@ def save_file_path(prod_part_number, prod_revision, view_type): for cat_part in source_files: with CATIADocHandler(cat_part) as handler: caa = handler.catia - document = ProductDocument(caa.active_document.com_object) - product = Product(document.product.com_object) - # Note: It's not necessary to explicitly use the ProductDocument or the Product class - # with the com_object. It's perfectly fine to write it like this: - # document = caa.active_document - # product = document.product - # But declaring 'document' and 'product' this way, your linter can't resolve the - # product reference, see https://github.com/evereux/pycatia/issues/107#issuecomment-1336195688 + product_document: ProductDocument = caa.active_document + product = Product(product_document.product.com_object) active_window = caa.active_window active_viewer = active_window.active_viewer - cameras = document.cameras + cameras = product_document.cameras # get current background colour background_colour = active_viewer.get_background_color() diff --git a/examples/example__visual_properties__001.py b/examples/example__visual_properties__001.py index 4fd363d5..b56e2e82 100644 --- a/examples/example__visual_properties__001.py +++ b/examples/example__visual_properties__001.py @@ -22,7 +22,6 @@ ########################################################## from pycatia import catia -from pycatia.enumeration.enumeration_types import cat_vis_property_status caa = catia() document = caa.active_document From c740eddad97945fadd9c90fa87f5494fb191ff32 Mon Sep 17 00:00:00 2001 From: evereux Date: Thu, 6 Jun 2024 14:04:05 +0100 Subject: [PATCH 5/8] use Path.isfile() properly --- pycatia/in_interfaces/documents.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pycatia/in_interfaces/documents.py b/pycatia/in_interfaces/documents.py index a4c2105b..71fba27d 100644 --- a/pycatia/in_interfaces/documents.py +++ b/pycatia/in_interfaces/documents.py @@ -155,7 +155,7 @@ def new_from(self, file_name: Path) -> Document: if not os.path.isfile(file_name): raise FileNotFoundError(f'Could not find file {file_name}.') else: - if not file_name.is_file: + if not file_name.is_file(): raise FileNotFoundError(f'Could not find file {file_name}.') @@ -266,7 +266,11 @@ def open(self, file_name: Path) -> Document: try: self.logger.info(f'Opening document "{file_name}".') - return Document(self.documents.Open(file_name)) + open_doc_com = self.documents.Open(file_name) + extension = file_name.suffix[1:] + types = [document_types[k]['type'] for k in (document_types) if document_types[k]['extension'] == extension] + document_type = types[0] + return document_type(open_doc_com) except com_error: raise CATIAApplicationException( f'Could not open document "{file_name}". ' From cb0d45d42c4a1af23571eee8c50bb9654dc3d545 Mon Sep 17 00:00:00 2001 From: evereux Date: Thu, 6 Jun 2024 14:05:07 +0100 Subject: [PATCH 6/8] ignore .CATMaterial files --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 5c98c3fb..0753a05a 100644 --- a/.gitignore +++ b/.gitignore @@ -135,6 +135,7 @@ quick_n_dirty.py *.CATDrawing *.CATPart *.CATProduct +*.CATMaterial pycatia-exe.build pycatia-exe.dist From 1dcb97b4cbe74f022cebd8b3a0af57cac0eb8fa4 Mon Sep 17 00:00:00 2001 From: evereux Date: Thu, 6 Jun 2024 14:15:29 +0100 Subject: [PATCH 7/8] updated the user_scripts to show how to better initialise documents. --- CHANGELOG.md | 4 ++++ user_scripts/coords_relative_to_axis_system.py | 8 ++++---- user_scripts/create_bounding_box.py | 10 +++++----- user_scripts/create_lines_normal_to_surface.py | 8 ++++---- user_scripts/create_parameters_from_yaml.py | 13 +++++++------ user_scripts/wing_surface_from_naca_profile.py | 11 +++++------ 6 files changed, 29 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dc972b22..46732709 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,14 @@ # Changelog ## 0.7.1 + * fixed Documents.read() method which was broken by changes made in 0.6.9. * updated Documents.open() so that filename should now be a Path object. * updated Documents.new_from() so that filename should now be a Path object. * updated Documents.open() so that filename should now be a Path object. +* updated the examples so they use explicit path objects. +* updated the examples to show how to better initialise documents. +* updated the user_scripts to show how to better initialise documents. ## 0.7.0 diff --git a/user_scripts/coords_relative_to_axis_system.py b/user_scripts/coords_relative_to_axis_system.py index dd8bfc3d..e8b3c8e1 100644 --- a/user_scripts/coords_relative_to_axis_system.py +++ b/user_scripts/coords_relative_to_axis_system.py @@ -28,13 +28,13 @@ ########################################################## from pycatia import catia +from pycatia.mec_mod_interfaces.part_document import PartDocument caa = catia() -document = caa.active_document -product = document.product -part = document.part +part_document: PartDocument = caa.active_document +part = part_document.part hybrid_bodies = part.hybrid_bodies -spa_workbench = document.spa_workbench() +spa_workbench = part_document.spa_workbench() def coords_relative_to_axis(axis_system, point, precision=6): diff --git a/user_scripts/create_bounding_box.py b/user_scripts/create_bounding_box.py index 4a12f95f..3d811f77 100644 --- a/user_scripts/create_bounding_box.py +++ b/user_scripts/create_bounding_box.py @@ -49,19 +49,19 @@ from pycatia.enumeration.enumeration_types import cat_constraint_type, cat_vis_property_show, cat_constraint_mode from pycatia.knowledge_interfaces.length import Length from pycatia.mec_mod_interfaces.axis_system import AxisSystem -from pycatia.mec_mod_interfaces.part import Part +from pycatia.mec_mod_interfaces.part_document import PartDocument from pycatia.sketcher_interfaces.geometry_2D import Geometry2D logger = create_logger() caa = catia() application = caa.application -document = application.active_document +part_document: PartDocument = application.active_document -if '.CATPart' not in document.name: +if '.CATPart' not in part_document.name: logger.critical('There must be an CATPart open and active.') -part = Part(document.part.com_object) +part = part_document.part shape_factory = part.shape_factory hybrid_shape_factory = part.hybrid_shape_factory bodies = part.bodies @@ -76,7 +76,7 @@ logger.info('Exiting script.') exit() -selection = document.selection +selection = part_document.selection selection.clear() filter_ = ('AxisSystem',) logger.info('Select the Axis system.') diff --git a/user_scripts/create_lines_normal_to_surface.py b/user_scripts/create_lines_normal_to_surface.py index 54b2f85e..bbadf79e 100644 --- a/user_scripts/create_lines_normal_to_surface.py +++ b/user_scripts/create_lines_normal_to_surface.py @@ -42,21 +42,21 @@ from pycatia.enumeration.enumeration_types import geometrical_feature_type from pycatia.mec_mod_interfaces.hybrid_body import HybridBody from pycatia.mec_mod_interfaces.hybrid_shape import HybridShape -from pycatia.mec_mod_interfaces.part import Part +from pycatia.mec_mod_interfaces.part_document import PartDocument LINE_LENGTH = 20 logger = create_logger() caa = catia() -document = caa.active_document -part = Part(document.part.com_object) +part_document: PartDocument = caa.active_document +part = part_document.part hybrid_bodies = part.hybrid_bodies hsf = part.hybrid_shape_factory gs_lines = hybrid_bodies.add() gs_lines.name = ("Lines") -selection = document.selection +selection = part_document.selection selection.clear() mb = caa.message_box( diff --git a/user_scripts/create_parameters_from_yaml.py b/user_scripts/create_parameters_from_yaml.py index e91a49f4..0cbedaf7 100644 --- a/user_scripts/create_parameters_from_yaml.py +++ b/user_scripts/create_parameters_from_yaml.py @@ -74,19 +74,20 @@ from pycatia import catia from pycatia.knowledge_interfaces.parameter_set import ParameterSet from pycatia.knowledge_interfaces.parameters import Parameters -from pycatia.mec_mod_interfaces.part import Part -from pycatia.product_structure_interfaces.product import Product +from pycatia.mec_mod_interfaces.part_document import PartDocument +from pycatia.product_structure_interfaces.product_document import ProductDocument f = Path(os.getcwd(), 'user_scripts', 'create_parameters_from_yaml_support', 'parameters.yaml') caa = catia() application = caa.application documents = application.documents -new_part = documents.add('Part').com_object -document = application.active_document +part_document: PartDocument = documents.add('Part') +active_document = application.active_document -product = Product(document.product.com_object) -part = Part(document.part.com_object) +product_document = ProductDocument(active_document.com_object) +product = product_document.product +part = part_document.part def get_yaml_file(yaml_file: Path) -> dict: diff --git a/user_scripts/wing_surface_from_naca_profile.py b/user_scripts/wing_surface_from_naca_profile.py index 46b5d151..6bd311a3 100644 --- a/user_scripts/wing_surface_from_naca_profile.py +++ b/user_scripts/wing_surface_from_naca_profile.py @@ -61,7 +61,7 @@ from wing_surface_from_naca_profile_support.read_dat_file import read_dat_file from pycatia import catia -from pycatia.mec_mod_interfaces.part import Part +from pycatia.mec_mod_interfaces.part_document import PartDocument from pycatia.product_structure_interfaces.product import Product from pycatia.scripts.vba import vba_nothing @@ -86,15 +86,14 @@ print("If you continue to see this error restart CATIA and close all open documents.") exit() -new_part = documents.add("Part") -document = application.active_document +part_document: PartDocument = documents.add("Part") -selection = document.selection +selection = part_document.selection -product = Product(document.product.com_object) +product = Product(part_document.product.com_object) product.part_number = part_number -part = Part(document.part.com_object) +part = part_document.part parameters = create_parameters(part, product) relations = part.relations From aa97921c44ddd2216a96a5ac25d07f335e9b29dc Mon Sep 17 00:00:00 2001 From: evereux Date: Thu, 6 Jun 2024 14:37:34 +0100 Subject: [PATCH 8/8] updated the introdutcion document to show how to get the PartDocument. --- CHANGELOG.md | 1 + docs/introduction.rst | 19 ++++++------------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 46732709..972f96d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ * updated the examples so they use explicit path objects. * updated the examples to show how to better initialise documents. * updated the user_scripts to show how to better initialise documents. +* updated the introdutcion document to show how to get the PartDocument. ## 0.7.0 diff --git a/docs/introduction.rst b/docs/introduction.rst index bc3d2feb..d17ac4d2 100644 --- a/docs/introduction.rst +++ b/docs/introduction.rst @@ -19,6 +19,7 @@ You will almost always want to import the `catia` .. code-block:: python from pycatia import catia + from pycatia.mec_mod_interfaces.part_document import PartDocument # initialise the catia automation appliction. CATIA V5 should already be running. caa = catia() documents = caa.documents @@ -28,27 +29,20 @@ class. .. code-block:: python - documents.add('Part') + part_document: PartDocument = documents.add('Part') the add method of the documents class expects the string 'Part', 'Product' or 'Drawing'. ``documents.add('Part')`` adds a new CATPart to the documents -collection. - -We want to work on this new document. Since this has just been added it's the -active document. - -.. code-block:: python - - document = caa.active_document +collection and returns a `Document`` object. In this case it is a `PartDocument`. The document object :ref:`Document` has a number of properties that can be accessed. .. code-block:: python - document.name + part_document.name # returns the name of the new document. - document.path + part_document.path # returns the pathlib.Path object of the document. @@ -61,7 +55,7 @@ create one here anyway. .. code-block:: python - part = document.part() + part = part_document.part hybrid_bodies = part.hybrid_bodies new_set = hybrid_bodies.add() new_set.name @@ -71,7 +65,6 @@ create one here anyway. - For more detailed examples on how to interact with pycatia see the :ref:`examples` page. There contain several scripts that can be run in the terminal.