|
45 | 45 | self.run('(F20.12)') |
46 | 46 | """ |
47 | 47 |
|
| 48 | +## Invalid commands in interactive mode. |
48 | 49 | INVAL_COMMANDS = { |
49 | 50 | "*VWR": VWRITE_REPLACEMENT, |
50 | 51 | "*CFO": "Run CFOPEN as ``non_interactive``", |
|
53 | 54 | "/EOF": "Unsupported command. Use ``exit`` to stop the server.", |
54 | 55 | "*ASK": "Unsupported command. Use python ``input`` instead.", |
55 | 56 | "*IF": "Use a python ``if`` or run as non_interactive", |
56 | | - "CMATRIX": "Use as non_interactive", |
| 57 | + "CMAT": "Use as non_interactive", |
| 58 | +} |
| 59 | + |
| 60 | +## Soft-invalid commands |
| 61 | +# Invalid commands in interactive mode but their execution is just ignored. |
| 62 | +# The correspondent command is replaced by a comment using the command '\COM' |
| 63 | +# and a warning is recorded in the logger |
| 64 | +# |
| 65 | +# This commands can still be executed in ``non_interactive`` mode or using |
| 66 | +# ``Mapdl._run`` method. |
| 67 | +# |
| 68 | +# Format of the message: |
| 69 | +# f"{CMD} is ignored: {INVAL_COMMANDS_SILENT[CMD]}. |
| 70 | +# |
| 71 | +# NOTE |
| 72 | +# Obtain the command from the string supplied using |
| 73 | +# |
| 74 | +# string.split(',')[0].upper() |
| 75 | +# |
| 76 | +# This way to get the command is different from the one used in ``INVAL_COMMANDS``. |
| 77 | +# |
| 78 | +INVAL_COMMANDS_SILENT = { |
| 79 | + "/NOPR": "Suppressing console output is not recommended, use ``Mute`` parameter instead. This command is disabled in interactive mode." |
57 | 80 | } |
58 | 81 |
|
59 | 82 | PLOT_COMMANDS = ["NPLO", "EPLO", "KPLO", "LPLO", "APLO", "VPLO", "PLNS", "PLES"] |
@@ -2045,19 +2068,29 @@ def run(self, command, write_to_log=True, **kwargs): |
2045 | 2068 | # https://github.com/pyansys/pymapdl/issues/380 |
2046 | 2069 | command = "/CLE,NOSTART" |
2047 | 2070 |
|
| 2071 | + # Invalid commands silently ignored. |
| 2072 | + cmd_ = command.split(',')[0].upper() |
| 2073 | + if cmd_ in INVAL_COMMANDS_SILENT: |
| 2074 | + msg = f"{cmd_} is ignored: {INVAL_COMMANDS_SILENT[cmd_]}." |
| 2075 | + self._log.info(msg) |
| 2076 | + |
| 2077 | + # This very likely won't be recorded anywhere. |
| 2078 | + # But just in case, adding info as a comment |
| 2079 | + command = f"/COM, PyAnsys: {msg}" # Using '!' makes the output of '_run' empty |
| 2080 | + |
2048 | 2081 | if self._store_commands: |
2049 | 2082 | self._stored_commands.append(command) |
2050 | 2083 | return |
2051 | 2084 | elif command[:3].upper() in INVAL_COMMANDS: |
2052 | 2085 | exception = RuntimeError( |
2053 | 2086 | 'Invalid pymapdl command "%s"\n\n%s' |
2054 | | - % (command, INVAL_COMMANDS[command[:3]]) |
| 2087 | + % (command, INVAL_COMMANDS[command[:3].upper()]) |
2055 | 2088 | ) |
2056 | 2089 | raise exception |
2057 | 2090 | elif command[:4].upper() in INVAL_COMMANDS: |
2058 | 2091 | exception = RuntimeError( |
2059 | 2092 | 'Invalid pymapdl command "%s"\n\n%s' |
2060 | | - % (command, INVAL_COMMANDS[command[:4]]) |
| 2093 | + % (command, INVAL_COMMANDS[command[:4].upper()]) |
2061 | 2094 | ) |
2062 | 2095 | raise exception |
2063 | 2096 | elif write_to_log and self._apdl_log is not None: |
|
0 commit comments