Skip to content

Commit cf2008b

Browse files
committed
fix: arguments with no types + accepting multiple line definition in CustomFunctions
1 parent b404bd4 commit cf2008b

File tree

2 files changed

+138
-3
lines changed

2 files changed

+138
-3
lines changed

src/pyconverter/xml2py/custom_functions.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ def get_docstring_lists(filename: str) -> Tuple[list[str], list[str], list[str],
5151
with open(filename, "r") as pyfile:
5252
lines = pyfile.readlines()
5353
bool_def = False
54+
end_def = False
5455
bool_param = False
5556
bool_return = False
5657
bool_notes = False
@@ -65,20 +66,32 @@ def get_docstring_lists(filename: str) -> Tuple[list[str], list[str], list[str],
6566
list_py_code = []
6667
list_import = []
6768
for line in lines:
68-
if "import" in line and bool_def is False:
69+
if "import " in line and bool_def is False:
6970
list_import.append(line)
70-
elif "def" in line and bool_def is False:
71+
# Need to accept the case where the function is defined in multiple lines
72+
elif "def " in line and bool_def is False:
7173
bool_def = True
74+
if bool_def and not end_def:
75+
if ")" in line:
76+
end_def = True
7277
split_def = line.split(",")
7378
for split_arg in split_def:
74-
if "**kwarg" in split_arg:
79+
split_arg = split_arg.strip()
80+
if "**kwarg" in split_arg or split_arg == "self":
81+
break
82+
elif re.search(r"[a-zA-Z0-9_]+", split_arg) is None:
7583
break
7684
elif ":" in split_arg and "=" in split_arg:
7785
find = re.search(r"\w*(?=\:)", split_arg).group()
7886
list_py_args.append(find)
7987
elif "=" in split_arg:
8088
find = re.search(r"\w*(?=\=)", split_arg).group()
8189
list_py_args.append(find)
90+
elif "def " in split_arg:
91+
pass
92+
else:
93+
find = re.search(r"\S+", split_arg).group()
94+
list_py_args.append(find)
8295
elif '"""' in line and begin_docstring is False:
8396
begin_docstring = True
8497
elif '"""' in line and begin_docstring is True:
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# Copyright (C) 2025 ANSYS, Inc. and/or its affiliates.
2+
# SPDX-License-Identifier: MIT
3+
#
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in all
13+
# copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
# SOFTWARE.
22+
23+
24+
def secmodif(
25+
self,
26+
secid,
27+
keyword,
28+
nx="",
29+
ny="",
30+
nz="",
31+
kcn="",
32+
name="",
33+
name_new="",
34+
option="",
35+
dispPnltVal="",
36+
RotPnltVal="",
37+
**kwargs,
38+
):
39+
"""Modifies a pretension section
40+
41+
APDL Command: SECMODIF
42+
43+
.. warning::
44+
45+
This command have specific signature depending on the values of the given
46+
arguments ``keyword``.
47+
48+
Parameters
49+
----------
50+
51+
secid : int
52+
Unique section number. This number must already be assigned to a
53+
section.
54+
55+
keyword : str
56+
- If `Keyword = NORM`:
57+
SECMODIF,SECID, NORM, NX, NY, NZ, KCN
58+
- If `Keyword = NAME`:
59+
SECMODIF,SECID, NAME, Name
60+
- If `Keyword = JOIN`:
61+
SECMODIF,SECID, JOIN, Option, dispPnltVal, RotPnltVal
62+
63+
norm : str
64+
Keyword specifying that the command will modify the pretension
65+
section normal direction.
66+
67+
nx, ny, nz : str
68+
Specifies the individual normal components to modify.
69+
70+
kcn : str
71+
Coordinate system number. This can be either 0 (Global Cartesian),
72+
1 (Global Cylindrical) 2 (Global Spherical), 4 (Working Plane), 5
73+
(Global Y Axis Cylindrical) or an arbitrary reference number
74+
assigned to a coordinate system.
75+
76+
name : str
77+
Change the name of the specified pretension section.
78+
79+
name_new : str
80+
The new name to be assigned to the pretension section.
81+
82+
join : str
83+
Set command actions to apply to joint sections only.
84+
85+
option : str
86+
PNLT -- Modify penalty factors for the specified section.
87+
88+
dispPnltVal : str
89+
Penalty value for displacement-based constraints:
90+
- `> 0` -- The number is used as a scaling factor to scale the
91+
internally calculated penalty values.
92+
- `< 0` -- The absolute value of the number is used as the penalty
93+
factor in calculations.
94+
95+
RotPnltVal : str
96+
Penalty value for rotation-based constraints.
97+
- `> 0` -- The number is used as a scaling factor to scale the
98+
internally calculated penalty values.
99+
- `< 0` -- The absolute value of the number is used as the penalty
100+
factor in calculations.
101+
102+
103+
Notes
104+
-----
105+
The SECMODIF command either modifies the normal for a specified
106+
pretension section, or changes the name of the specified pretension
107+
surface.
108+
"""
109+
# Sanity checks
110+
if keyword.upper() not in ["NORM", "NAME", "JOIN"]:
111+
raise ValueError(f"The given argument 'keyword' ({keyword}) is not valid.")
112+
113+
if keyword == "NORM":
114+
cmd = f"SECMODIF, {secid}, NORM, {nx}, {ny}, {nz}, {kcn}"
115+
elif keyword == "NAME":
116+
cmd = f"SECMODIF, {secid}, NAME, {name or nx}, {name_new or ny}"
117+
elif keyword == "JOIN":
118+
cmd = f"SECMODIF, {secid}, JOIN, {option or nx},{dispPnltVal or ny},{RotPnltVal or nz}"
119+
else:
120+
raise ValueError("We couldn't map the arguments given....")
121+
122+
self.run(cmd, **kwargs)

0 commit comments

Comments
 (0)