ansys-mechanical-core 0.10.10__py3-none-any.whl → 0.11.12__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. ansys/mechanical/core/__init__.py +11 -4
  2. ansys/mechanical/core/_version.py +48 -47
  3. ansys/mechanical/core/embedding/__init__.py +1 -1
  4. ansys/mechanical/core/embedding/addins.py +1 -7
  5. ansys/mechanical/core/embedding/app.py +610 -281
  6. ansys/mechanical/core/embedding/app_libraries.py +24 -5
  7. ansys/mechanical/core/embedding/appdata.py +16 -4
  8. ansys/mechanical/core/embedding/background.py +106 -0
  9. ansys/mechanical/core/embedding/cleanup_gui.py +61 -0
  10. ansys/mechanical/core/embedding/enum_importer.py +2 -2
  11. ansys/mechanical/core/embedding/imports.py +27 -7
  12. ansys/mechanical/core/embedding/initializer.py +105 -53
  13. ansys/mechanical/core/embedding/loader.py +19 -9
  14. ansys/mechanical/core/embedding/logger/__init__.py +219 -216
  15. ansys/mechanical/core/embedding/logger/environ.py +1 -1
  16. ansys/mechanical/core/embedding/logger/linux_api.py +1 -1
  17. ansys/mechanical/core/embedding/logger/sinks.py +1 -1
  18. ansys/mechanical/core/embedding/logger/windows_api.py +2 -2
  19. ansys/mechanical/core/embedding/poster.py +38 -4
  20. ansys/mechanical/core/embedding/resolver.py +41 -44
  21. ansys/mechanical/core/embedding/runtime.py +1 -1
  22. ansys/mechanical/core/embedding/shims.py +9 -8
  23. ansys/mechanical/core/embedding/ui.py +228 -0
  24. ansys/mechanical/core/embedding/utils.py +1 -1
  25. ansys/mechanical/core/embedding/viz/__init__.py +1 -1
  26. ansys/mechanical/core/embedding/viz/{pyvista_plotter.py → embedding_plotter.py} +24 -8
  27. ansys/mechanical/core/embedding/viz/usd_converter.py +59 -25
  28. ansys/mechanical/core/embedding/viz/utils.py +32 -2
  29. ansys/mechanical/core/embedding/warnings.py +1 -1
  30. ansys/mechanical/core/errors.py +2 -1
  31. ansys/mechanical/core/examples/__init__.py +1 -1
  32. ansys/mechanical/core/examples/downloads.py +10 -5
  33. ansys/mechanical/core/feature_flags.py +51 -0
  34. ansys/mechanical/core/ide_config.py +212 -0
  35. ansys/mechanical/core/launcher.py +9 -9
  36. ansys/mechanical/core/logging.py +14 -2
  37. ansys/mechanical/core/mechanical.py +2324 -2237
  38. ansys/mechanical/core/misc.py +176 -176
  39. ansys/mechanical/core/pool.py +712 -712
  40. ansys/mechanical/core/run.py +321 -246
  41. {ansys_mechanical_core-0.10.10.dist-info → ansys_mechanical_core-0.11.12.dist-info}/LICENSE +7 -7
  42. {ansys_mechanical_core-0.10.10.dist-info → ansys_mechanical_core-0.11.12.dist-info}/METADATA +57 -56
  43. ansys_mechanical_core-0.11.12.dist-info/RECORD +45 -0
  44. {ansys_mechanical_core-0.10.10.dist-info → ansys_mechanical_core-0.11.12.dist-info}/WHEEL +1 -1
  45. {ansys_mechanical_core-0.10.10.dist-info → ansys_mechanical_core-0.11.12.dist-info}/entry_points.txt +1 -0
  46. ansys_mechanical_core-0.10.10.dist-info/RECORD +0 -40
