Skip to content

Commit 3f6a6fc

Browse files
committed
Merge branch 'developement'
2 parents 79ecb88 + 2076fd7 commit 3f6a6fc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+879
-585
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Changelog
22

3+
## 0.5.9
4+
5+
* Added missing com_oject to references in navigator_interfaces. (@evereux & @marciolrc)
6+
* Fixed reference plane method in HybridShapePlaneAngle. (@Mithro86)
7+
* Updates to examples to include latest supported python version. Also fix IDE autocompletion & syntax highlighting
8+
issues. (@deloarts)
9+
*
10+
311
## 0.5.8
412

513
* Added new document type CatalogDocument.

CONTRIBUTORS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@ deloarts
1717
Mithro86
1818

1919
ptm-tm
20+
21+
marciolrc

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def __getattr__(cls, name):
3636
author = 'Paul Bourne'
3737

3838
# The short X.Y version
39-
version = '0.5.8'
39+
version = '0.5.9'
4040
# The full version, including alpha/beta/rc tags
4141
release = version
4242

examples/example__assembly_convertor__001.py

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
1-
#! /usr/bin/python3.6
1+
#! /usr/bin/python3.9
22

33
"""
44
55
Example - Assembly Convertor - 001
66
7-
Print the BOM of a product to XLS using the inbuilt AssemblyConvertor. You
8-
must already have excel installed.
7+
Description:
8+
Print the BOM of a product to XLS using the inbuilt AssemblyConvertor.
9+
This can also be used to create TXT and HTML files.
910
10-
This can also be used to create TXT and HTML files.
11+
Requirements:
12+
- An open product document with parts inside.
13+
- MS EXCEL must be installed.
1114
12-
See github issue https://github.com/evereux/pycatia/issues/110 with regards
13-
to file paths and saying "No" to overwriting existing files and file paths
14-
when using excel. These issues are mitigated using the code below by
15-
checking for an existing excel file and removing it and also using pythons
16-
pathlib.Path module.
15+
Further information:
16+
See github issue https://github.com/evereux/pycatia/issues/110 with regards
17+
to file paths and saying "No" to overwriting existing files and file paths
18+
when using excel. These issues are mitigated using the code below by
19+
checking for an existing excel file and removing it and also using pythons
20+
pathlib.Path module.
1721
1822
"""
1923

@@ -34,13 +38,32 @@
3438

3539
# file_type can be "TXT", "HTML" or "XLS".
3640
file_type = "XLS"
37-
# full path to excel file.
38-
# use pathlib.Path to prevent path related errors. See github link above.
39-
excel_file = Path("C:\\Users\\evereux\\Desktop\\my_bom.xls")
4041

41-
# check that the parent folder exists
42-
if not excel_file.parent.is_dir():
43-
raise NotADirectoryError(f'Directory "{excel_file.parent}" doesn\'t exist')
42+
caa = catia()
43+
document = ProductDocument(caa.active_document.com_object)
44+
product = Product(document.product.com_object)
45+
# Note: It's not necessary to explicitly use the ProductDocument or the Product class
46+
# with the com_object. It's perfectly fine to write it like this:
47+
# document = caa.active_document
48+
# product = document.product
49+
# But declaring 'document' and 'product' this way, your linter can't resolve the
50+
# product reference, see https://github.com/evereux/pycatia/issues/107#issuecomment-1336195688
51+
52+
bom = product.get_item("BillOfMaterial")
53+
assembly_convertor = AssemblyConvertor(bom.com_object)
54+
55+
details_top = ("Quantity", "Part Number", "Type", "Nomenclature", "Revision")
56+
details_recap = ("Quantity", "Part Number")
57+
# Note: Keep in mind that CATIA is language based when it comes to the bill of material format.
58+
# So 'Part Number' in english will become 'Teilenummer' in german, and so on.
59+
assembly_convertor.set_current_format(details_top)
60+
assembly_convertor.set_secondary_format(details_recap)
61+
62+
# Define the absolute path for the excel file.
63+
# In this example the excel file will be saved to the same folder as the product,
64+
# from which the bill of material is created. The excel file will also have the
65+
# same name as the product.
66+
excel_path = Path(product.path().parent, product.name + ".xls")
4467

