Skip to content

Commit e682065

Browse files
committed
Merge branch 'development'
2 parents 9ad1ec1 + c47c230 commit e682065

File tree

17 files changed

+204
-38
lines changed

17 files changed

+204
-38
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,5 @@ pycatia-exe.build
140140
pycatia-exe.dist
141141
zip_win32_dist.py
142142
win_32/pycatia
143-
pycatia-exe.py
143+
pycatia-exe.py
144+
logo*

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.4.1
4+
* Document.save_as() If overwrite is to true DisplayFileAlerts is set to False.
5+
* Analyze added to Part().
6+
* Updates / fixes to SettingController(s) and LicenseSettingAtt. More work to
7+
be done here yet though.
8+
* Document.add() now accepts lowercase document_types.
9+
* Document.add() now correctly returns a document.
10+
311
## 0.4.0
412
Breaking changes.
513
* The catia application object now needs to be initialized in your scripts.

CONTRIBUTORS.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
CONTRIBUTORS
22

33
z86961027
4-
Luanee
4+
Luanee
5+
Tian-Jionglu

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.4.0'
39+
version = '0.4.1'
4040
# The full version, including alpha/beta/rc tags
4141
release = version
4242

docs/examples.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,3 +226,16 @@ also show further usage of constraints.
226226

227227
`Example 23 <https://github.com/evereux/pycatia/blob/master/example_023.py>`_
228228

229+
Example 24
230+
----------
231+
232+
Basic license checking.
233+
234+
`Example 24 <https://github.com/evereux/pycatia/blob/master/example_024.py>`_
235+
236+
Example 25
237+
----------
238+
239+
Write the contents of a product to a html file.
240+
241+
`Example 25 <https://github.com/evereux/pycatia/blob/master/example_025.py>`_

example_024.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#! /usr/bin/python3.6
2+
3+
"""
4+
5+
Example 24:
6+
7+
Determine if a license for DF1 has been requested.
8+
9+
"""
10+
11+
from pycatia import catia
12+
from pycatia.system_interfaces.license_setting_att import LicenseSettingAtt
13+
from pycatia.in_interfaces.setting_controllers import SettingControllers
14+
15+
cat_lic = "AL3.prd"
16+
17+
caa = catia()
18+
settings_controller = SettingControllers(caa)
19+
setting_controller = settings_controller.item("CATSysLicenseSettingCtrl")
20+
license_settings = LicenseSettingAtt(setting_controller)
21+
22+
status = license_settings.get_license(cat_lic)
23+
24+
if status == "Requested":
25+
print(f'License "{cat_lic}" has been requested.')
26+
elif status == "NotRequested":
27+
print(f'License "{cat_lic}" has not been requested.')

example_025.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#! /usr/bin/python3.6
2+
3+
"""
4+
5+
Example 25:
6+
7+
8+
9+
"""
10+
11+
from collections import Counter
12+
from datetime import datetime
13+
14+
from pycatia import catia
15+
16+
caa = catia()
17+
document = caa.active_document
18+
product = document.product()
19+
products = product.products
20+
21+
part_numbers = []
22+
prd_dict = {}
23+
24+
for product_item in products:
25+
part_numbers.append(product_item.part_number)
26+
prd_dict[product_item.part_number] = product_item.nomenclature
27+
28+
part_numbers.sort()
29+
c = Counter(part_numbers)
30+
31+
html = f"""<!doctype html>
32+
<html lang="en">
33+
<head>
34+
<!-- Required meta tags -->
35+
<meta charset="utf-8">
36+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
37+
38+
<!-- Bootstrap CSS -->
39+
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
40+
41+
<title>{product.part_number} - {product.nomenclature}</title>
42+
</head>
43+
<body>
44+
<div class="container">
45+
<h1>{product.part_number} - {product.nomenclature}</h1>
46+
<p>
47+
Product BOM generated on {datetime.now()}.
48+
</p>
49+
<table class="table table-striped table-hover">
50+
<thead>
51+
<tr>
52+
<th>Part Number</th>
53+
<th>Title</th>
54+
<th>QTY</th>
55+
</tr>
56+
</thead>
57+
<tbody>
58+
"""
59+
60+
for item in c:
61+
print(item, prd_dict[item], c[item])
62+
row = f"""
63+
<tr>
64+
<td>{item}</td>
65+
<td>{prd_dict[item]}</td>
66+
<td>{c[item]}</td>
67+
</tr>"""
68+
html += row
69+
70+
html += """
71+
<tbody>
72+
</table>
73+
</body>
74+
</html>"""
75+
76+
with open((product.part_number + '.html'), 'w') as f:
77+
f.write(html)

pycatia/cat_logger.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ def create_logger() -> logging.Logger:
5151
logger = logging.getLogger('pycatia')
5252

5353
logger.setLevel(logging.INFO)
54-
54+
55+
# clear existed Handlers
56+
logger.handlers.clear()
57+
5558
logger.addHandler(default_handler)
5659

5760
return logger

pycatia/in_interfaces/document.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
if TYPE_CHECKING:
2828
from pycatia.in_interfaces.selection import Selection
2929

30+
3031
class Document(AnyObject):
3132
"""
3233
.. note::
@@ -171,7 +172,6 @@ def is_product(self):
171172
172173
:return: bool
173174
"""
174-
175175
if self.product().is_catproduct():
176176
return True
177177
return False
@@ -778,6 +778,8 @@ def save_as(self, file_name: str, overwrite: bool = False) -> None:
778778
"""
779779
Save the document to a new name.
780780
781+
If overwrite is True CAA.DisplayFileAlerts is set to False.
782+
781783
.. note::
782784
:class: toggle
783785
@@ -804,13 +806,16 @@ def save_as(self, file_name: str, overwrite: bool = False) -> None:
804806
"""
805807

806808
path_file_name = Path(file_name)
809+
807810
if overwrite is False:
808811
if path_file_name.is_file():
809812
raise FileExistsError(f'File: {path_file_name} already exists. '
810813
f'Set overwrite=True if you want to overwrite.')
811814
else:
812-
if path_file_name.is_file():
813-
self.logger.warning('File already exists. Click YES in CATIA V5.')
815+
self.document.Application.DisplayFileAlerts = False
816+
# if path_file_name.is_file():
817+
# self.logger.warning('File already exists. Click YES in CATIA V5.')
818+
814819
self.document.SaveAs(path_file_name)
815820

816821
def search_for_items(self, selection_objects):

pycatia/in_interfaces/documents.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,15 @@ def add(self, document_type) -> Document:
8686
:rtype: Document
8787
"""
8888

89+
document_type_uf = document_type.capitalize()
90+
8991
document_types = ['Part', 'Product', 'Drawing']
90-
if document_type not in document_types:
92+
if document_type_uf not in document_types:
9193
raise ValueError(f'Document type must be in [{document_types}]')
9294

93-
self.logger.info(f'Creating a new "{document_type}".')
95+
self.logger.info(f'Creating a new "{document_type_uf}".')
9496

95-
return Document(self.child_object(self.documents.Add(document_type)))
97+
return Document(self.documents.Add(document_type_uf))
9698

9799
def count_types(self, file_type_list: list_str) -> int:
98100
"""

0 commit comments

Comments
 (0)