ansys-pyensight-core 0.11.0__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 (37) hide show
  1. ansys/pyensight/core/__init__.py +41 -0
  2. ansys/pyensight/core/common.py +341 -0
  3. ansys/pyensight/core/deep_pixel_view.html +98 -0
  4. ansys/pyensight/core/dockerlauncher.py +1124 -0
  5. ansys/pyensight/core/dvs.py +872 -0
  6. ansys/pyensight/core/enscontext.py +345 -0
  7. ansys/pyensight/core/enshell_grpc.py +641 -0
  8. ansys/pyensight/core/ensight_grpc.py +874 -0
  9. ansys/pyensight/core/ensobj.py +515 -0
  10. ansys/pyensight/core/launch_ensight.py +296 -0
  11. ansys/pyensight/core/launcher.py +388 -0
  12. ansys/pyensight/core/libuserd.py +2110 -0
  13. ansys/pyensight/core/listobj.py +280 -0
  14. ansys/pyensight/core/locallauncher.py +579 -0
  15. ansys/pyensight/core/py.typed +0 -0
  16. ansys/pyensight/core/renderable.py +880 -0
  17. ansys/pyensight/core/session.py +1923 -0
  18. ansys/pyensight/core/sgeo_poll.html +24 -0
  19. ansys/pyensight/core/utils/__init__.py +21 -0
  20. ansys/pyensight/core/utils/adr.py +111 -0
  21. ansys/pyensight/core/utils/dsg_server.py +1220 -0
  22. ansys/pyensight/core/utils/export.py +606 -0
  23. ansys/pyensight/core/utils/omniverse.py +769 -0
  24. ansys/pyensight/core/utils/omniverse_cli.py +614 -0
  25. ansys/pyensight/core/utils/omniverse_dsg_server.py +1196 -0
  26. ansys/pyensight/core/utils/omniverse_glb_server.py +848 -0
  27. ansys/pyensight/core/utils/parts.py +1221 -0
  28. ansys/pyensight/core/utils/query.py +487 -0
  29. ansys/pyensight/core/utils/readers.py +300 -0
  30. ansys/pyensight/core/utils/resources/Materials/000_sky.exr +0 -0
  31. ansys/pyensight/core/utils/support.py +128 -0
  32. ansys/pyensight/core/utils/variables.py +2019 -0
  33. ansys/pyensight/core/utils/views.py +674 -0
  34. ansys_pyensight_core-0.11.0.dist-info/METADATA +309 -0
  35. ansys_pyensight_core-0.11.0.dist-info/RECORD +37 -0
  36. ansys_pyensight_core-0.11.0.dist-info/WHEEL +4 -0
  37. ansys_pyensight_core-0.11.0.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,515 @@
