Skip to content

Commit 6559af5

Browse files
koubaaMohamed Koubaapyansys-ci-bot
authored
feat: add api to get keyword names (#745)
Co-authored-by: Mohamed Koubaa <[email protected]> Co-authored-by: pyansys-ci-bot <[email protected]>
1 parent 52c9957 commit 6559af5

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

doc/changelog/745.documentation.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
feat: add api to get keyword names

src/ansys/dyna/core/lib/deck.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,19 @@ def title(self) -> typing.Optional[str]:
539539
def title(self, value: str) -> None:
540540
self._title = value
541541

542+
@property
543+
def keyword_names(self) -> typing.List[str]:
544+
names = []
545+
for kw in self.all_keywords:
546+
if isinstance(kw, KeywordBase):
547+
names.append(f"{kw.get_title()}")
548+
elif isinstance(kw, str):
549+
try_title = kw.split("\n")[0]
550+
names.append(f"str({try_title}...)")
551+
elif isinstance(kw, EncryptedKeyword):
552+
names.append(f"Encrypted")
553+
return names
554+
542555
def __repr__(self) -> str:
543556
"""Get a console-friendly representation of a list of all keywords in the deck."""
544557
kwlist = self.all_keywords

tests/test_deck.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,8 @@ def test_kwdeck_basic_002(file_utils, ref_string):
279279
deck.extend([curve1, curve2, include1, volume1, volume2, volume3, tshell1, seatbelt1] + string)
280280
deck_string = deck.write()
281281
file_utils.compare_string_with_file(deck_string, "test.k")
282+
assert deck.keyword_names[0] == "*DEFINE_CURVE"
283+
assert deck.keyword_names[2] == "*INCLUDE"
282284

283285

284286
@pytest.mark.keywords

0 commit comments

Comments
 (0)