@@ -1,216 +1,219 @@
1
- # Copyright (C) 2022 - 2024 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
- """Embedding logger.
24
-
25
- Module to interact with the built-in logging system of Mechanical.
26
-
27
- Usage
28
- -----
29
-
30
- Configuring logger
31
- ~~~~~~~~~~~~~~~~~~
32
-
33
- Configuring the logger can be done using the :class:`Configuration <ansys.mechanical.core.embedding.logger.Configuration>` class:
34
-
35
- .. code:: python
36
- import ansys.mechanical.core as mech
37
- from ansys.mechanical.core.embedding.logger import Configuration, Logger
38
-
39
- Configuration.configure(level=logging.INFO, to_stdout=True, base_directory=None)
40
- app = mech.App(version=241)
41
-
42
- Then, the :class:`Logger <ansys.mechanical.core.embedding.logger.Logger>` class can be used to write messages to the log:
43
-
44
- .. code:: python
45
-
46
- Logger.error("message")
47
-
48
-
49
- """
50
-
51
- import logging
52
- import os
53
- import typing
54
-
55
- from ansys.mechanical.core.embedding import initializer
56
- from ansys.mechanical.core.embedding.logger import environ, linux_api, sinks, windows_api
57
-
58
- LOGGING_SINKS: typing.Set[int] = set()
59
- LOGGING_CONTEXT: str = "PYMECHANICAL"
60
-
61
-
62
- def _get_backend() -> (
63
- typing.Union[windows_api.APIBackend, linux_api.APIBackend, environ.EnvironBackend]
64
- ):
65
- """Get the appropriate logger backend.
66
-
67
- Before embedding is initialized, logging is configured via environment variables.
68
- After embedding is initialized, logging is configured by making API calls into the
69
- Mechanical logging system.
70
-
71
- However, the API is mostly the same in both cases, though some methods only work
72
- in one of the two backends.
73
-
74
- Setting the base directory only works before initializing.
75
- Actually logging a message or flushing the log only works after initializing.
76
- """
77
- # TODO - use abc instead of a union type?
78
- embedding_initialized = initializer.INITIALIZED_VERSION != None
79
- if not embedding_initialized:
80
- return environ.EnvironBackend()
81
- if os.name == "nt":
82
- return windows_api.APIBackend()
83
- return linux_api.APIBackend()
84
-
85
-
86
- class Configuration:
87
- """Configures logger for Mechanical embedding."""
88
-
89
- @classmethod
90
- def configure(cls, level=logging.WARNING, directory=None, base_directory=None, to_stdout=True):
91
- """Configure the logger for PyMechanical embedding.
92
-
93
- Parameters
94
- ----------
95
- level : int, optional
96
- Level of logging that is defined in the ``logging`` package. The default is 'DEBUG'.
97
- Options are ``"DEBUG"``, ``"INFO"``, ``"WARNING"``, and ``"ERROR"``.
98
- directory : str, optional
99
- Directory to write log file to. The default is ``None``, but by default the log
100
- will appear somewhere in the system temp folder.
101
- base_directory: str, optional
102
- Base directory to write log files to. Each instance of Mechanical will write its
103
- log to a time-stamped subfolder within this directory. This is only possible to set
104
- before Mechanical is initialized.
105
- to_stdout : bool, optional
106
- Whether to write log messages to the standard output, which is the
107
- command line. The default is ``True``.
108
- """
109
- # Set up the global log configuration.
110
- cls.set_log_directory(directory)
111
- cls.set_log_base_directory(base_directory)
112
-
113
- # Set up the sink-specific log configuration and store to global state.
114
- cls._store_stdout_sink_enabled(to_stdout)
115
- file_sink_enabled = directory != None or base_directory != None
116
- cls._store_file_sink_enabled(file_sink_enabled)
117
-
118
- # Commit the sink-specific log configuration global state to the backend.
119
- cls._commit_enabled_configuration()
120
- cls.set_log_level(level)
121
-
122
- @classmethod
123
- def set_log_to_stdout(cls, value: bool) -> None:
124
- """Configure logging to write to the standard output."""
125
- cls._store_stdout_sink_enabled(value)
126
- cls._commit_enabled_configuration()
127
-
128
- @classmethod
129
- def set_log_to_file(cls, value: bool) -> None:
130
- """Configure logging to write to a file."""
131
- cls._store_file_sink_enabled(value)
132
- cls._commit_enabled_configuration()
133
-
134
- @classmethod
135
- def set_log_level(cls, level: int) -> None:
136
- """Set the log level for all configured sinks."""
137
- if len(LOGGING_SINKS) == 0:
138
- raise Exception("No logging backend configured!")
139
- cls._commit_level_configuration(level)
140
-
141
- @classmethod
142
- def set_log_directory(cls, value: str) -> None:
143
- """Configure logging to write to a directory."""
144
- if value == None:
145
- return
146
- _get_backend().set_directory(value)
147
-
148
- @classmethod
149
- def set_log_base_directory(cls, directory: str) -> None:
150
- """Configure logging to write in a time-stamped subfolder in this directory."""
151
- if directory == None:
152
- return
153
- _get_backend().set_base_directory(directory)
154
-
155
- @classmethod
156
- def _commit_level_configuration(cls, level: int) -> None:
157
- for sink in LOGGING_SINKS:
158
- _get_backend().set_log_level(level, sink)
159
-
160
- @classmethod
161
- def _commit_enabled_configuration(cls) -> None:
162
- for sink in LOGGING_SINKS:
163
- _get_backend().enable(sink)
164
-
165
- @classmethod
166
- def _store_stdout_sink_enabled(cls, value: bool) -> None:
167
- if value:
168
- LOGGING_SINKS.add(sinks.StandardSinks.CONSOLE)
169
- else:
170
- LOGGING_SINKS.discard(sinks.StandardSinks.CONSOLE)
171
-
172
- @classmethod
173
- def _store_file_sink_enabled(cls, value: bool) -> None:
174
- if value:
175
- LOGGING_SINKS.add(sinks.StandardSinks.STANDARD_LOG_FILE)
176
- else:
177
- LOGGING_SINKS.discard(sinks.StandardSinks.STANDARD_LOG_FILE)
178
-
179
-
180
- class Logger:
181
- """Provides the ``Logger`` class for embedding."""
182
-
183
- @classmethod
184
- def flush(cls):
185
- """Flush the log."""
186
- _get_backend().flush()
187
-
188
- @classmethod
189
- def can_log_message(cls, level: int) -> bool:
190
- """Get whether a message at this level is logged."""
191
- return _get_backend().can_log_message(level)
192
-
193
- @classmethod
194
- def debug(cls, msg: str):
195
- """Write a debug message to the log."""
196
- _get_backend().log_message(logging.DEBUG, LOGGING_CONTEXT, msg)
197
-
198
- @classmethod
199
- def error(cls, msg: str):
200
- """Write a error message to the log."""
201
- _get_backend().log_message(logging.ERROR, LOGGING_CONTEXT, msg)
202
-
203
- @classmethod
204
- def info(cls, msg: str):
205
- """Write an info message to the log."""
206
- _get_backend().log_message(logging.INFO, LOGGING_CONTEXT, msg)
207
-
208
- @classmethod
209
- def warning(cls, msg: str):
210
- """Write a warning message to the log."""
211
- _get_backend().log_message(logging.WARNING, LOGGING_CONTEXT, msg)
212
-
213
- @classmethod
214
- def fatal(cls, msg: str):
215
- """Write a fatal message to the log."""
216
- _get_backend().log_message(logging.FATAL, LOGGING_CONTEXT, msg)
1
+ # Copyright (C) 2022 - 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
+ """Embedding logger.
24
+
25
+ Module to interact with the built-in logging system of Mechanical.
26
+
27
+ Usage
28
+ -----
29
+
30
+ Configuring logger
31
+ ~~~~~~~~~~~~~~~~~~
32
+
33
+ Configuring the logger can be done using the :class:`Configuration <ansys.mechanical.core.embedding.logger.Configuration>` class:
34
+
35
+ .. code:: python
36
+ import ansys.mechanical.core as mech
37
+ from ansys.mechanical.core.embedding.logger import Configuration, Logger
38
+
39
+ Configuration.configure(level=logging.INFO, to_stdout=True, base_directory=None)
40
+ app = mech.App(version=251)
41
+
42
+ Then, the :class:`Logger <ansys.mechanical.core.embedding.logger.Logger>` class can be used to write messages to the log:
43
+
44
+ .. code:: python
45
+
46
+ Logger.error("message")
47
+
48
+
49
+ """
50
+
51
+ import logging
52
+ import os
53
+ import typing
54
+
55
+ from ansys.mechanical.core.embedding import initializer
56
+ from ansys.mechanical.core.embedding.logger import environ, linux_api, sinks, windows_api
57
+
58
+ LOGGING_SINKS: typing.Set[int] = set()
59
+ """Constant for logging sinks."""
60
+
61
+ LOGGING_CONTEXT: str = "PYMECHANICAL"
62
+ """Constant for logging context."""
63
+
64
+
65
+ def _get_backend() -> (
66
+ typing.Union[windows_api.APIBackend, linux_api.APIBackend, environ.EnvironBackend]
67
+ ):
68
+ """Get the appropriate logger backend.
69
+
70
+ Before embedding is initialized, logging is configured via environment variables.
71
+ After embedding is initialized, logging is configured by making API calls into the
72
+ Mechanical logging system.
73
+
74
+ However, the API is mostly the same in both cases, though some methods only work
75
+ in one of the two backends.
76
+
77
+ Setting the base directory only works before initializing.
78
+ Actually logging a message or flushing the log only works after initializing.
79
+ """
80
+ # TODO - use abc instead of a union type?
81
+ embedding_initialized = initializer.INITIALIZED_VERSION is not None
82
+ if not embedding_initialized:
83
+ return environ.EnvironBackend()
84
+ if os.name == "nt":
85
+ return windows_api.APIBackend()
86
+ return linux_api.APIBackend()
87
+
88
+
89
+ class Configuration:
90
+ """Configures logger for Mechanical embedding."""
91
+
92
+ @classmethod
93
+ def configure(cls, level=logging.WARNING, directory=None, base_directory=None, to_stdout=True):
94
+ """Configure the logger for PyMechanical embedding.
95
+
96
+ Parameters
97
+ ----------
98
+ level : int, optional
99
+ Level of logging that is defined in the ``logging`` package. The default is 'DEBUG'.
100
+ Options are ``"DEBUG"``, ``"INFO"``, ``"WARNING"``, and ``"ERROR"``.
101
+ directory : str, optional
102
+ Directory to write log file to. The default is ``None``, but by default the log
103
+ will appear somewhere in the system temp folder.
104
+ base_directory: str, optional
105
+ Base directory to write log files to. Each instance of Mechanical will write its
106
+ log to a time-stamped subfolder within this directory. This is only possible to set
107
+ before Mechanical is initialized.
108
+ to_stdout : bool, optional
109
+ Whether to write log messages to the standard output, which is the
110
+ command line. The default is ``True``.
111
+ """
112
+ # Set up the global log configuration.
113
+ cls.set_log_directory(directory)
114
+ cls.set_log_base_directory(base_directory)
115
+
116
+ # Set up the sink-specific log configuration and store to global state.
117
+ cls._store_stdout_sink_enabled(to_stdout)
118
+ file_sink_enabled = directory is not None or base_directory is not None
119
+ cls._store_file_sink_enabled(file_sink_enabled)
120
+
121
+ # Commit the sink-specific log configuration global state to the backend.
122
+ cls._commit_enabled_configuration()
123
+ cls.set_log_level(level)
124
+
125
+ @classmethod
126
+ def set_log_to_stdout(cls, value: bool) -> None:
127
+ """Configure logging to write to the standard output."""
128
+ cls._store_stdout_sink_enabled(value)
129
+ cls._commit_enabled_configuration()
130
+
131
+ @classmethod
132
+ def set_log_to_file(cls, value: bool) -> None:
133
+ """Configure logging to write to a file."""
134
+ cls._store_file_sink_enabled(value)
135
+ cls._commit_enabled_configuration()
136
+
137
+ @classmethod
138
+ def set_log_level(cls, level: int) -> None:
139
+ """Set the log level for all configured sinks."""
140
+ if len(LOGGING_SINKS) == 0:
141
+ raise Exception("No logging backend configured!")
142
+ cls._commit_level_configuration(level)
143
+
144
+ @classmethod
145
+ def set_log_directory(cls, value: str) -> None:
146
+ """Configure logging to write to a directory."""
147
+ if value is None:
148
+ return
149
+ _get_backend().set_directory(value)
150
+
151
+ @classmethod
152
+ def set_log_base_directory(cls, directory: str) -> None:
153
+ """Configure logging to write in a time-stamped subfolder in this directory."""
154
+ if directory is None:
155
+ return
156
+ _get_backend().set_base_directory(directory)
157
+
158
+ @classmethod
159
+ def _commit_level_configuration(cls, level: int) -> None:
160
+ for sink in LOGGING_SINKS:
161
+ _get_backend().set_log_level(level, sink)
162
+
163
+ @classmethod
164
+ def _commit_enabled_configuration(cls) -> None:
165
+ for sink in LOGGING_SINKS:
166
+ _get_backend().enable(sink)
167
+
168
+ @classmethod
169
+ def _store_stdout_sink_enabled(cls, value: bool) -> None:
170
+ if value:
171
+ LOGGING_SINKS.add(sinks.StandardSinks.CONSOLE)
172
+ else:
173
+ LOGGING_SINKS.discard(sinks.StandardSinks.CONSOLE)
174
+
175
+ @classmethod
176
+ def _store_file_sink_enabled(cls, value: bool) -> None:
177
+ if value:
178
+ LOGGING_SINKS.add(sinks.StandardSinks.STANDARD_LOG_FILE)
179
+ else:
180
+ LOGGING_SINKS.discard(sinks.StandardSinks.STANDARD_LOG_FILE)
181
+
182
+
183
+ class Logger:
184
+ """Provides the ``Logger`` class for embedding."""
185
+
186
+ @classmethod
187
+ def flush(cls):
188
+ """Flush the log."""
189
+ _get_backend().flush()
190
+
191
+ @classmethod
192
+ def can_log_message(cls, level: int) -> bool:
193
+ """Get whether a message at this level is logged."""
194
+ return _get_backend().can_log_message(level)
195
+
196
+ @classmethod
197
+ def debug(cls, msg: str):
198
+ """Write a debug message to the log."""
199
+ _get_backend().log_message(logging.DEBUG, LOGGING_CONTEXT, msg)
200
+
201
+ @classmethod
202
+ def error(cls, msg: str):
203
+ """Write a error message to the log."""
204
+ _get_backend().log_message(logging.ERROR, LOGGING_CONTEXT, msg)
205
+
206
+ @classmethod
207
+ def info(cls, msg: str):
208
+ """Write an info message to the log."""
209
+ _get_backend().log_message(logging.INFO, LOGGING_CONTEXT, msg)
210
+
211
+ @classmethod
212
+ def warning(cls, msg: str):
213
+ """Write a warning message to the log."""
214
+ _get_backend().log_message(logging.WARNING, LOGGING_CONTEXT, msg)
215
+
216
+ @classmethod
217
+ def fatal(cls, msg: str):
218
+ """Write a fatal message to the log."""
219
+ _get_backend().log_message(logging.FATAL, LOGGING_CONTEXT, msg)
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2022 - 2024 ANSYS, Inc. and/or its affiliates.
1
+ # Copyright (C) 2022 - 2025 ANSYS, Inc. and/or its affiliates.
2
2
  # SPDX-License-Identifier: MIT