4568
# check if the file already exists. I recommend doing this in python for two
4669
# reasons ....
@@ -50,25 +73,11 @@
5073
# errors until CATIA is restarted.
5174
# see github link above for more information.
5275
# !! this will delete excel file if it exists !!
53-
if excel_file.is_file():
54-
os.remove(excel_file)
76+
if excel_path.is_file():
77+
os.remove(excel_path)
5578

5679

57-
caa = catia()
58-
document = caa.active_document
59-
product = ProductDocument(document.com_object).product
60-
# not neccessary but will provide autocompletion in IDEs.
61-
product = Product(product.com_object)
62-
63-
bom = product.get_item("BillOfMaterial")
64-
assembly_convertor = AssemblyConvertor(bom.com_object)
65-
66-
details_top = ("Quantity", "Part Number", "Type", "Nomenclature", "Revision")
67-
details_recap = ("Quantity", "Part Number")
68-
assembly_convertor.set_current_format(details_top)
69-
assembly_convertor.set_secondary_format(details_recap)
70-
71-
assembly_convertor.print(file_type, excel_file, product)
80+
assembly_convertor.print(file_type, excel_path, product)
7281
# Important note:
7382
# The print-method will fail if you try to export the bill-of-material-xls file
7483
# to a location, where another process will access this file. Such process is

examples/example__bom_custom_001.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
#! /usr/bin/python3.6
1+
#! /usr/bin/python3.9
22

33
"""
44
5-
Example - BOM CUSTOM - 001:
5+
Example - BOM CUSTOM - 001
66
7-
Create a custom formatted html of the product tree.
7+
Description:
8+
Create a custom formatted html of the product tree.
9+
10+
Requirements:
11+
- An open product document with parts inside.
812
913
"""
1014

@@ -14,22 +18,26 @@
1418
import os
1519
import sys
1620

17-
sys.path.insert(0, os.path.abspath('..\\pycatia'))
21+
sys.path.insert(0, os.path.abspath("..\\pycatia"))
1822
##########################################################
1923

2024
from collections import Counter
2125
from datetime import datetime
2226

2327
from pycatia import catia
2428
from pycatia.product_structure_interfaces.product import Product
25-
29+
from pycatia.product_structure_interfaces.product_document import ProductDocument
2630

2731
caa = catia()
28-
document = caa.active_document
29-
product = document.product
30-
# not neccessary but will provide autocompletion in IDEs.
31-
product = Product(product.com_object)
32+
document = ProductDocument(caa.active_document.com_object).product
33+
product = Product(document.com_object)
3234
products = product.products
35+
# Note: It's not necessary to explicitly use the ProductDocument or the Product class
36+
# with the com_object. It's perfectly fine to write it like this:
37+
# document = caa.active_document
38+
# product = document.product
39+
# But declaring 'document' and 'product' this way, your linter can't resolve the
40+
# product reference, see https://github.com/evereux/pycatia/issues/107#issuecomment-1336195688
3341

