-
Notifications
You must be signed in to change notification settings - Fork 142
/
Copy pathPrimitives.py
9104 lines (7929 loc) · 319 KB
/
Primitives.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""
This module contains these Primitives classes: `Polyline` and `Primitives`.
"""
from __future__ import absolute_import # noreorder
from collections import OrderedDict
import copy
import math
import os
import random
import string
import time
import warnings
from pyaedt.application.Variables import Variable
from pyaedt.application.Variables import decompose_variable_value
from pyaedt.generic.DataHandlers import json_to_dict
from pyaedt.generic.constants import AEDT_UNITS
from pyaedt.generic.general_methods import _dim_arg
from pyaedt.generic.general_methods import _uname
from pyaedt.generic.general_methods import generate_unique_name
from pyaedt.generic.general_methods import is_number
from pyaedt.generic.general_methods import pyaedt_function_handler
from pyaedt.generic.general_methods import settings
from pyaedt.modeler.cad.Modeler import BaseCoordinateSystem
from pyaedt.modeler.cad.Modeler import CoordinateSystem
from pyaedt.modeler.cad.Modeler import FaceCoordinateSystem
from pyaedt.modeler.cad.Modeler import Lists
from pyaedt.modeler.cad.Modeler import Modeler
from pyaedt.modeler.cad.Modeler import ObjectCoordinateSystem
from pyaedt.modeler.cad.components_3d import UserDefinedComponent
from pyaedt.modeler.cad.elements3d import EdgePrimitive
from pyaedt.modeler.cad.elements3d import FacePrimitive
from pyaedt.modeler.cad.elements3d import Plane
from pyaedt.modeler.cad.elements3d import Point
from pyaedt.modeler.cad.elements3d import VertexPrimitive
from pyaedt.modeler.cad.object3d import Object3d
from pyaedt.modeler.cad.polylines import Polyline
from pyaedt.modeler.cad.polylines import PolylineSegment
from pyaedt.modeler.geometry_operators import GeometryOperators
from pyaedt.modules.MaterialLib import Material
default_materials = {
"Icepak": "air",
"HFSS": "vacuum",
"Maxwell 3D": "vacuum",
"Maxwell 2D": "vacuum",
"2D Extractor": "copper",
"Q3D Extractor": "copper",
"HFSS 3D Layout": "copper",
"Mechanical": "copper",
}
aedt_wait_time = 0.1
class Objects(dict):
"""AEDT object dictionary."""
def _parse_objs(self):
if self.__refreshed is False and dict.__len__(self) != len(self.__parent.object_names):
self.__refreshed = True
if self.__obj_type == "o":
self.__parent.logger.info("Parsing design objects. This operation can take time")
self.__parent.logger.reset_timer()
self.__parent._refresh_all_ids_from_aedt_file()
self.__parent.add_new_solids()
self.__parent.cleanup_solids()
self.__parent.logger.info_timer("3D Modeler objects parsed.")
elif self.__obj_type == "p":
self.__parent.logger.info("Parsing design points. This operation can take time")
self.__parent.logger.reset_timer()
self.__parent.add_new_points()
self.__parent.cleanup_points()
self.__parent.logger.info_timer("3D Modeler objects parsed.")
elif self.__obj_type == "u":
self.__parent.add_new_user_defined_component()
def __len__(self):
if self.__refreshed:
return dict.__len__(self)
elif self.__obj_type == "o":
return len(self.__parent.object_names)
elif self.__obj_type == "p":
return len(self.__parent.point_names)
else:
return len(self.__parent.user_defined_component_names)
def __contains__(self, item):
if self.__refreshed:
return True if (item in dict.keys(self) or item in self.__obj_names) else False
elif isinstance(item, str):
if self.__obj_type == "o":
return True if item in self.__parent.object_names else False
elif self.__obj_type == "p":
return True if item in self.__parent.point_names else False
else:
return True if item in self.__parent.user_defined_component_names else False
self._parse_objs()
return True if (item in dict.keys(self) or item in self.__obj_names) else False
def keys(self):
self._parse_objs()
return dict.keys(self)
def values(self):
self._parse_objs()
return dict.values(self)
def items(self):
self._parse_objs()
return dict.items(self)
def __iter__(self):
self._parse_objs()
return dict.__iter__(self)
def __setitem__(self, key, value):
dict.__setitem__(self, key, value)
self.__obj_names[value.name] = value
if self.__obj_type == "o":
self.__parent._object_names_to_ids[value.name] = key
@pyaedt_function_handler()
def __getitem__(self, item):
if item in dict.keys(self):
return dict.__getitem__(self, item)
elif item in self.__obj_names:
return self.__obj_names[item]
if self.__obj_type == "o":
if isinstance(item, int):
try:
id = item
name = self.__parent.oeditor.GetObjectNameByID(id)
o = self.__parent._create_object(name, id)
self.__setitem__(id, o)
return o
except:
raise KeyError(item)
elif isinstance(item, str):
try:
name = item
id = self.__parent.oeditor.GetObjectIDByName(name)
o = self.__parent._create_object(name, id)
self.__setitem__(id, o)
return o
except:
raise KeyError(item)
elif isinstance(item, (Object3d, Polyline)):
self.__setitem__(item.id, item)
return item
else:
raise TypeError(item)
self._parse_objs()
if item in dict.keys(self):
return dict.__getitem__(self, item)
elif item in self.__obj_names:
return self.__obj_names[item]
raise KeyError(item)
def __init__(self, parent, obj_type="o", props=None):
dict.__init__(self)
self.__obj_names = {}
self.__parent = parent
self.__obj_type = obj_type
if props:
for key, value in props.items():
dict.__setitem__(self, key, value)
self.__obj_names[value.name] = value
if self.__obj_type == "o":
self.__parent._object_names_to_ids[value.name] = key
self.__refreshed = True
else:
self.__refreshed = False
class GeometryModeler(Modeler):
"""Manages the main AEDT Modeler functionalities for geometry-based designs.
Parameters
----------
app :
Inherited parent object.
is3d : bool, optional
Whether the model is 3D. The default is ``True``.
"""
@pyaedt_function_handler()
def __getitem__(self, partId):
"""Get the object ``Object3D`` for a given object ID or object name.
Parameters
----------
partId : int or str
Object ID or object name from the 3D modeler.
Returns
-------
:class:`pyaedt.modeler.cad.object3d.Object3d`
Returns ``None`` if the part ID or the object name is not found.
"""
if isinstance(partId, (Object3d, UserDefinedComponent, Point)):
return partId
try:
return self.objects[partId]
except:
if partId in self.user_defined_components.keys():
return self.user_defined_components[partId]
self.logger.error("Object '{}' not found.".format(partId))
return None
def __init__(self, app, is3d=True):
self._app = app
self._model_data = {}
Modeler.__init__(self, app)
self._coordinate_systems = []
self._user_lists = []
self._planes = []
self._is3d = is3d
self._solids = []
self._sheets = []
self._lines = []
self._points = []
self._unclassified = []
self._all_object_names = []
self._object_names_to_ids = {}
self.objects = Objects(self, "o")
self.user_defined_components = Objects(self, "u")
self.points = Objects(self, "p")
self.refresh()
class Position:
"""Position.
Parameters
----------
args : list or int
Position of the item as either a list of the ``[x, y, z]`` coordinates
or three separate values. If no or insufficient arguments
are specified, ``0`` is applied.
"""
@pyaedt_function_handler()
def __getitem__(self, item):
if item == 0:
return self.X
elif item == 1:
return self.Y
elif item == 2:
return self.Z
else:
raise IndexError
@pyaedt_function_handler()
def __setitem__(self, item, value):
if item == 0:
self.X = value
elif item == 1:
self.Y = value
elif item == 2:
self.Z = value
def __len__(self):
return 3
def __init__(self, *args):
if len(args) == 1 and type(args[0]) is list:
try:
self.X = args[0][0]
except:
self.X = 0
try:
self.Y = args[0][1]
except:
self.Y = 0
try:
self.Z = args[0][2]
except:
self.Z = 0
else:
try:
self.X = args[0]
except:
self.X = 0
try:
self.Y = args[1]
except:
self.Y = 0
try:
self.Z = args[2]
except:
self.Z = 0
class SweepOptions(object):
"""Manages sweep options.
Parameters
----------
draftType : str, optional
Type of the draft. Options are ``"Round"``, ``"Natural"``,
and ``"Extended"``. The default is ``"Round"``.
draftAngle : str, optional
Draft angle with units. The default is ``"0deg"``.
twistAngle : str, optional
Twist angle with units. The default is ``"0deg"``.
"""
@pyaedt_function_handler()
def __init__(self, draftType="Round", draftAngle="0deg", twistAngle="0deg"):
self.DraftType = draftType
self.DraftAngle = draftAngle
self.TwistAngle = twistAngle
@property
def _design_properties(self):
return self._app.design_properties
@property
def _odefinition_manager(self):
return self._app.odefinition_manager
@property
def _omaterial_manager(self):
return self._app.omaterial_manager
@property
def coordinate_systems(self):
"""Coordinate systems."""
if settings.aedt_version > "2022.2":
cs_names = [i for i in self.oeditor.GetChildNames("CoordinateSystems") if i != "Global"]
for cs_name in cs_names:
props = {}
local_names = [i.name for i in self._coordinate_systems]
if cs_name not in local_names:
if self.oeditor.GetChildObject(cs_name).GetPropValue("Type") == "Relative":
self._coordinate_systems.append(CoordinateSystem(self, props, cs_name))
elif self.oeditor.GetChildObject(cs_name).GetPropValue("Type") == "Face":
self._coordinate_systems.append(FaceCoordinateSystem(self, props, cs_name))
elif self.oeditor.GetChildObject(cs_name).GetPropValue("Type") == "Object":
self._coordinate_systems.append(ObjectCoordinateSystem(self, props, cs_name))
return self._coordinate_systems
if not self._coordinate_systems:
self._coordinate_systems = self._get_coordinates_data()
return self._coordinate_systems
@property
def user_lists(self):
"""User lists."""
if not self._user_lists:
self._user_lists = self._get_lists_data()
return self._user_lists
@property
def planes(self):
"""Planes."""
if not self._planes:
self._planes = self._get_planes_data()
return self._planes
@property
def oeditor(self):
"""AEDT ``oEditor`` module.
References
----------
>>> oEditor = oDesign.SetActiveEditor("3D Modeler")"""
return self._app.oeditor
@property
def materials(self):
"""Material library used in the project.
Returns
-------
:class:`pyaedt.modules.MaterialLib.Materials`
"""
return self._app.materials
@property
def model_units(self):
"""Model units as a string. For example, ``"mm"``.
References
----------
>>> oEditor.GetModelUnits
>>> oEditor.SetModelUnits
"""
return self.oeditor.GetModelUnits()
@model_units.setter
def model_units(self, units):
assert units in AEDT_UNITS["Length"], "Invalid units string {0}.".format(units)
self.oeditor.SetModelUnits(["NAME:Units Parameter", "Units:=", units, "Rescale:=", False])
@property
def selections(self):
"""Selections.
References
----------
>>> oEditor.GetSelections
"""
return self.oeditor.GetSelections()
@property
def obounding_box(self):
"""Bounding box.
References
----------
>>> oEditor.GetModelBoundingBox
"""
return self.oeditor.GetModelBoundingBox()
@property
def dimension(self):
"""Dimensions.
Returns
-------
str
Dimensionality, which is either ``"2D"`` or ``"3D"``.
References
----------
>>> oDesign.Is2D
"""
try:
if self._odesign.Is2D():
return "2D"
else:
return "3D"
except:
if self.design_type == "2D Extractor":
return "2D"
else:
return "3D"
@property
def design_type(self):
"""Design type.
References
----------
>>> oDesign.GetDesignType
"""
return self._app.design_type
@property
def geometry_mode(self):
"""Geometry mode.
References
----------
>>> oDesign.GetGeometryMode"""
return self._odesign.GetGeometryMode()
@property
def solid_bodies(self):
"""List of object names.
.. note::
Non-model objects are also returned.
Returns
-------
list os str
List of object names with the object name as the key.
References
----------
>>> oEditor.GetObjectsInGroup
"""
if self.dimension == "3D":
objects = self.oeditor.GetObjectsInGroup("Solids")
else:
objects = self.oeditor.GetObjectsInGroup("Sheets")
return list(objects)
@property
def _modeler(self):
return self
@property
def solid_objects(self):
"""List of all solid objects.
Returns
-------
list of :class:`pyaedt.modeler.cad.object3d.Object3d`
3D object.
"""
# self._refresh_solids()
return [self[name] for name in self.solid_names if self[name]]
@property
def sheet_objects(self):
"""List of all sheet objects.
Returns
-------
list of :class:`pyaedt.modeler.cad.object3d.Object3d`
3D object.
"""
self._refresh_sheets()
return [v for k, v in self.objects_by_name.items() if k in self._sheets]
@property
def line_objects(self):
"""List of all line objects.
Returns
-------
list of :class:`pyaedt.modeler.cad.object3d.Object3d`
3D object.
"""
self._refresh_lines()
return [v for k, v in self.objects_by_name.items() if k in self._lines]
@property
def point_objects(self):
"""List of points objects.
Returns
-------
list of :class:`pyaedt.modeler.cad.object3d.Object3d`
3D object.
"""
self._refresh_points()
return [v for k, v in self.points.items() if k in self._points]
@property
def unclassified_objects(self):
"""List of all unclassified objects.
Returns
-------
list of :class:`pyaedt.modeler.cad.object3d.Object3d`
3D object.
"""
self._refresh_unclassified()
return [v for k, v in self.objects_by_name.items() if k in self._unclassified]
@property
def object_list(self):
"""List of all objects.
Returns
-------
list of :class:`pyaedt.modeler.cad.object3d.Object3d`
3D object.
"""
self._refresh_object_types()
return [v for name, v in self.objects_by_name.items() if name is not None and name not in self.point_names]
@property
def solid_names(self):
"""List of the names of all solid objects.
Returns
-------
List
"""
self._refresh_solids()
return self._solids
@property
def sheet_names(self):
"""List of the names of all sheet objects.
Returns
-------
str
"""
self._refresh_sheets()
return self._sheets
@property
def line_names(self):
"""List of the names of all line objects.
Returns
-------
str
"""
self._refresh_lines()
return self._lines
@property
def unclassified_names(self):
"""List of the names of all unclassified objects.
Returns
-------
str
"""
self._refresh_unclassified()
return self._unclassified
@property
def object_names(self):
"""List of the names of all objects.
Returns
-------
str
"""
self._refresh_object_types()
return [i for i in self._all_object_names if i not in self._unclassified and i not in self._points]
@property
def point_names(self):
"""List of the names of all points.
Returns
-------
str
"""
self._refresh_points()
return self._points
@property
def user_defined_component_names(self):
"""List of the names of all 3D component objects.
References
----------
>>> oEditor.Get3DComponentDefinitionNames
>>> oEditor.Get3DComponentInstanceNames
"""
obs3d = []
try:
comps3d = self.oeditor.Get3DComponentDefinitionNames()
for comp3d in comps3d:
obs3d += list(self.oeditor.Get3DComponentInstanceNames(comp3d))
udm = []
if "UserDefinedModels" in self.oeditor.GetChildTypes():
try:
udm = list(self.oeditor.GetChildNames("UserDefinedModels"))
except: # pragma: no cover
udm = []
obs3d = list(set(udm + obs3d))
new_obs3d = copy.deepcopy(obs3d)
if self.user_defined_components.keys():
existing_components = list(self.user_defined_components.keys())
new_obs3d = [i for i in obs3d if i]
for _, value in enumerate(existing_components):
if value not in new_obs3d:
new_obs3d.append(value)
except Exception:
new_obs3d = []
return new_obs3d
@property
def layout_component_names(self):
"""List of the names of all Layout component objects.
Returns
-------
list
Layout component names.
"""
lc_names = []
if self.user_defined_components.keys():
for name, value in self.user_defined_components.items():
if value.layout_component:
lc_names.append(name)
return lc_names
@property
def _oproject(self):
"""Project."""
return self._app.oproject
@property
def _odesign(self):
"""Design."""
return self._app._odesign
@property
def _materials(self):
"""Material Manager that is used to manage materials in the project.
Returns
-------
:class:`pyaedt.modules.MaterialLib.Materials`
Material Manager that is used to manage materials in the project.
"""
return self._app.materials
@property
def defaultmaterial(self):
"""Default material."""
return default_materials[self._app._design_type]
@property
def logger(self):
"""Logger."""
return self._app.logger
@property
def version(self):
"""Version."""
return self._app._aedt_version
@property
def model_objects(self):
"""List of the names of all model objects."""
return self._get_model_objects(model=True)
@property
def non_model_objects(self):
"""List of objects of all non-model objects."""
return list(self.oeditor.GetObjectsInGroup("Non Model"))
@property
def model_consistency_report(self):
"""Summary of detected inconsistencies between the AEDT modeler and PyAEDT structures.
Returns
-------
dict
"""
obj_names = self.object_names
missing = []
for name in obj_names:
if name not in self._object_names_to_ids:
missing.append(name)
non_existent = []
for name in self._object_names_to_ids:
if name not in obj_names and name not in self.unclassified_names:
non_existent.append(name)
report = {"Missing Objects": missing, "Non-Existent Objects": non_existent}
return report
@property
def objects_by_name(self):
"""Object dictionary organized by name.
Returns
-------
dict
"""
obj_dict = {}
for _, v in self.objects.items():
obj_dict[v._m_name] = v
return obj_dict
@pyaedt_function_handler()
def refresh(self):
"""Refresh this object."""
self._solids = []
self._sheets = []
self._lines = []
self._points = []
self._unclassified = []
self._all_object_names = []
self._object_names_to_ids = {}
self.objects = Objects(self, "o")
self.user_defined_components = Objects(self, "u")
self._refresh_object_types()
if not settings.objects_lazy_load:
self._refresh_all_ids_from_aedt_file()
self.refresh_all_ids()
@pyaedt_function_handler()
def _get_commands(self, name):
try:
return self.oeditor.GetChildObject(name).GetChildNames()
except:
return []
@pyaedt_function_handler()
def _create_user_defined_component(self, name):
if name not in list(self.user_defined_components.keys()):
native_component_properties = self._get_native_component_properties(name)
if native_component_properties:
component_type = native_component_properties["NativeComponentDefinitionProvider"]["Type"]
o = UserDefinedComponent(self, name, native_component_properties, component_type)
else:
o = UserDefinedComponent(self, name)
self.user_defined_components[name] = o
else:
o = self.user_defined_components[name]
return o
@pyaedt_function_handler()
def _create_point(self, name):
point = Point(self, name)
self.refresh_all_ids()
return point
@pyaedt_function_handler()
def _refresh_all_ids_from_aedt_file(self):
dp = copy.deepcopy(self._app.design_properties)
if not dp or "ModelSetup" not in dp:
return False
try:
groups = dp["ModelSetup"]["GeometryCore"]["GeometryOperations"]["Groups"]["Group"]
except KeyError:
groups = []
if not isinstance(groups, list):
groups = [groups]
try:
dp["ModelSetup"]["GeometryCore"]["GeometryOperations"]["ToplevelParts"]["GeometryPart"]
except KeyError:
return 0
for el in dp["ModelSetup"]["GeometryCore"]["GeometryOperations"]["ToplevelParts"]["GeometryPart"]:
if isinstance(el, (OrderedDict, dict)):
attribs = el["Attributes"]
operations = el.get("Operations", None)
else:
attribs = dp["ModelSetup"]["GeometryCore"]["GeometryOperations"]["ToplevelParts"]["GeometryPart"][
"Attributes"
]
operations = dp["ModelSetup"]["GeometryCore"]["GeometryOperations"]["ToplevelParts"]["GeometryPart"][
"Operations"
]
if attribs["Name"] in self._all_object_names:
pid = 0
if operations and isinstance(operations.get("Operation", None), (OrderedDict, dict)):
try:
pid = operations["Operation"]["ParentPartID"]
except: # pragma: no cover
pass
elif operations and isinstance(operations.get("Operation", None), list):
try:
pid = operations["Operation"][0]["ParentPartID"]
except:
pass
is_polyline = False
if operations and "PolylineParameters" in operations.get("Operation", {}):
is_polyline = True
o = self._create_object(name=attribs["Name"], pid=pid, use_cached=True, is_polyline=is_polyline)
o._part_coordinate_system = attribs["PartCoordinateSystem"]
if "NonModel" in attribs["Flags"]:
o._model = False
else:
o._model = True
if "Wireframe" in attribs["Flags"]:
o._wireframe = True
else:
o._wireframe = False
groupname = ""
for group in groups:
if attribs["GroupId"] == group["GroupID"]:
groupname = group["Attributes"]["Name"]
o._m_groupName = groupname
try:
o._color = tuple(int(x) for x in attribs["Color"][1:-1].split(" "))
except:
o._color = None
o._surface_material = attribs.get("SurfaceMaterialValue", None)
if o._surface_material:
o._surface_material = o._surface_material[1:-1].lower()
if "MaterialValue" in attribs:
o._material_name = attribs["MaterialValue"][1:-1].lower()
o._is_updated = True
return len(self.objects)
@pyaedt_function_handler()
def cleanup_objects(self):
"""Clean up objects that no longer exist in the modeler because
they were removed by previous operations.
This method also updates object IDs that may have changed via
a modeler operation such as :func:`pyaedt.modeler.Model3D.Modeler3D.unite`
or :func:`pyaedt.modeler.Model2D.Modeler2D.unite`.
Returns
-------
dict
Dictionary of updated object IDs.
"""
self.cleanup_solids()
self.cleanup_points()
@pyaedt_function_handler()
def cleanup_solids(self):
"""Clean up solids that no longer exist in the modeler because
they were removed by previous operations.
This method also updates object IDs that may have changed via
a modeler operation such as :func:`pyaedt.modeler.Model3D.Modeler3D.unite`
or :func:`pyaedt.modeler.Model2D.Modeler2D.unite`.
Returns
-------
dict
Dictionary of updated object IDs.
"""
new_object_dict = {}
new_object_id_dict = {}
all_objects = self.object_names
all_unclassified = self.unclassified_names
all_objs = all_objects + all_unclassified
if len(all_objs) != len(self._object_names_to_ids):
for old_id, obj in self.objects.items():
if obj.name in all_objs:
# Check if ID can change in boolean operations
# updated_id = obj.id # By calling the object property we get the new id
new_object_id_dict[obj.name] = old_id
new_object_dict[old_id] = obj
self._object_names_to_ids = {}
self.objects = Objects(self, "o", new_object_dict)
@pyaedt_function_handler()
def cleanup_points(self):
"""Clean up points that no longer exist in the modeler because
they were removed by previous operations.
This method also updates object IDs that may have changed via
a modeler operation such as :func:`pyaedt.modeler.Model3D.Modeler3D.unite`
or :func:`pyaedt.modeler.Model2D.Modeler2D.unite`.
Returns
-------
dict
Dictionary of updated object IDs.
"""
new_points_dict = {}
for old_id, obj in self.points.items():
if obj.name in self._points:
new_points_dict[obj.name] = obj
self.points = Objects(self, "p", new_points_dict)
@pyaedt_function_handler()
def find_new_objects(self):
"""Find any new objects in the modeler that were created
by previous operations.
Returns
-------
dict
Dictionary of new objects.
"""
new_objects = []
for obj_name in self.object_names:
if obj_name not in self._object_names_to_ids:
new_objects.append(obj_name)
return new_objects
@pyaedt_function_handler()
def add_new_objects(self):
"""Add objects that have been created in the modeler by
previous operations.
Returns
-------
list
List of added objects.
"""
added_objects = []
objs_ids = {}
added_objects = self.add_new_solids()
added_objects += self.add_new_points()
return added_objects
@pyaedt_function_handler()
def add_new_solids(self):
"""Add objects that have been created in the modeler by
previous operations.