3
3
  #
4
4
  #
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2022 - 2024 ANSYS, Inc. and/or its affiliates.
1
+ # Copyright (C) 2022 - 2025 ANSYS, Inc. and/or its affiliates.
2
2
  # SPDX-License-Identifier: MIT
3
3
  #
4
4
  #
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2022 - 2024 ANSYS, Inc. and/or its affiliates.
1
+ # Copyright (C) 2022 - 2025 ANSYS, Inc. and/or its affiliates.
2
2
  # SPDX-License-Identifier: MIT
3
3
  #
4
4
  #
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2022 - 2024 ANSYS, Inc. and/or its affiliates.
1
+ # Copyright (C) 2022 - 2025 ANSYS, Inc. and/or its affiliates.
2
2
  # SPDX-License-Identifier: MIT
3
3
  #
4
4
  #
@@ -41,7 +41,7 @@ def _get_logger():
41
41
  import Ansys
42
42
 
43
43
  return Ansys.Common.WB1ManagedUtils.Logger
44
- except:
44
+ except (ImportError, RuntimeError):
45
45
  raise Exception("Logging cannot be used until after Mechanical embedding is initialized.")
46
46
 
47
47
 
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2022 - 2024 ANSYS, Inc. and/or its affiliates.
1
+ # Copyright (C) 2022 - 2025 ANSYS, Inc. and/or its affiliates.
2
2
  # SPDX-License-Identifier: MIT