3442
part_numbers = []
3543
prd_dict = {}
@@ -86,5 +94,5 @@
8694
</body>
8795
</html>"""
8896

89-
with open((product.part_number + '.html'), 'w') as f:
97+
with open((product.part_number + ".html"), "w") as f:
9098
f.write(html)

examples/example__constraints_001.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
#! /usr/bin/python3.6
1+
#! /usr/bin/python3.9
22

33
"""
44
5-
Example - Constraints - 001:
5+
Example - Constraints - 001
66
7-
Fix the first Sub Product in Product using constraints. The Sketch examples
8-
also show further usage of constraints.
7+
Description:
8+
Fix the first Sub Product in Product using constraints.
9+
The Sketch examples also show further usage of constraints.
10+
11+
Requirements:
12+
- An open product document with at least two parts inside.
913
1014
"""
1115

@@ -15,21 +19,26 @@
1519
import os
1620
import sys
1721

18-
sys.path.insert(0, os.path.abspath('..\\pycatia'))
22+
sys.path.insert(0, os.path.abspath("..\\pycatia"))
1923
##########################################################
2024

2125
from pycatia import catia
22-
from pycatia.product_structure_interfaces.product import Product
2326
from pycatia.enumeration.enumeration_types import cat_constraint_type
27+
from pycatia.product_structure_interfaces.product import Product
28+
from pycatia.product_structure_interfaces.product_document import ProductDocument
2429

2530
caa = catia()
26-
document = caa.active_document
27-
product = document.product
28-
# not neccessary but will provide autocompletion in IDEs.
29-
product = Product(product.com_object)
30-
constraints = product.constraints()
31+
document = ProductDocument(caa.active_document.com_object).product
32+
product = Product(document.com_object)
33+
# Note: It's not necessary to explicitly use the ProductDocument or the Product class
34+
# with the com_object. It's perfectly fine to write it like this:
35+
# document = caa.active_document
36+
# product = document.product
37+
# But declaring 'document' and 'product' this way, your linter can't resolve the
38+
# product reference, see https://github.com/evereux/pycatia/issues/107#issuecomment-1336195688
3139

3240
products = product.products
41+
constraints = product.constraints()
3342
sub_prod_1 = products.item(1)
3443
ref_sub_prod_1 = sub_prod_1.reference_product
3544

examples/example__document__001.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
#! /usr/bin/python3.6
1+
#! /usr/bin/python3.9
22

33
"""
44
5-
Example - Document - 001:
5+
Example - Document - 001
66
7-
Use the context manager to open CATIA documents and close
7+
Description:
8+
Use the context manager to open CATIA documents and close
9+
10+
Requirements:
11+
- CATIA running.
12+
- Tests already setup.
813
914
"""
1015

@@ -14,14 +19,14 @@
1419
import os
1520
import sys
1621

17-
sys.path.insert(0, os.path.abspath('..\\pycatia'))
22+
sys.path.insert(0, os.path.abspath("..\\pycatia"))
1823
##########################################################
1924

2025
import time
2126

2227
from pycatia import CATIADocHandler
2328

24-
catia_part = r'tests\cat_files\part_measurable.CATPart'
29+
catia_part = r"tests\cat_files\part_measurable.CATPart"
2530

2631
with CATIADocHandler(catia_part) as caa:
2732
document = caa.document

examples/example__document__002.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
#! /usr/bin/python3.6
1+
#! /usr/bin/python3.9
22

33
"""
44
5-
Example - Document - 002:
5+
Example - Document - 002
66
7-
Open all CATParts in source directory and save to IGS in target directory.
7+
Description:
8+
Open all CATParts in source directory and save to IGS in target directory.
9+
10+
Requirements:
11+
- CATIA running.
12+
- Tests already setup.
813
914
"""
1015

@@ -14,35 +19,38 @@
1419
import os
1520
import sys
1621

17-
sys.path.insert(0, os.path.abspath('..\\pycatia'))
22+
sys.path.insert(0, os.path.abspath("..\\pycatia"))
1823
##########################################################
1924

2025
import os
26+
from pathlib import Path
2127

2228
from pycatia import CATIADocHandler
29+
from pycatia.in_interfaces.document import Document
2330

2431
# make these directories the full pathname.
25-
source_directory = 'tests/cat_files'
26-
target_directory = '__junk__'
32+
source_directory = "tests/cat_files"
33+
target_directory = "__junk__"
2734

2835
# if full paths are supplied above you should not do this.
2936
source_directory = os.path.join(os.getcwd(), source_directory)
3037
target_directory = os.path.join(os.getcwd(), target_directory)
3138

3239
# This loop assumes there are NO sub-directories.
3340
for root, dirs, files in os.walk(source_directory):
34-
3541
for file in files:
36-
3742
# only convert CATParts.
38-
if os.path.splitext(file)[1] == '.CATPart':
43+
if os.path.splitext(file)[1] == ".CATPart":
3944
# create filename with path.
4045
file_name = os.path.join(source_directory, file)
4146

4247
with CATIADocHandler(file_name) as caa:
43-
file_ext = 'igs'
48+
file_ext = "igs"
4449
document = caa.document
50+
assert isinstance(document, Document)
51+
4552
# create the full name of the target file, minus extension.
46-
target_file = os.path.join(target_directory, os.path.splitext(file)[0]) + "." + file_ext
53+
target_file = Path(target_directory, os.path.splitext(file)[0] + "." + file_ext)
54+
4755
# create the igs file in the __junk__ directory.
4856
document.export_data(target_file, file_ext)

0 commit comments

Comments
 (0)