Skip to content

Commit 444dd9e

Browse files
committed
add ScriptArgs argument
1 parent 8646e3d commit 444dd9e

File tree

1 file changed

+19
-0
lines changed
  • src/ansys/mechanical/core

1 file changed

+19
-0
lines changed

src/ansys/mechanical/core/run.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ def _cli_impl(
9191
port: int = 0,
9292
debug: bool = False,
9393
input_script: str = None,
94+
script_args: str = None,
9495
exe: str = None,
9596
version: int = None,
9697
graphical: bool = False,
@@ -111,6 +112,9 @@ def _cli_impl(
111112
if input_script:
112113
raise Exception("Cannot open in server mode with an input script.")
113114

115+
if not input_script and script_args:
116+
raise Exception("Cannot add script arguments without an input script.")
117+
114118
# If the input_script and port are missing in batch mode, raise an exception
115119
if (not graphical) and (input_script is None) and (not port):
116120
raise Exception("An input script, -i, or port, --port, are required in batch mode.")
@@ -142,6 +146,13 @@ def _cli_impl(
142146
args.append("-script")
143147
args.append(input_script)
144148

149+
if script_args:
150+
args.append("-ScriptArgs")
151+
if '"' in script_args:
152+
args.append(f"'{script_args}'")
153+
else:
154+
args.append(f'"{script_args}"')
155+
145156
if (not graphical) and input_script:
146157
exit = True
147158
if version < 241:
@@ -179,6 +190,7 @@ def _cli_impl(
179190
if DRY_RUN:
180191
return args, env
181192
else:
193+
print(args)
182194
_run(args, env, False, True)
183195

184196
if private_appdata:
@@ -218,6 +230,11 @@ def _cli_impl(
218230
default=None,
219231
help="Name of the input Python script. Cannot be mixed with -p",
220232
)
233+
@click.option(
234+
"--script-args",
235+
default=None,
236+
help="Arguments to pass into the --input-script, -i. Can only be used with -i.",
237+
)
221238
@click.option(
222239
"--exit",
223240
is_flag=True,
@@ -261,6 +278,7 @@ def cli(
261278
port: int,
262279
debug: bool,
263280
input_script: str,
281+
script_args: str,
264282
revision: int,
265283
graphical: bool,
266284
show_welcome_screen: bool,
@@ -286,6 +304,7 @@ def cli(
286304
port,
287305
debug,
288306
input_script,
307+
script_args,
289308
exe,
290309
version,
291310
graphical,

0 commit comments

Comments
 (0)