1
+ # Copyright (C) 2022 - 2026 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
+ """ensobj module
24
+
25
+ The ensobj module provides the base class to all EnSight proxy objects
26
+
27
+ """
28
+ from typing import TYPE_CHECKING, Any, Optional, no_type_check
29
+
30
+ if TYPE_CHECKING:
31
+ from ansys.pyensight.core import Session
32
+
33
+
34
+ class ENSOBJ(object):
35
+ """Bass class for all EnSight proxy objects
36
+
37
+ The ENSOBJ class is the base class for the EnSight object proxy interface.
38
+ Note: this interface is internal and applications should not attempt to
39
+ create ENSOBJ instances directly.
40
+
41
+ Parameters
42
+ ----------
43
+ session :
44
+ The session object associated with this object instance.
45
+ objid :
46
+ The EnSight CvfObjID of the object instance that this instance will
47
+ serve as the proxy for.
48
+ attr_id :
49
+ For subclasses that differentiate classes by an attribute value,
50
+ this is the attribute ID to use as the differentiator. Example
51
+ classes are ENS_TOOL, ENS_PART and ENS_ANNOT.
52
+ attr_value :
53
+ The attribute value associated with any specified attr_id.
54
+ owned : bool
55
+ If True, the object is assumed to be "owned" by this interpreter.
56
+ This means that the lifecycle of the ENSOBJ instance in EnSight is
57
+ dictated by the lifecycle of this proxy object.
58
+
59
+ """
60
+
61
+ def __init__(
62
+ self,
63
+ session: "Session",
64
+ objid: int,
65
+ attr_id: Optional[int] = None,
66
+ attr_value: Optional[int] = None,
67
+ owned: Optional[bool] = None,
68
+ ) -> None:
69
+ self._session = session
70
+ self._objid = objid
71
+ self._attr_id = attr_id
72
+ self._attr_value = attr_value
73
+
74
+ # True if this Python instance "owns" the ENSOBJ instance (via EnSight proxy cache)
75
+ if owned:
76
+ self._is_owned = True
77
+ else:
78
+ self._is_owned = False
79
+ # do not put this object in the cache if it is owned, allow gc
80
+ self._session.add_ensobj_instance(self)
81
+
82
+ def __eq__(self, obj):
83
+ return self._objid == obj._objid
84
+
85
+ def __lt__(self, obj):
86
+ return self._objid < obj._objid
87
+
88
+ def __hash__(self):
89
+ return self._objid
90
+
91
+ def __del__(self):
92
+ # release the session to allow for garbage collection
93
+ tmp_session = self._session
94
+ self._session = None
95
+ if self._is_owned:
96
+ try:
97
+ cmd = f"ensight.objs.release_id('{tmp_session.name}', {self.__OBJID__})"
98
+ tmp_session.cmd(cmd, do_eval=False)
99
+ except Exception: # pragma: no cover
100
+ # This could happen at any time, including outside
101
+ # the scope of the session, so we need to be
102
+ # ready for any error.
103
+ pass
104
+
105
+ @property
106
+ def __OBJID__(self) -> int: # noqa: N802
107
+ return self._objid
108
+
109
+ def _remote_obj(self) -> str:
110
+ """Convert the object into a string appropriate for use in the
111
+ remote EnSight session. Usually, this is some form of
112
+ ensight.objs.wrap_id()."""
113
+ return self._session.remote_obj(self._objid)
114
+
115
+ def getattr(self, attrid: Any) -> Any:
116
+ """Query the value of the specified attribute
117
+
118
+ Parameters
119
+ ----------
120
+ attrid: Any
121
+ The attribute to query
122
+
123
+ Returns
124
+ -------
125
+ Any
126
+ The current value of the attribute.
127
+
128
+ Examples
129
+ --------
130
+ These commands are equivalent
131
+
132
+ >>> v = part.VISIBLE
133
+ >>> v = part.getattr("VISIBLE")
134
+ >>> v = part.getattr(session.ensight.objs.enums.VISIBLE)
135
+ """
136
+ return self._session.cmd(f"{self._remote_obj()}.getattr({attrid.__repr__()})")
137
+
138
+ def getattrs(self, attrid: Optional[list] = None, text: int = 0) -> dict:
139
+ """Query the value of a collection of attributes
140
+
141
+ This method queries a collection of attributes in a single call and
142
+ returns the attribute values in a dictionary keyed by the attribute ids.
143
+
144
+ Parameters
145
+ ----------
146
+ attrid : Optional[list]
147
+ If this value is a list (of attribute ids as strings or enum values),
148
+ then the returned dictionary will only include values for the specified
149
+ attributes. Otherwise, the returned dictionary will include values for
150
+ all attributes of the target object.
151
+ text : int
152
+ By default, the returned dictionary keys are the attribute ID enum
153
+ values. If text is set to 1, the dictionary keys will be strings.
154
+ Return:
155
+
156
+ Returns
157
+ -------
158
+ Session CMD.
159
+
160
+ Examples
161
+ --------
162
+ To copy some attributes from one part to another.
163
+
164
+ >>> tmp = part0.getattrs(["VISIBLE", session.ensight.objs.enums.OPAQUENESS])
165
+ >>> part1.setattrs(tmp)
166
+
167
+ """
168
+ if attrid is None:
169
+ cmd = f"{self._remote_obj()}.getattrs(text={text})"
170
+ else:
171
+ cmd = f"{self._remote_obj()}.getattrs({attrid.__repr__()},text={text})"
172
+ return self._session.cmd(cmd)
173
+
174
+ def setattr(self, attrid: Any, value: Any) -> None:
175
+ """Set the value of the specified attribute
176
+
177
+ Parameters
178
+ ----------
179
+ attrid : Any
180
+ The attribute to set. This can be an integer (enum) or string.
181
+ value : Any
182
+ The value to set the attribute to.
183
+
184
+ Returns
185
+ -------
186
+ Session CMD.
187
+
188
+ Examples
189
+ --------
190
+ These commands are equivalent
191
+
192
+ >>> part.setattr("VISIBLE", True)
193
+ >>> part.getattr(session.ensight.objs.enums.VISIBLE, True)
194
+
195
+ """
196
+ return self._session.cmd(
197
+ f"{self._remote_obj()}.setattr({attrid.__repr__()}, {value.__repr__()})"
198
+ )
199
+
200
+ def setattrs(self, values: dict, all_errors: int = 0) -> None:
201
+ """Set the values of a collection of attributes
202
+
203
+ Parameters
204
+ ----------
205
+ values : Dict
206
+ The values to set. The keys are the attribute IDs.
207
+ all_errors : int
208
+ If non-zero, raise a RuntimeError exception if any attribute set
209
+ operation fails. By default, 0.
210
+
211
+ Examples
212
+ --------
213
+ These commands are equivalent
214
+
215
+ >>> part.VISIBLE = True
216
+ >>> part.setattrs(dict(VISIBLE=True))
217
+ >>> part.setattrs({session.ensight.objs.enums.VISIBLE: True})
218
+
219
+ """
220
+ cmd = f"{self._remote_obj()}.setattrs({values.__repr__()}, all_errors={all_errors})"
221
+ return self._session.cmd(cmd)
222
+
223
+ def attrinfo(self, attrid: Optional[Any] = None) -> dict:
224
+ """For a given attribute id, return type information
225
+
226
+ The dictionary returned by will always have the following keys:
227
+ - `type` the high-level type. This can include any of the values noted in the next
228
+ section
229
+
230
+ - `basetype` the low-level type. Only types starting with `CVF` are allowed.
231
+
232
+ - `numvals` the number of values of the `basetype`.
233
+
234
+ - `desc` string description for the attr
235
+
236
+ - `name` the python legal name for the attr
237
+
238
+ - `flags` this integer is formed by or-ing values from the table below
239
+
240
+ Optional keys:
241
+ - `range` if selected in the flags, this key will be a list of two floats or
242
+ ints: [min,max]. see `flags` below
243
+
244
+ - `enums` if selected in the flags, this key will be list of lists. Each list has
245
+ three values: [int_value, description, python_name]. The integer value is the number
246
+ for the enum (see `flags` below), while the other two values are human and Python
247
+ strings. The python_name will also be available as an integer in the
248
+ ensight.objs.enums module.
249
+
250
+ - `dependencies` if present, this key is a list of dictionaries that describe the
251
+ fact that this attr is dependent on another attr. The dictionary is described below.
252
+
253
+ Parameters
254
+ ----------
255
+ attrid : Optional[Any]
256
+ The attribute to query
257
+
258
+ Returns
259
+ -------
260
+ dict
261
+ A dictionary that describes type information for the attribute.
262
+
263
+ Examples
264
+ --------
265
+ >>> part.attrinfo(session.ensight.objs.enums.VISIBLE)
266
+
267
+ """
268
+ if not attrid:
269
+ return self._session.cmd(f"{self._remote_obj()}.attrinfo()")
270
+ return self._session.cmd(f"{self._remote_obj()}.attrinfo({attrid.__repr__()})")
271
+
272
+ def attrissensitive(self, attrid: Any) -> bool:
273
+ """Check to see if a given attribute is 'sensitive'
274
+
275
+ Given the current state of the target object, return True if it makes sense to
276
+ allow the specified attribute to change. Return False if the object is currently
277
+ ignoring the value of a given attribute due to the state of other attributes.
278
+
279
+ Parameters
280
+ ----------
281
+ attrid : Any
282
+ The attribute to query
283
+
284
+ Returns
285
+ -------
286
+ bool
287
+ True or False
288
+
289
+ """
290
+ return self._session.cmd(f"{self._remote_obj()}.attrissensitive({attrid.__repr__()})")
291
+
292
+ def attrtree(
293
+ self,
294
+ all: int = 0,
295
+ filter: Optional[list] = None,
296
+ exclude: Optional[list] = None,
297
+ include: Optional[list] = None,
298
+ group_exclude: Optional[list] = None,
299
+ group_include: Optional[list] = None,
300
+ insensitive: int = 1,
301
+ ) -> dict:
302
+ """Get detailed GUI information for attributes of this object.
303
+
304
+ This method is on MOST of the intrinsic objects, but not all of them. This method is used
305
+ to generate a "visual" tree of an object's attributes. The most common use would be to
306
+ dynamically generate labels and hierarchy for a "property sheet" editor.
307
+
308
+ The method returns an object tree that describes the way attribute should be laid out.
309
+ Each object has three attributes: `attr`, 'hasdeps' and `name`. All objects will have names
310
+ and group objects will have an attr of -1. All objects can also be iterated for children
311
+ objects of the same type. Only objects with an `attr` of -1 will have children. len() can
312
+ be used to get the number of child objects. The top level object always has the name
313
+ `root`. The 'hasdeps' attribute is the number of attributes in this attrtree() that have
314
+ a dependency on this attr. This can be used to decide if a new sensitivity check is needed
315
+ if a given attribute changes.
316
+
317
+ Parameters
318
+ ----------
319
+ all : int
320
+ If set to 1 will include all attrs for the object, even if they are not in the group
321
+ tables.
322
+ filter : Optional[list]
323
+ Should be set to an optional list of EnSight objects. The output will be filtered
324
+ to include only the attributes in common between all of the objects (they do not
325
+ need to be of the same type).
326
+ include : Optional[list]
327
+ Should be set to a list of attribute enums. Only the enums in the list will be
328
+ included in the output object tree. Note: passing an empty list via this keyword,
329
+ all the enums will be initially excluded. This is useful with the
330
+ group_include= keyword.
331
+ exclude : Optional[list]
332
+ Should be set to a list of attribute enums. Any enums in the list will be
333
+ removed from the output object tree.
334
+ group_exclude : Optional[list]
335
+ Should be set to a list of attribute enums. For any enum in this list, exclude
336
+ the enum and all the other enums in the same groups as the passed enums. Think
337
+ of this as a shortcut for exclude= that requires you to only pass a single enum
338
+ in the group you want to suppress.
339
+ group_include : Optional[list]
340
+ Should be set to a list of attribute enums. For any enum in this list, include
341
+ the enum and all the other enums in the same groups as the passed enums. Think
342
+ of this as a shortcut for include= that requires you to only pass a single enum
343
+ in the group you want to include. Note: it may be necessary to pass include=[]
344
+ (the empty list) to start with an empty list of enums.
345
+ insensitive : int
346
+ If this keyword is set to 0, attrtree() will call foo.issensitive() on each
347
+ filtered attr and if the attr is not currently sensitive, it will remove it
348
+ from the output. The default value for this keyword is 1 which disables all
349
+ sensitivity filtering.
350
+
351
+ Examples
352
+ --------
353
+
354
+ >>> def walk_tree(part,obj,s):
355
+ >>> a = obj.attr
356
+ >>> if (a == -1):
357
+ >>> print("{}Group={}".format(s, obj.name)))
358
+ >>> else:
359
+ >>> = part.attrinfo(a)
360
+ >>> t = enum_to_name(a)
361
+ >>> d = info['desc']
362
+ >>> print("{}Attr={} - '{}' ({:d} deps)".format(s, t, d, obj.hasdeps))
363
+ >>> for i in obj:
364
+ >>> walk_tree(part,i,s+" ")
365
+ >>> walk_tree(session.ensight.core.PARTS[0],session.ensight.core.PARTS[0].attrtree(),"")
366
+ """
367
+ obj = f"{self._remote_obj()}"
368
+ options = f"all={all}"
369
+ options += f",insensitive={insensitive}"
370
+ if filter:
371
+ options += f",filter={filter.__repr__()}"
372
+ if include:
373
+ options += f",include={include.__repr__()}"
374
+ if exclude:
375
+ options += f",exclude={exclude.__repr__()}"
376
+ if group_exclude:
377
+ options += f",group_exclude={group_exclude.__repr__()}"
378
+ if group_include:
379
+ options += f",group_include={group_include.__repr__()}"
380
+ return self._session.cmd(f"{obj}.attrgroupinfo({options})")
381
+
382
+ def setattr_begin(self) -> None:
383
+ """Signal bulk attribute update begin
384
+
385
+ By default, EnSight will update the display with every attribute change. If a lot of
386
+ changes are to be made, this can slow execution down. Putting a collection of changes
387
+ inside of a setattr_begin()/setattr_end() pair of calls will defer the update until the
388
+ setattr_end() call is made.
389
+
390
+ """
391
+ return self._session.cmd(f"{self._remote_obj()}.setattr_begin()")
392
+
393
+ def setattr_end(self) -> None:
394
+ """Signal bulk attribute update end
395
+
396
+ By default, EnSight will update the display with every attribute change. If a lot of
397
+ changes are to be made, this can slow execution down. Putting a collection of changes
398
+ inside of a setattr_begin()/setattr_end() pair of calls will defer the update until the
399
+ setattr_end() call is made.
400
+
401
+ """
402
+ return self._session.cmd(f"{self._remote_obj()}.setattr_end()")
403
+
404
+ def setattr_status(self) -> int:
405
+ """ """
406
+ return self._session.cmd(f"{self._remote_obj()}.setattr_status()")
407
+
408
+ def setmetatag(self, tag: str, value: Optional[Any]) -> None:
409
+ """Change a value in the METADATA attribute
410
+
411
+ All ENSOBJ subclasses have a METADATA read only attribute that is viewed as a Python
412
+ dictionary. A value can be set in that dictionary using this call:
413
+
414
+ Parameters
415
+ ----------
416
+ tag : str
417
+ The string name of the METADATA tag to add/change.
418
+ value : Any, optional
419
+ The value to change to tag to. Note: this can be a string, int or float.
420
+
421
+ Examples
422
+ --------
423
+ >>> session.ensight.objs.core.PARTS[0].setmetatag("FOO", "HELLO")
424
+ >>> print(session.ensight.objs.core.PARTS[0].METADATA)
425
+
426
+ """
427
+ if value is None:
428
+ cmd = f"{self._remote_obj()}.setmetatag({tag.__repr__()})"
429
+ else:
430
+ cmd = f"{self._remote_obj()}.setmetatag({tag.__repr__()}, {value.__repr__()})"
431
+ return self._session.cmd(cmd)
432
+
433
+ def hasmetatag(self, tag: str) -> bool:
434
+ """Check to see if a tag exists in the METADATA attribute
435
+
436
+ Parameters
437
+ ----------
438
+ tag : str
439
+ The string name of the METADATA tag to check
440
+
441
+ Returns
442
+ -------
443
+ bool
444
+ True if the named tag exists in the METADATA attribute.
445
+
446
+ """
447
+ return self._session.cmd(f"{self._remote_obj()}.hasmetatag({tag.__repr__()})")
448
+
449
+ def getmetatag(self, tag: str) -> Any:
450
+ """Get the value of a tag in the METADATA attribute
451
+
452
+ Parameters
453
+ ----------
454
+ tag : str
455
+
456
+ The string name of the METADATA tag to get
457
+
458
+ Returns
459
+ -------
460
+ Any
461
+ The value assigned to the tag in the METADATA attribute.
462
+
463
+ Examples
464
+ --------
465
+ >>> session.ensight.objs.core.PARTS[0].setmetatag("FOO", "HELLO")
466
+ >>> print(session.ensight.objs.core.PARTS[0].getmetatag("FOO"))
467
+
468
+ """
469
+ return self._session.cmd(f"{self._remote_obj()}.getmetatag({tag.__repr__()})")
470
+
471
+ def destroy(self) -> None:
472
+ """Destroy the EnSight object associated with this proxy object"""
473
+ self._session.cmd(f"{self._remote_obj()}.destroy()")
474
+
475
+ def __str__(self) -> str:
476
+ desc = ""
477
+ if hasattr(self.__class__, "attr_list"): # pragma: no cover
478
+ if self._session.ensight.objs.enums.DESCRIPTION in self.__class__.attr_list:
479
+ try:
480
+ if hasattr(self, "DESCRIPTION"): # pragma: no cover
481
+ desc_text = self.DESCRIPTION
482
+ else:
483
+ desc_text = ""
484
+ except RuntimeError: # pragma: no cover
485
+ # self.DESCRIPTION is a gRPC call that can fail for default objects
486
+ desc_text = "" # pragma: no cover
487
+ desc = f", desc: '{desc_text}'"
488
+ owned = ""
489
+ if self._is_owned:
490
+ owned = ", Owned"
491
+ return f"Class: {self.__class__.__name__}{desc}{owned}, CvfObjID: {self._objid}, cached:no"
492
+
493
+ def __repr__(self) -> str:
494
+ """Custom __repr__ method used by the stub API.
495
+
496
+ In some cases, we need to specify the object representation in the EnSight
497
+ instance. For ENSOBJ instances, this means using the wrap_id() mechanism
498
+ instead of the built-in __repr__. So the generated API uses this interface.
499
+ """
500
+ return f"ensight.objs.wrap_id({self._objid})"
501
+
502
+ @no_type_check
503
+ def _repr_pretty_(self, p: "pretty", cycle: bool) -> None:
504
+ """Support the pretty module for better IPython support.
505
+
506
+ Parameters
507
+ ----------
508
+ p: str
509
+ pretty flag.
510
+
511
+ cycle: bool :
512
+ cycle flag.
513
+
514
+ """
515
+ p.text(self.__str__())