3
3
  #
4
4
  #
@@ -25,6 +25,19 @@
25
25
  import typing
26
26
 
27
27
 
28
+ class PosterError(Exception):
29
+ """Class which holds errors from the background thread posting system."""
30
+
31
+ def __init__(self, error: Exception):
32
+ """Create an instance to hold the given error."""
33
+ self._error = error
34
+
35
+ @property
36
+ def error(self) -> Exception:
37
+ """Get the underlying exception."""
38
+ return self._error
39
+
40
+
28
41
  class Poster:
29
42
  """Class which can post a python callable function to Mechanical's main thread."""
30
43
 
@@ -37,15 +50,36 @@ class Poster:
37
50
 
38
51
  self._poster = Ans.Common.WB1ManagedUtils.TaskPoster
39
52
 
40
- def post(self, callable: typing.Callable):
53
+ def try_post(self, callable: typing.Callable) -> typing.Any:
54
+ """Post the callable to Mechanical's main thread.
55
+
56
+ This does the same thing as `post` but if `callable`
57
+ raises an exception, try_post will raise the same
58
+ exception to the caller of `try_post`.
59
+ """
60
+
61
+ def wrapped():
62
+ try:
63
+ return callable()
64
+ except Exception as e:
65
+ return PosterError(e)
66
+
67
+ result = self.post(wrapped)
68
+ if isinstance(result, PosterError):
69
+ raise result.error
70
+ return result
71
+
72
+ def post(self, callable: typing.Callable) -> typing.Any:
41
73
  """Post the callable to Mechanical's main thread.
42
74
 
43
75
  The main thread needs to be receiving posted messages
44
76
  in order for this to work from a background thread. Use
45
77
  the `sleep` routine from the `utils` module to make
46
78
  Mechanical available to receive messages.
79
+
80
+ Returns the result of `callable` if any.
47
81
  """
48
82
  import System
49
83
 
50
- action = System.Action(callable)
51
- self._poster.Post(action)
84
+ func = System.Func[System.Object](callable)
85
+ return self._poster.Get[System.Object](func)
@@ -1,44 +1,41 @@
1
- # Copyright (C) 2022 - 2024 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
- """This is the .NET assembly resolving for embedding Ansys Mechanical.
24
-
25
- Note that for some Mechanical Addons - additional resolving may be
26
- necessary. A resolve handler is shipped with Ansys Mechanical on windows
27
- starting in version 23.1 and on linux starting in version 23.2
28
- """
29
-
30
-
31
- def resolve(version):
32
- """Resolve function for all versions of Ansys Mechanical."""
33
- import clr # isort: skip
34
- import System # isort: skip
35
-
36
- clr.AddReference("Ansys.Mechanical.Embedding")
37
- import Ansys # isort: skip
38
-
39
- assembly_resolver = Ansys.Mechanical.Embedding.AssemblyResolver
40
- if version == 231: # pragma: no cover
41
- resolve_handler = assembly_resolver.WindowsResolveEventHandler
42
- else:
43
- resolve_handler = assembly_resolver.MechanicalResolveEventHandler
44
- System.AppDomain.CurrentDomain.AssemblyResolve += resolve_handler
1
+ # Copyright (C) 2022 - 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
+ """This is the .NET assembly resolving for embedding Ansys Mechanical.
24
+
25
+ Note that for some Mechanical Addons - additional resolving may be
26
+ necessary. A resolve handler is shipped with Ansys Mechanical on Windows
27
+ starting in version 23.1 and on Linux starting in version 23.2
28
+ """
29
+
30
+
31
+ def resolve(version):
32
+ """Resolve function for all versions of Ansys Mechanical."""
33
+ import clr # isort: skip
34
+ import System # isort: skip
35
+
36
+ clr.AddReference("Ansys.Mechanical.Embedding")
37
+ import Ansys # isort: skip
38
+
39
+ assembly_resolver = Ansys.Mechanical.Embedding.AssemblyResolver
40
+ resolve_handler = assembly_resolver.MechanicalResolveEventHandler
41
+ System.AppDomain.CurrentDomain.AssemblyResolve += resolve_handler
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2022 - 2024 ANSYS, Inc. and/or its affiliates.
1
+ # Copyright (C) 2022 - 2025 ANSYS, Inc. and/or its affiliates.
2
2
  # SPDX-License-Identifier: MIT
3
3
  #
4
4
  #