diff --git a/src/ansys/aedt/core/modeler/cad/polylines.py b/src/ansys/aedt/core/modeler/cad/polylines.py index 2ad98cca92e..27cfdc55c3c 100644 --- a/src/ansys/aedt/core/modeler/cad/polylines.py +++ b/src/ansys/aedt/core/modeler/cad/polylines.py @@ -342,17 +342,17 @@ def __init__( self._is_closed = close_surface self._is_covered = cover_surface - varg1 = self._point_segment_string_array() + arg_1 = self._point_segment_string_array() if non_model: flag = "NonModel#" else: flag = "" - varg2 = self._primitives._default_object_attributes(name=name, material=matname, flags=flag) + arg_2 = self._primitives._default_object_attributes(name=name, material=matname, flags=flag) if self._primitives.design_type in ["Maxwell 2D", "2D Extractor"]: - solve_inside_idx = varg2.index("SolveInside:=") + solve_inside_idx = arg_2.index("SolveInside:=") self._solve_inside = False - varg2[solve_inside_idx + 1] = self._solve_inside - new_object_name = self._oeditor.CreatePolyline(varg1, varg2) + arg_2[solve_inside_idx + 1] = self._solve_inside + new_object_name = self._oeditor.CreatePolyline(arg_1, arg_2) Object3d.__init__(self, primitives, name=new_object_name) self._primitives._create_object(self.name, is_polyline=True) @@ -573,11 +573,13 @@ def _point_segment_string_array(self): segment_types = self.segment_types # Add a closing point if needed - varg1 = ["NAME:PolylineParameters"] - varg1.append("IsPolylineCovered:=") - varg1.append(self._is_covered) - varg1.append("IsPolylineClosed:=") - varg1.append(self._is_closed) + arg_1 = [ + "NAME:PolylineParameters", + "IsPolylineCovered:=", + self._is_covered, + "IsPolylineClosed:=", + self._is_closed, + ] # PointsArray points_str = ["NAME:PolylinePoints"] @@ -633,13 +635,13 @@ def _point_segment_string_array(self): else: break - varg1.append(points_str) - varg1.append(segment_str) + arg_1.append(points_str) + arg_1.append(segment_str) # Poly Line Cross Section - varg1.append(self._xsection) + arg_1.append(self._xsection) - return varg1 + return arg_1 @pyaedt_function_handler() def _evaluate_arc_angle_extra_points(self, segment, start_point): @@ -778,15 +780,16 @@ def clone(self): >>> P2 = P1.clone() """ - vArg1 = ["NAME:Selections", "Selections:=", self.name] - self._primitives.oeditor.Copy(vArg1) + arg_1 = ["NAME:Selections", "Selections:=", self.name] + self._primitives.oeditor.Copy(arg_1) self._primitives.oeditor.Paste() return self._add_new_polyline() @pyaedt_function_handler() def _add_new_polyline(self): new_objects = self._primitives.find_new_objects() - assert len(new_objects) == 1 + if len(new_objects) != 1: + raise RuntimeError("Cannot create a new polyline object when multiple new objects exist.") new_name = new_objects[0] new_polyline = Polyline(self._primitives, src_object=self, name=new_name) new_polyline._id = None @@ -1008,8 +1011,8 @@ def set_crosssection_properties( section_bend = "Corner" # Ensure number-of segments is valid - if num_seg: - assert num_seg > 2, "Number of segments for a cross-section must be 0 or greater than 2." + if num_seg and num_seg < 3: + raise ValueError("Number of segments for a cross-section must be 0 or greater than 2.") model_units = self._primitives.model_units @@ -1220,46 +1223,47 @@ def insert_segment(self, points, segment=None): points = [end_point, self.points[1]] break - assert p_insert_position is not None, "Point for the insert is not found." - assert insert_points is not None, "Point for the insert is not found." + if p_insert_position is None or insert_points is None: + raise RuntimeError("Point for the insert is not found.") if i is None: raise ValueError("The polyline contains no points. It is impossible to insert a segment.") segment_index = self._get_segment_id_from_point_n(i, at_start=at_start) - assert isinstance(segment_index, int), "Segment for the insert is not found." + if not isinstance(segment_index, int): + raise ValueError("Segment for the insert is not found.") if at_start: s_insert_position = segment_index else: s_insert_position = segment_index + 1 - - type = segment.type - - varg1 = ["NAME:Insert Polyline Segment"] - varg1.append("Selections:=") - varg1.append(self._m_name + ":CreatePolyline:1") - varg1.append("Segment Indices:=") - varg1.append([segment_index]) - varg1.append("At Start:=") - varg1.append(at_start) - varg1.append("SegmentType:=") - varg1.append(type) + segment_type = segment.type + + arg_1 = [ + "NAME:Insert Polyline Segment", + "Selections:=", + self._m_name + ":CreatePolyline:1", + "Segment Indices:=", + [segment_index], + "At Start:=", + at_start, + "SegmentType:=", + segment_type, + ] # Points and segment data - varg2 = ["NAME:PolylinePoints"] - - if segment.type == "Line" or segment.type == "Spline" or segment.type == "Arc": + arg_2 = ["NAME:PolylinePoints"] + if segment.type in ("Line", "Spline", "Arc"): for pt in points[0:num_points]: - varg2.append(self._pl_point(pt)) - varg1.append(varg2) + arg_2.append(self._pl_point(pt)) + arg_1.append(arg_2) elif segment.type == "AngularArc": seg_str = self._segment_array(segment, start_point=start_point) - varg2.append(self._pl_point(start_point)) - varg2.append(self._pl_point(segment.extra_points[0])) - varg2.append(self._pl_point(segment.extra_points[1])) - varg1.append(varg2) - varg1 += seg_str[9:] - self._primitives.oeditor.InsertPolylineSegment(varg1) + arg_2.append(self._pl_point(start_point)) + arg_2.append(self._pl_point(segment.extra_points[0])) + arg_2.append(self._pl_point(segment.extra_points[1])) + arg_1.append(arg_2) + arg_1 += seg_str[9:] + self._primitives.oeditor.InsertPolylineSegment(arg_1) # check if the polyline has been modified correctly if self._check_polyline_health() is False: @@ -1279,6 +1283,7 @@ def _check_polyline_health(self): # Undo operation self._primitives._app.odesign.Undo() self._object_type = None - assert self.object_type != "Unclassified", "Undo operation failed." + if self.object_type == "Unclassified": + raise RuntimeError("Undo operation failed.") return False return True diff --git a/src/ansys/aedt/core/modeler/cad/primitives.py b/src/ansys/aedt/core/modeler/cad/primitives.py index 7ccb9f8280f..aa1f32daaec 100644 --- a/src/ansys/aedt/core/modeler/cad/primitives.py +++ b/src/ansys/aedt/core/modeler/cad/primitives.py @@ -443,7 +443,8 @@ def model_units(self): @model_units.setter def model_units(self, units): - assert units in AEDT_UNITS["Length"], f"Invalid units string {units}." + if units not in AEDT_UNITS["Length"]: + raise RuntimeError(f"Invalid units string {units}.") self.oeditor.SetModelUnits(["NAME:Units Parameter", "Units:=", units, "Rescale:=", self.rescale_model]) self._model_units = units @@ -1389,7 +1390,9 @@ def _find_perpendicular_points(self, face): vertices = [] for vertex in list(self.oeditor.GetVertexIDsFromFace(face)): vertices.append([float(i) for i in list(self.oeditor.GetVertexPosition(vertex))]) - assert len(vertices) > 2, "Automatic A-B Assignment can be done only on face with more than 2 vertices." + if len(vertices) < 3: + raise RuntimeError("Automatic A-B assignment requires more than 2 vertices.") + origin = vertices[0] a_end = [] b_end = [] @@ -2383,7 +2386,7 @@ def _get_faceid_on_axis(self, objname, axisdir): face = f center = c except Exception: - pass + self.logger.debug(f"Cannot retrieve face center from face ID {f}") return face @pyaedt_function_handler() @@ -2837,21 +2840,29 @@ def mirror(self, assignment, origin, vector, duplicate=False, is_3d_comp=False, >>> oEditor.DuplicateMirror """ selections = self.convert_to_selections(assignment) - Xpos, Ypos, Zpos = self._pos_with_arg(origin) - Xnorm, Ynorm, Znorm = self._pos_with_arg(vector) + x_pos, y_pos, z_pos = self._pos_with_arg(origin) + x_norm, y_norm, z_norm = self._pos_with_arg(vector) if duplicate: - vArg1 = ["NAME:Selections", "Selections:=", selections, "NewPartsModelFlag:=", "Model"] - vArg2 = ["NAME:DuplicateToMirrorParameters"] - vArg2.append("DuplicateMirrorBaseX:="), vArg2.append(Xpos) - vArg2.append("DuplicateMirrorBaseY:="), vArg2.append(Ypos) - vArg2.append("DuplicateMirrorBaseZ:="), vArg2.append(Zpos) - vArg2.append("DuplicateMirrorNormalX:="), vArg2.append(Xnorm) - vArg2.append("DuplicateMirrorNormalY:="), vArg2.append(Ynorm) - vArg2.append("DuplicateMirrorNormalZ:="), vArg2.append(Znorm) - vArg3 = ["NAME:Options", "DuplicateAssignments:=", duplicate_assignment] + arg_1 = ["NAME:Selections", "Selections:=", selections, "NewPartsModelFlag:=", "Model"] + arg_2 = [ + "NAME:DuplicateToMirrorParameters", + "DuplicateMirrorBaseX:=", + x_pos, + "DuplicateMirrorBaseY:=", + y_pos, + "DuplicateMirrorBaseZ:=", + z_pos, + "DuplicateMirrorNormalX:=", + x_norm, + "DuplicateMirrorNormalY:=", + y_norm, + "DuplicateMirrorNormalZ:=", + z_norm, + ] + arg_3 = ["NAME:Options", "DuplicateAssignments:=", duplicate_assignment] if is_3d_comp: orig_3d = [i for i in self.user_defined_component_names] - added_objs = self.oeditor.DuplicateMirror(vArg1, vArg2, vArg3) + added_objs = self.oeditor.DuplicateMirror(arg_1, arg_2, arg_3) self.add_new_objects() if is_3d_comp: added_3d_comps = [i for i in self.user_defined_component_names if i not in orig_3d] @@ -2860,16 +2871,23 @@ def mirror(self, assignment, origin, vector, duplicate=False, is_3d_comp=False, return added_3d_comps return added_objs else: - vArg1 = ["NAME:Selections", "Selections:=", selections, "NewPartsModelFlag:=", "Model"] - vArg2 = ["NAME:MirrorParameters"] - vArg2.append("MirrorBaseX:="), vArg2.append(Xpos) - vArg2.append("MirrorBaseY:="), vArg2.append(Ypos) - vArg2.append("MirrorBaseZ:="), vArg2.append(Zpos) - vArg2.append("MirrorNormalX:="), vArg2.append(Xnorm) - vArg2.append("MirrorNormalY:="), vArg2.append(Ynorm) - vArg2.append("MirrorNormalZ:="), vArg2.append(Znorm) - - self.oeditor.Mirror(vArg1, vArg2) + arg_1 = ["NAME:Selections", "Selections:=", selections, "NewPartsModelFlag:=", "Model"] + arg_2 = [ + "NAME:MirrorParameters", + "MirrorBaseX:=", + x_pos, + "MirrorBaseY:=", + y_pos, + "MirrorBaseZ:=", + z_pos, + "MirrorNormalX:=", + x_norm, + "MirrorNormalY:=", + y_norm, + "MirrorNormalZ:=", + z_norm, + ] + self.oeditor.Mirror(arg_1, arg_2) return True @pyaedt_function_handler(objid="assignment") @@ -2893,17 +2911,22 @@ def move(self, assignment, vector): ---------- >>> oEditor.Move """ - Xvec, Yvec, Zvec = self._pos_with_arg(vector) - szSelections = self.convert_to_selections(assignment) + x_vec, y_vec, z_vec = self._pos_with_arg(vector) + selections = self.convert_to_selections(assignment) - vArg1 = ["NAME:Selections", "Selections:=", szSelections, "NewPartsModelFlag:=", "Model"] - vArg2 = ["NAME:TranslateParameters"] - vArg2.append("TranslateVectorX:="), vArg2.append(Xvec) - vArg2.append("TranslateVectorY:="), vArg2.append(Yvec) - vArg2.append("TranslateVectorZ:="), vArg2.append(Zvec) + arg_1 = ["NAME:Selections", "Selections:=", selections, "NewPartsModelFlag:=", "Model"] + arg_2 = [ + "NAME:TranslateParameters", + "TranslateVectorX:=", + x_vec, + "TranslateVectorY:=", + y_vec, + "TranslateVectorZ:=", + z_vec, + ] if self.oeditor is not None: - self.oeditor.Move(vArg1, vArg2) + self.oeditor.Move(arg_1, arg_2) return True @pyaedt_function_handler(objid="assignment", cs_axis="axis", nclones="clones") @@ -3018,18 +3041,25 @@ def duplicate_along_line( >>> oEditor.DuplicateAlongLine """ selections = self.convert_to_selections(assignment) - Xpos, Ypos, Zpos = self._pos_with_arg(vector) + x_pos, y_pos, z_pos = self._pos_with_arg(vector) - vArg1 = ["NAME:Selections", "Selections:=", selections, "NewPartsModelFlag:=", "Model"] - vArg2 = ["NAME:DuplicateToAlongLineParameters"] - vArg2.append("CreateNewObjects:="), vArg2.append(not attach) - vArg2.append("XComponent:="), vArg2.append(Xpos) - vArg2.append("YComponent:="), vArg2.append(Ypos) - vArg2.append("ZComponent:="), vArg2.append(Zpos) - vArg2.append("Numclones:="), vArg2.append(str(clones)) - vArg3 = ["NAME:Options", "DuplicateAssignments:=", duplicate_assignment] + arg_1 = ["NAME:Selections", "Selections:=", selections, "NewPartsModelFlag:=", "Model"] + arg_2 = [ + "NAME:DuplicateToAlongLineParameters", + "CreateNewObjects:=", + not attach, + "XComponent:=", + x_pos, + "YComponent:=", + y_pos, + "ZComponent:=", + z_pos, + "Numclones:=", + str(clones), + ] + arg_3 = ["NAME:Options", "DuplicateAssignments:=", duplicate_assignment] self.add_new_objects() - self.oeditor.DuplicateAlongLine(vArg1, vArg2, vArg3) + self.oeditor.DuplicateAlongLine(arg_1, arg_2, arg_3) if is_3d_comp: return self._duplicate_added_components_tuple() if attach: @@ -3636,14 +3666,13 @@ def unite(self, assignment, purge=False, keep_originals=False): objs_groups = [] while remaining > 1: objs = assignment[:slice] - szSelections = self.convert_to_selections(objs) - vArg1 = ["NAME:Selections", "Selections:=", szSelections] - vArg2 = ["NAME:UniteParameters", "KeepOriginals:=", keep_originals] + selections = self.convert_to_selections(objs) + arg_1 = ["NAME:Selections", "Selections:=", selections] + arg_2 = ["NAME:UniteParameters", "KeepOriginals:=", keep_originals] if settings.aedt_version > "2022.2": - vArg2.append("TurnOnNBodyBoolean:=") - vArg2.append(True) - self.oeditor.Unite(vArg1, vArg2) - if szSelections.split(",")[0] in self.unclassified_names: # pragma: no cover + arg_2 += ["TurnOnNBodyBoolean:=", True] + self.oeditor.Unite(arg_1, arg_2) + if selections.split(",")[0] in self.unclassified_names: # pragma: no cover self.logger.error("Error in uniting objects.") self._odesign.Undo() self.cleanup_objects() @@ -3758,9 +3787,9 @@ def intersect(self, assignment, keep_originals=False, **kwargs): warnings.warn("keeporiginal has been deprecated. use keep_originals.", DeprecationWarning) keep_originals = kwargs["keeporiginal"] unclassified = list(self.oeditor.GetObjectsInGroup("Unclassified")) - szSelections = self.convert_to_selections(assignment) + selections = self.convert_to_selections(assignment) - vArg1 = ["NAME:Selections", "Selections:=", szSelections] + vArg1 = ["NAME:Selections", "Selections:=", selections] vArg2 = ["NAME:IntersectParameters", "KeepOriginals:=", keep_originals] self.oeditor.Intersect(vArg1, vArg2) @@ -3827,9 +3856,9 @@ def connect(self, assignment): """ try: unclassified_before = list(self.unclassified_names) - szSelections = self.convert_to_selections(assignment) - szSelections_list = szSelections.split(",") - vArg1 = ["NAME:Selections", "Selections:=", szSelections] + selections = self.convert_to_selections(assignment) + selections_list = selections.split(",") + vArg1 = ["NAME:Selections", "Selections:=", selections] self.oeditor.Connect(vArg1) if unclassified_before != self.unclassified_names: # pragma: no cover @@ -3844,7 +3873,7 @@ def connect(self, assignment): objects_list_after_connection = [ obj for obj in self.object_list - for sel in set(szSelections_list).intersection(self.object_names) + for sel in set(selections_list).intersection(self.object_names) if obj.name == sel ] return objects_list_after_connection @@ -3942,7 +3971,7 @@ def check_plane(self, assignment, face_location, offset=1): """ - Xvec, Yvec, Zvec = self._pos_with_arg(face_location) + x_vec, y_vec, z_vec = self._pos_with_arg(face_location) if isinstance(assignment, int): assignment = self.objects[assignment].name @@ -3951,13 +3980,19 @@ def check_plane(self, assignment, face_location, offset=1): i = 0 while not found: off1, off2, off3 = self._offset_on_plane(i, offset) - vArg1 = ["NAME:FaceParameters"] - vArg1.append("BodyName:="), vArg1.append(assignment) - vArg1.append("XPosition:="), vArg1.append(Xvec + "+" + self._arg_with_dim(off1)) - vArg1.append("YPosition:="), vArg1.append(Yvec + "+" + self._arg_with_dim(off2)) - vArg1.append("ZPosition:="), vArg1.append(Zvec + "+" + self._arg_with_dim(off3)) + arg_1 = [ + "NAME:FaceParameters", + "BodyName:=", + assignment, + "XPosition:=", + x_vec + "+" + self._arg_with_dim(off1), + "YPosition:=", + y_vec + "+" + self._arg_with_dim(off2), + "ZPosition:=", + z_vec + "+" + self._arg_with_dim(off3), + ] try: - face_id = self.oeditor.GetFaceByPosition(vArg1) + _ = self.oeditor.GetFaceByPosition(arg_1) if i < 4: plane = "XY" elif i < 8: @@ -4551,11 +4586,11 @@ def get_object_name_from_edge_id(self, assignment): ---------- >>> oEditor.GetEdgeIDsFromObject """ - for object in self.solid_names + self.sheet_names + self.line_names: + for obj in self.solid_names + self.sheet_names + self.line_names: try: - oEdgeIDs = self.oeditor.GetEdgeIDsFromObject(object) + oEdgeIDs = self.oeditor.GetEdgeIDsFromObject(obj) if str(assignment) in oEdgeIDs: - return object + return obj except Exception: return False return False @@ -5328,8 +5363,8 @@ def setunassigned_mats(self): ---------- >>> oEditor.SetPropertyValue """ - oObjects = list(self.oeditor.GetObjectsInGroup("Solids")) - for obj in oObjects: + objects = list(self.oeditor.GetObjectsInGroup("Solids")) + for obj in objects: pro = self.oeditor.GetPropertyValue("Geometry3DAttributeTab", obj, "Material") if pro == '""': self.oeditor.SetPropertyValue("Geometry3DAttributeTab", obj, "Model", False) @@ -7894,12 +7929,17 @@ def get_bodynames_from_position(self, position, units=None, include_non_model=Tr if not isinstance(position, (self.Position, list)): # self.logger.error("A list of point has to be provided") return [] - XCenter, YCenter, ZCenter = self._pos_with_arg(position, units) - vArg1 = ["NAME:Parameters"] - vArg1.append("XPosition:="), vArg1.append(XCenter) - vArg1.append("YPosition:="), vArg1.append(YCenter) - vArg1.append("ZPosition:="), vArg1.append(ZCenter) - list_of_bodies = list(self.oeditor.GetBodyNamesByPosition(vArg1)) + x_center, y_center, z_center = self._pos_with_arg(position, units) + arg_1 = [ + "NAME:Parameters", + "XPosition:=", + x_center, + "YPosition:=", + y_center, + "ZPosition:=", + z_center, + ] + list_of_bodies = list(self.oeditor.GetBodyNamesByPosition(arg_1)) if not include_non_model: non_models = [i for i in self.non_model_objects] list_of_bodies = [i for i in list_of_bodies if i not in non_models] @@ -7930,21 +7970,27 @@ def get_edgeid_from_position(self, position, assignment=None, units=None): else: object_list = self.object_names - edgeID = -1 - XCenter, YCenter, ZCenter = self._pos_with_arg(position, units) + edge_id = -1 + x_center, y_center, z_center = self._pos_with_arg(position, units) - vArg1 = ["NAME:EdgeParameters"] - vArg1.append("BodyName:="), vArg1.append("") - vArg1.append("XPosition:="), vArg1.append(XCenter) - vArg1.append("YPosition:="), vArg1.append(YCenter) - vArg1.append("ZPosition:="), vArg1.append(ZCenter) + arg_1 = [ + "NAME:EdgeParameters", + "BodyName:=", + "", + "XPosition:=", + x_center, + "YPosition:=", + y_center, + "ZPosition:=", + z_center, + ] for obj in object_list: - vArg1[2] = obj + arg_1[2] = obj try: - edgeID = int(self.oeditor.GetEdgeByPosition(vArg1)) - return edgeID + edge_id = int(self.oeditor.GetEdgeByPosition(arg_1)) + return edge_id except Exception: - pass + self.logger.debug(f"Cannot retrieve edge id from {obj}") @pyaedt_function_handler(vertexid="vertex", obj_name="assignment") def get_edgeids_from_vertexid(self, vertex, assignment): @@ -7968,14 +8014,14 @@ def get_edgeids_from_vertexid(self, vertex, assignment): >>> oEditor.GetVertexIDsFromEdge """ - edgeID = [] + edge_ids = [] edges = self.get_object_edges(assignment) for edge in edges: vertices = self.get_edge_vertices(edge) if vertex in vertices: - edgeID.append(edge) + edge_ids.append(edge) - return edgeID + return edge_ids @pyaedt_function_handler(obj_name="assignment") def get_faceid_from_position(self, position, assignment=None, units=None): @@ -8007,20 +8053,25 @@ def get_faceid_from_position(self, position, assignment=None, units=None): else: object_list = self.object_names - XCenter, YCenter, ZCenter = self._pos_with_arg(position, units) - vArg1 = ["NAME:FaceParameters"] - vArg1.append("BodyName:="), vArg1.append("") - vArg1.append("XPosition:="), vArg1.append(XCenter) - vArg1.append("YPosition:="), vArg1.append(YCenter) - vArg1.append("ZPosition:="), vArg1.append(ZCenter) + x_center, y_center, z_center = self._pos_with_arg(position, units) + arg_1 = [ + "NAME:FaceParameters", + "BodyName:=", + "", + "XPosition:=", + x_center, + "YPosition:=", + y_center, + "ZPosition:=", + z_center, + ] for obj in object_list: - vArg1[2] = obj + arg_1[2] = obj try: - face_id = self.oeditor.GetFaceByPosition(vArg1) + face_id = self.oeditor.GetFaceByPosition(arg_1) return face_id except Exception: - # Not Found, keep looking - pass + self.logger.debug(f"Cannot retrieve face id from {obj}") @pyaedt_function_handler(sheets="assignment", tol="tolerance") def get_edges_on_bounding_box(self, assignment, return_colinear=True, tolerance=1e-6): @@ -8517,60 +8568,65 @@ def _check_material(self, material, default_material, threshold=100000): else: return default_material, True + # TODO: Checks should be performed to check if all objects values are really reachable @pyaedt_function_handler() - def _refresh_solids(self): + def __refresh_object_type(self, object_type: str): + ALLOWED_TYPES = ["Solids", "Sheets", "Lines", "Unclassified"] + OBJECT_TYPE_TO_ATTRIBUTE = { + "Solids": "_solids", + "Sheets": "_sheets", + "Lines": "_lines", + "Unclassified": "_unclassified", + } + + if object_type not in ALLOWED_TYPES: + raise ValueError(f"Object type {object_type} is not allowed.") + try: - test = self.oeditor.GetObjectsInGroup("Solids") + objects = self.oeditor.GetObjectsInGroup(object_type) except (TypeError, AttributeError): - test = [] - if test is False: - assert False, "Get Solids is failing" - elif test is True or test is None: - self._solids = [] # In IronPython True is returned when no sheets are present + objects = [] + # TODO: To be checked + if objects is False: + raise RuntimeError(f"Get {object_type.lower()} is failing") + # TODO: To be checked (in IronPython True is supposed to be returned when no solids are present) + elif objects is True or objects is None: + setattr( + self, OBJECT_TYPE_TO_ATTRIBUTE[object_type], [] + ) # In IronPython True is returned when no solids are present else: - self._solids = list(test) + setattr(self, OBJECT_TYPE_TO_ATTRIBUTE[object_type], list(objects)) self._all_object_names = self._solids + self._sheets + self._lines + self._points + @pyaedt_function_handler() + def _refresh_solids(self): + self.__refresh_object_type("Solids") + @pyaedt_function_handler() def _refresh_sheets(self): - try: - test = self.oeditor.GetObjectsInGroup("Sheets") - except (TypeError, AttributeError): - test = [] - if test is False: - assert False, "Get Sheets is failing" - elif test is True or test is None: - self._sheets = [] # In IronPython True is returned when no sheets are present - else: - self._sheets = list(test) - self._all_object_names = self._solids + self._sheets + self._lines + self._points + self.__refresh_object_type("Sheets") @pyaedt_function_handler() def _refresh_lines(self): - try: - test = self.oeditor.GetObjectsInGroup("Lines") - except (TypeError, AttributeError): - test = [] - if test is False: - assert False, "Get Lines is failing" - elif test is True or test is None: - self._lines = [] # In IronPython True is returned when no lines are present - else: - self._lines = list(test) - self._all_object_names = self._solids + self._sheets + self._lines + self._points + self.__refresh_object_type("Lines") + + @pyaedt_function_handler() + def _refresh_unclassified(self): + self.__refresh_object_type("Unclassified") + # TODO: Checks should be performed to check if all objects values are really reachable @pyaedt_function_handler() def _refresh_points(self): try: - test = self.oeditor.GetPoints() + objects = self.oeditor.GetPoints() except (TypeError, AttributeError): - test = [] - if test is False: - assert False, "Get Points is failing" - elif test is True or test is None: + objects = [] + if objects is False: + raise RuntimeError(f"Get points is failing") + elif objects is True or objects is None: self._points = [] # In IronPython True is returned when no points are present else: - self._points = list(test) + self._points = list(objects) self._all_object_names = self._solids + self._sheets + self._lines + self._points @pyaedt_function_handler() @@ -8585,20 +8641,6 @@ def _refresh_planes(self): self._planes = {} self._all_object_names = self._solids + self._sheets + self._lines + self._points + list(self._planes.keys()) - @pyaedt_function_handler() - def _refresh_unclassified(self): - try: - test = self.oeditor.GetObjectsInGroup("Unclassified") - except (TypeError, AttributeError): - test = [] - if test is None or test is False: - self._unclassified = [] - self.logger.debug("Unclassified is failing") - elif test is True: - self._unclassified = [] # In IronPython True is returned when no unclassified are present - else: - self._unclassified = list(test) - @pyaedt_function_handler() def _refresh_object_types(self): self._refresh_solids() @@ -8741,8 +8783,8 @@ def _crosssection_arguments(self, type, orient, width, topwidth, height, num_seg section_bend = "Corner" # Ensure number-of segments is valid - if num_seg: - assert num_seg > 2, "Number of segments for a cross-section must be 0 or greater than 2." + if num_seg and num_seg < 3: + self.logger.error("Number of segments for a cross-section must be 0 or greater than 2") model_units = self.model_units arg_str += ["XSectionType:=", section_type] @@ -8771,17 +8813,17 @@ def _arg_with_dim(self, value, units=None): @pyaedt_function_handler() def _pos_with_arg(self, pos, units=None): - xpos = self._arg_with_dim(pos[0], units) + x_pos = self._arg_with_dim(pos[0], units) if len(pos) < 2: - ypos = self._arg_with_dim(0, units) + y_pos = self._arg_with_dim(0, units) else: - ypos = self._arg_with_dim(pos[1], units) + y_pos = self._arg_with_dim(pos[1], units) if len(pos) < 3: - zpos = self._arg_with_dim(0, units) + z_pos = self._arg_with_dim(0, units) else: - zpos = self._arg_with_dim(pos[2], units) + z_pos = self._arg_with_dim(pos[2], units) - return xpos, ypos, zpos + return x_pos, y_pos, z_pos @pyaedt_function_handler() def _str_list(self, theList): diff --git a/src/ansys/aedt/core/modeler/cad/primitives_2d.py b/src/ansys/aedt/core/modeler/cad/primitives_2d.py index fee3a4a67d9..82808b9d87f 100644 --- a/src/ansys/aedt/core/modeler/cad/primitives_2d.py +++ b/src/ansys/aedt/core/modeler/cad/primitives_2d.py @@ -101,21 +101,29 @@ def create_circle( """ # TODO: kwargs such as 'matname' and 'nonmodel' should be deprecated. - szAxis = self.plane2d - XCenter, YCenter, ZCenter = self._pos_with_arg(origin) - Radius = self._arg_with_dim(radius) - - vArg1 = ["NAME:CircleParameters"] - vArg1.append("IsCovered:="), vArg1.append(is_covered) - vArg1.append("XCenter:="), vArg1.append(XCenter) - vArg1.append("YCenter:="), vArg1.append(YCenter) - vArg1.append("ZCenter:="), vArg1.append(ZCenter) - vArg1.append("Radius:="), vArg1.append(Radius) - vArg1.append("WhichAxis:="), vArg1.append(szAxis) - vArg1.append("NumSegments:="), vArg1.append(f"{num_sides}") - - vArg2 = self._default_object_attributes(name=name, material=material, flags="NonModel#" if non_model else "") - new_object_name = self.oeditor.CreateCircle(vArg1, vArg2) + axis = self.plane2d + x_center, y_center, z_center = self._pos_with_arg(origin) + radius = self._arg_with_dim(radius) + + arg_1 = [ + "NAME:CircleParameters", + "IsCovered:=", + is_covered, + "XCenter:=", + x_center, + "YCenter:=", + y_center, + "ZCenter:=", + z_center, + "Radius:=", + radius, + "WhichAxis:=", + axis, + "NumSegments:=", + f"{num_sides}", + ] + arg_2 = self._default_object_attributes(name=name, material=material, flags="NonModel#" if non_model else "") + new_object_name = self.oeditor.CreateCircle(arg_1, arg_2) return self._create_object(new_object_name, **kwargs) # fmt: off @@ -175,21 +183,22 @@ def create_ellipse( >>> ellipse2 = aedtapp.modeler.create_ellipse(origin=[0, -2, -2], major_radius=4.0, ratio=0.2, ... name="MyEllipse", material="Copper") """ - szAxis = self.plane2d - XStart, YStart, ZStart = self._pos_with_arg(origin) - - vArg1 = ["NAME:EllipseParameters"] - vArg1.append("IsCovered:="), vArg1.append(is_covered) - vArg1.append("XCenter:="), vArg1.append(XStart) - vArg1.append("YCenter:="), vArg1.append(YStart) - vArg1.append("ZCenter:="), vArg1.append(ZStart) - vArg1.append("MajRadius:="), vArg1.append(self._arg_with_dim(major_radius)) - vArg1.append("Ratio:="), vArg1.append(ratio) - vArg1.append("WhichAxis:="), vArg1.append(szAxis) - vArg1.append("NumSegments:="), vArg1.append(segments) - - vArg2 = self._default_object_attributes(name=name, material=material, flags="NonModel#" if non_model else "") - new_object_name = self.oeditor.CreateEllipse(vArg1, vArg2) + axis = self.plane2d + x_center, y_center, z_center = self._pos_with_arg(origin) + + arg_1 = [ + "NAME:EllipseParameters", + "IsCovered:=", is_covered, + "XCenter:=", x_center, + "YCenter:=", y_center, + "ZCenter:=", z_center, + "MajRadius:=", self._arg_with_dim(major_radius), + "Ratio:=", ratio, + "WhichAxis:=", axis, + "NumSegments:=", segments + ] + arg_2 = self._default_object_attributes(name=name, material=material, flags="NonModel#" if non_model else "") + new_object_name = self.oeditor.CreateEllipse(arg_1, arg_2) return self._create_object(new_object_name, **kwargs) @pyaedt_function_handler(position="origin", dimension_list="sizes", matname="material") @@ -235,17 +244,19 @@ def create_rectangle(self, origin, sizes, is_covered=True, name=None, material=N width = self._arg_with_dim(sizes[0]) height = self._arg_with_dim(sizes[1]) - vArg1 = ["NAME:RectangleParameters"] - vArg1.append("IsCovered:="), vArg1.append(is_covered) - vArg1.append("XStart:="), vArg1.append(x_start) - vArg1.append("YStart:="), vArg1.append(y_start) - vArg1.append("ZStart:="), vArg1.append(z_start) - vArg1.append("Width:="), vArg1.append(width) - vArg1.append("Height:="), vArg1.append(height) - vArg1.append("WhichAxis:="), vArg1.append(axis) - - vArg2 = self._default_object_attributes(name=name, material=material, flags="NonModel#" if non_model else "") - new_object_name = self.oeditor.CreateRectangle(vArg1, vArg2) + arg_1 = [ + "NAME:RectangleParameters", + "IsCovered:=", is_covered, + "XStart:=", x_start, + "YStart:=", y_start, + "ZStart:=", z_start, + "Width:=", width, + "Height:=", height, + "WhichAxis:=", axis + ] + + arg_2 = self._default_object_attributes(name=name, material=material, flags="NonModel#" if non_model else "") + new_object_name = self.oeditor.CreateRectangle(arg_1, arg_2) return self._create_object(new_object_name, **kwargs) @pyaedt_function_handler(position="origin", matname="material") @@ -295,21 +306,24 @@ def create_regular_polygon( x_start, y_start, z_start = self._pos_with_arg(start_point) n_sides = int(num_sides) - assert n_sides > 2 # TODO: Replace assert with an exception. - - vArg1 = ["NAME:RegularPolygonParameters"] - vArg1.append("XCenter:="), vArg1.append(x_center) - vArg1.append("YCenter:="), vArg1.append(y_center) - vArg1.append("ZCenter:="), vArg1.append(z_center) - vArg1.append("XStart:="), vArg1.append(x_start) - vArg1.append("YStart:="), vArg1.append(y_start) - vArg1.append("ZStart:="), vArg1.append(z_start) - - vArg1.append("NumSides:="), vArg1.append(n_sides) - vArg1.append("WhichAxis:="), vArg1.append(self.plane2d) - - vArg2 = self._default_object_attributes(name=name, material=material, flags="NonModel#" if non_model else "") - new_object_name = self.oeditor.CreateRegularPolygon(vArg1, vArg2) + if n_sides < 3: + self.logger.error("Number of sides must be an integer >= 3.") + return False + + arg_1 = [ + "NAME:RegularPolygonParameters", + "XCenter:=", x_center, + "YCenter:=", y_center, + "ZCenter:=", z_center, + "XStart:=", x_start, + "YStart:=", y_start, + "ZStart:=", z_start, + "NumSides:=", n_sides, + "WhichAxis:=", self.plane2d + ] + + arg_2 = self._default_object_attributes(name=name, material=material, flags="NonModel#" if non_model else "") + new_object_name = self.oeditor.CreateRegularPolygon(arg_1, arg_2) return self._create_object(new_object_name, **kwargs) @pyaedt_function_handler(region_name="name") diff --git a/src/ansys/aedt/core/modeler/cad/primitives_3d.py b/src/ansys/aedt/core/modeler/cad/primitives_3d.py index 51fb08aebd7..69c31285bd6 100644 --- a/src/ansys/aedt/core/modeler/cad/primitives_3d.py +++ b/src/ansys/aedt/core/modeler/cad/primitives_3d.py @@ -159,17 +159,25 @@ def create_box(self, origin, sizes, name=None, material=None, **kwargs): self.logger.error("The ``dimension_list`` argument must be a valid three-element list.") return False - XPosition, YPosition, ZPosition = self._pos_with_arg(origin) - XSize, YSize, ZSize = self._pos_with_arg(sizes) - vArg1 = ["NAME:BoxParameters"] - vArg1.append("XPosition:="), vArg1.append(XPosition) - vArg1.append("YPosition:="), vArg1.append(YPosition) - vArg1.append("ZPosition:="), vArg1.append(ZPosition) - vArg1.append("XSize:="), vArg1.append(XSize) - vArg1.append("YSize:="), vArg1.append(YSize) - vArg1.append("ZSize:="), vArg1.append(ZSize) - vArg2 = self._default_object_attributes(name=name, material=material) - new_object_name = self.oeditor.CreateBox(vArg1, vArg2) + x_position, y_position, z_position = self._pos_with_arg(origin) + x_size, y_size, z_size = self._pos_with_arg(sizes) + arg_1 = [ + "NAME:BoxParameters", + "XPosition:=", + x_position, + "YPosition:=", + y_position, + "ZPosition:=", + z_position, + "XSize:=", + x_size, + "YSize:=", + y_size, + "ZSize:=", + z_size, + ] + arg_2 = self._default_object_attributes(name=name, material=material) + new_object_name = self.oeditor.CreateBox(arg_1, arg_2) return self._create_object(new_object_name, **kwargs) @pyaedt_function_handler(cs_axis="orientation", position="origin", numSides="num_sides", matname="material") @@ -234,22 +242,31 @@ def create_cylinder(self, orientation, origin, radius, height, num_sides=0, name self.logger.error("The ``position`` argument must be a valid three-element list.") return False - szAxis = GeometryOperators.cs_axis_str(orientation) - XCenter, YCenter, ZCenter = self._pos_with_arg(origin) - - Radius = self._arg_with_dim(radius) - Height = self._arg_with_dim(height) - - vArg1 = ["NAME:CylinderParameters"] - vArg1.append("XCenter:="), vArg1.append(XCenter) - vArg1.append("YCenter:="), vArg1.append(YCenter) - vArg1.append("ZCenter:="), vArg1.append(ZCenter) - vArg1.append("Radius:="), vArg1.append(Radius) - vArg1.append("Height:="), vArg1.append(Height) - vArg1.append("WhichAxis:="), vArg1.append(szAxis) - vArg1.append("NumSides:="), vArg1.append(f"{num_sides}") - vArg2 = self._default_object_attributes(name=name, material=material) - new_object_name = self.oeditor.CreateCylinder(vArg1, vArg2) + axis = GeometryOperators.cs_axis_str(orientation) + x_center, y_center, z_center = self._pos_with_arg(origin) + + radius = self._arg_with_dim(radius) + height = self._arg_with_dim(height) + + arg_1 = [ + "NAME:CylinderParameters", + "XCenter:=", + x_center, + "YCenter:=", + y_center, + "ZCenter:=", + z_center, + "Radius:=", + radius, + "Height:=", + height, + "WhichAxis:=", + axis, + "NumSides:=", + f"{num_sides}", + ] + arg_2 = self._default_object_attributes(name=name, material=material) + new_object_name = self.oeditor.CreateCylinder(arg_1, arg_2) return self._create_object(new_object_name, **kwargs) # fmt: off @@ -322,18 +339,20 @@ def create_polyhedron(self, orientation=None, center=(0.0, 0.0, 0.0), origin=(0. height = self._arg_with_dim(height) - vArg1 = ["NAME:PolyhedronParameters"] - vArg1.append("XCenter:="), vArg1.append(x_center) - vArg1.append("YCenter:="), vArg1.append(y_center) - vArg1.append("ZCenter:="), vArg1.append(z_center) - vArg1.append("XStart:="), vArg1.append(x_start) - vArg1.append("YStart:="), vArg1.append(y_start) - vArg1.append("ZStart:="), vArg1.append(z_start) - vArg1.append("Height:="), vArg1.append(height) - vArg1.append("NumSides:="), vArg1.append(int(num_sides)) - vArg1.append("WhichAxis:="), vArg1.append(orientation) - vArg2 = self._default_object_attributes(name=name, material=material) - new_object_name = self.oeditor.CreateRegularPolyhedron(vArg1, vArg2) + arg_1 = [ + "NAME:PolyhedronParameters", + "XCenter:=", x_center, + "YCenter:=", y_center, + "ZCenter:=", z_center, + "XStart:=", x_start, + "YStart:=", y_start, + "ZStart:=", z_start, + "Height:=", height, + "NumSides:=", int(num_sides), + "WhichAxis:=", orientation + ] + arg_2 = self._default_object_attributes(name=name, material=material) + new_object_name = self.oeditor.CreateRegularPolyhedron(arg_1, arg_2) return self._create_object(new_object_name, **kwargs) @pyaedt_function_handler(cs_axis="orientation", position="origin", matname="material") @@ -405,22 +424,22 @@ def create_cone(self, orientation, origin, bottom_radius, top_radius, height, na self.logger.error("The ``position`` argument must be a valid three-element list.") return False - XCenter, YCenter, ZCenter = self._pos_with_arg(origin) - szAxis = GeometryOperators.cs_axis_str(orientation) - Height = self._arg_with_dim(height) - RadiusBt = self._arg_with_dim(bottom_radius) - RadiusUp = self._arg_with_dim(top_radius) - - vArg1 = ["NAME:ConeParameters"] - vArg1.append("XCenter:="), vArg1.append(XCenter) - vArg1.append("YCenter:="), vArg1.append(YCenter) - vArg1.append("ZCenter:="), vArg1.append(ZCenter) - vArg1.append("WhichAxis:="), vArg1.append(szAxis) - vArg1.append("Height:="), vArg1.append(Height) - vArg1.append("BottomRadius:="), vArg1.append(RadiusBt) - vArg1.append("TopRadius:="), vArg1.append(RadiusUp) - vArg2 = self._default_object_attributes(name=name, material=material) - new_object_name = self.oeditor.CreateCone(vArg1, vArg2) + x_center, y_center, z_center = self._pos_with_arg(origin) + axis = GeometryOperators.cs_axis_str(orientation) + height = self._arg_with_dim(height) + bottom_radius = self._arg_with_dim(bottom_radius) + top_radius = self._arg_with_dim(top_radius) + + arg_1 = ["NAME:ConeParameters", + "XCenter:=", x_center, + "YCenter:=", y_center, + "ZCenter:=", z_center, + "WhichAxis:=", axis, + "Height:=", height, + "BottomRadius:=", bottom_radius, + "TopRadius:=", top_radius] + arg_2 = self._default_object_attributes(name=name, material=material) + new_object_name = self.oeditor.CreateCone(arg_1, arg_2) return self._create_object(new_object_name, **kwargs) @pyaedt_function_handler(position="origin", matname="material") @@ -472,17 +491,18 @@ def create_sphere(self, origin, radius, name=None, material=None, **kwargs): self.logger.error("The ``radius`` argument must be greater than 0.") return False - XCenter, YCenter, ZCenter = self._pos_with_arg(origin) - - Radius = self._arg_with_dim(radius) - - vArg1 = ["NAME:SphereParameters"] - vArg1.append("XCenter:="), vArg1.append(XCenter) - vArg1.append("YCenter:="), vArg1.append(YCenter) - vArg1.append("ZCenter:="), vArg1.append(ZCenter) - vArg1.append("Radius:="), vArg1.append(Radius) - vArg2 = self._default_object_attributes(name=name, material=material) - new_object_name = self.oeditor.CreateSphere(vArg1, vArg2) + x_center, y_center, z_center = self._pos_with_arg(origin) + radius = self._arg_with_dim(radius) + + arg_1 = [ + "NAME:SphereParameters", + "XCenter:=", x_center, + "YCenter:=", y_center, + "ZCenter:=", z_center, + "Radius:=", radius, + ] + arg_2 = self._default_object_attributes(name=name, material=material) + new_object_name = self.oeditor.CreateSphere(arg_1, arg_2) return self._create_object(new_object_name, **kwargs) @pyaedt_function_handler(center="origin", material_name="material") @@ -747,22 +767,24 @@ def create_rectangle(self, orientation, origin, sizes, name=None, material=None, if len(sizes) != 2: self.logger.error("The ``sizes`` argument must be a valid two-element list.") return False - szAxis = GeometryOperators.cs_plane_to_axis_str(orientation) - XStart, YStart, ZStart = self._pos_with_arg(origin) - - Width = self._arg_with_dim(sizes[0]) - Height = self._arg_with_dim(sizes[1]) - - vArg1 = ["NAME:RectangleParameters"] - vArg1.append("IsCovered:="), vArg1.append(is_covered) - vArg1.append("XStart:="), vArg1.append(XStart) - vArg1.append("YStart:="), vArg1.append(YStart) - vArg1.append("ZStart:="), vArg1.append(ZStart) - vArg1.append("Width:="), vArg1.append(Width) - vArg1.append("Height:="), vArg1.append(Height) - vArg1.append("WhichAxis:="), vArg1.append(szAxis) - vArg2 = self._default_object_attributes(name=name, material=material) - new_object_name = self.oeditor.CreateRectangle(vArg1, vArg2) + + axis = GeometryOperators.cs_plane_to_axis_str(orientation) + x_start, y_start, z_start = self._pos_with_arg(origin) + width = self._arg_with_dim(sizes[0]) + height = self._arg_with_dim(sizes[1]) + + arg_1 = [ + "NAME:RectangleParameters", + "IsCovered:=", is_covered, + "XStart:=", x_start, + "YStart:=", y_start, + "ZStart:=", z_start, + "Width:=", width, + "Height:=", height, + "WhichAxis:=", axis + ] + arg_2 = self._default_object_attributes(name=name, material=material) + new_object_name = self.oeditor.CreateRectangle(arg_1, arg_2) return self._create_object(new_object_name, **kwargs) # fmt: off @@ -828,19 +850,21 @@ def create_circle(self, orientation, origin, radius, num_sides=0, is_covered=Tru non_model_flag = "" if non_model: non_model_flag = "NonModel#" - szAxis = GeometryOperators.cs_plane_to_axis_str(orientation) - XCenter, YCenter, ZCenter = self._pos_with_arg(origin) - Radius = self._arg_with_dim(radius) - vArg1 = ["NAME:CircleParameters"] - vArg1.append("IsCovered:="), vArg1.append(is_covered) - vArg1.append("XCenter:="), vArg1.append(XCenter) - vArg1.append("YCenter:="), vArg1.append(YCenter) - vArg1.append("ZCenter:="), vArg1.append(ZCenter) - vArg1.append("Radius:="), vArg1.append(Radius) - vArg1.append("WhichAxis:="), vArg1.append(szAxis) - vArg1.append("NumSegments:="), vArg1.append(f"{num_sides}") - vArg2 = self._default_object_attributes(name=name, material=material, flags=non_model_flag) - new_object_name = self.oeditor.CreateCircle(vArg1, vArg2) + axis = GeometryOperators.cs_plane_to_axis_str(orientation) + x_center, y_center, z_center = self._pos_with_arg(origin) + radius = self._arg_with_dim(radius) + arg_1 = [ + "NAME:CircleParameters", + "IsCovered:=", is_covered, + "XCenter:=", x_center, + "YCenter:=", y_center, + "ZCenter:=", z_center, + "Radius:=", radius, + "WhichAxis:=", axis, + "NumSegments:=", f"{num_sides}" + ] + arg_2 = self._default_object_attributes(name=name, material=material, flags=non_model_flag) + new_object_name = self.oeditor.CreateCircle(arg_1, arg_2) return self._create_object(new_object_name, **kwargs) @pyaedt_function_handler(cs_plane="orientation", position="origin", matname="material") @@ -919,23 +943,23 @@ def create_ellipse( ... major_radius=2, ratio=2, is_covered=True, name="myell", ... material="vacuum") """ - szAxis = GeometryOperators.cs_plane_to_axis_str(orientation) - XStart, YStart, ZStart = self._pos_with_arg(origin) - - MajorRadius = self._arg_with_dim(major_radius) - - vArg1 = ["NAME:EllipseParameters"] - vArg1.append("IsCovered:="), vArg1.append(is_covered) - vArg1.append("XCenter:="), vArg1.append(XStart) - vArg1.append("YCenter:="), vArg1.append(YStart) - vArg1.append("ZCenter:="), vArg1.append(ZStart) - vArg1.append("MajRadius:="), vArg1.append(MajorRadius) - vArg1.append("Ratio:="), vArg1.append(ratio) - vArg1.append("WhichAxis:="), vArg1.append(szAxis) - vArg1.append("NumSegments:="), vArg1.append(segments) - - vArg2 = self._default_object_attributes(name=name, material=material) - new_object_name = self.oeditor.CreateEllipse(vArg1, vArg2) + axis = GeometryOperators.cs_plane_to_axis_str(orientation) + x_start, y_start, z_start = self._pos_with_arg(origin) + major_radius = self._arg_with_dim(major_radius) + + arg_1 = [ + "NAME:EllipseParameters", + "IsCovered:=", is_covered, + "XCenter:=", x_start, + "YCenter:=", y_start, + "ZCenter:=", z_start, + "MajRadius:=", major_radius, + "Ratio:=", ratio, + "WhichAxis:=", axis, + "NumSegments:=", segments + ] + arg_2 = self._default_object_attributes(name=name, material=material) + new_object_name = self.oeditor.CreateEllipse(arg_1, arg_2) return self._create_object(new_object_name, **kwargs) # fmt: off @@ -1039,28 +1063,21 @@ def create_equationbased_curve(self, x_t=0, y_t=0, z_t=0, t_start=0, t_end=1, nu bend_type=xsection_bend_type, ) - vArg1 = [ + arg_1 = [ "NAME:EquationBasedCurveParameters", - "XtFunction:=", - str(x_t), - "YtFunction:=", - str(y_t), - "ZtFunction:=", - str(z_t), - "tStart:=", - str(t_start), - "tEnd:=", - str(t_end), - "NumOfPointsOnCurve:=", - num_points, - "Version:=", - 1, + "XtFunction:=", str(x_t), + "YtFunction:=", str(y_t), + "ZtFunction:=", str(z_t), + "tStart:=", str(t_start), + "tEnd:=", str(t_end), + "NumOfPointsOnCurve:=", num_points, + "Version:=", 1, x_section, ] - vArg2 = self._default_object_attributes(name) + arg_2 = self._default_object_attributes(name) - new_name = self.oeditor.CreateEquationCurve(vArg1, vArg2) + new_name = self.oeditor.CreateEquationCurve(arg_1, arg_2) return self._create_object(new_name, **kwargs) # fmt: off @@ -1123,29 +1140,21 @@ def create_equationbased_surface(self, x_uv=0, y_uv=0, z_uv=0, u_start=0, u_end= ... ) """ - vArg1 = [ + arg_1 = [ "NAME:EquationBasedSurfaceParameters", - "XuvFunction:=", - str(x_uv), - "YuvFunction:=", - str(y_uv), - "ZuvFunction:=", - str(z_uv), - "uStart:=", - str(u_start), - "uEnd:=", - str(u_end), - "vStart:=", - str(v_start), - "vEnd:=", - str(v_end), - "Version:=", - 1, + "XuvFunction:=", str(x_uv), + "YuvFunction:=", str(y_uv), + "ZuvFunction:=", str(z_uv), + "uStart:=", str(u_start), + "uEnd:=", str(u_end), + "vStart:=", str(v_start), + "vEnd:=", str(v_end), + "Version:=", 1, ] - vArg2 = self._default_object_attributes(name) + arg_2 = self._default_object_attributes(name) - new_name = self.oeditor.CreateEquationSurface(vArg1, vArg2) + new_name = self.oeditor.CreateEquationSurface(arg_1, arg_2) return self._create_object(new_name, **kwargs) # fmt: off @@ -1213,33 +1222,25 @@ def create_helix(self, assignment, origin, x_start_dir, y_start_dir, z_start_dir return False x_center, y_center, z_center = self._pos_with_arg(origin) - vArg1 = ["NAME:Selections"] - vArg1.append("Selections:="), vArg1.append(assignment) - vArg1.append("NewPartsModelFlag:="), vArg1.append("Model") - - vArg2 = ["NAME:HelixParameters"] - vArg2.append("XCenter:=") - vArg2.append(x_center) - vArg2.append("YCenter:=") - vArg2.append(y_center) - vArg2.append("ZCenter:=") - vArg2.append(z_center) - vArg2.append("XStartDir:=") - vArg2.append(self._arg_with_dim(x_start_dir)) - vArg2.append("YStartDir:=") - vArg2.append(self._arg_with_dim(y_start_dir)) - vArg2.append("ZStartDir:=") - vArg2.append(self._arg_with_dim(z_start_dir)) - vArg2.append("NumThread:=") - vArg2.append(turns) - vArg2.append("RightHand:=") - vArg2.append(right_hand) - vArg2.append("RadiusIncrement:=") - vArg2.append(self._arg_with_dim(radius_increment)) - vArg2.append("Thread:=") - vArg2.append(self._arg_with_dim(thread)) - - self.oeditor.CreateHelix(vArg1, vArg2) + arg_1 = [ + "NAME:Selections", + "Selections:=", assignment, + "NewPartsModelFlag:=", "Model" + ] + arg_2 = [ + "NAME:HelixParameters", + "XCenter:=", x_center, + "YCenter:=", y_center, + "ZCenter:=", z_center, + "XStartDir:=", self._arg_with_dim(x_start_dir), + "YStartDir:=", self._arg_with_dim(y_start_dir), + "ZStartDir:=", self._arg_with_dim(z_start_dir), + "NumThread:=", turns, + "RightHand:=", right_hand, + "RadiusIncrement:=", self._arg_with_dim(radius_increment), + "Thread:=", self._arg_with_dim(thread) + ] + self.oeditor.CreateHelix(arg_1, arg_2) if assignment in self.objects_by_name: del self.objects[self.objects_by_name[assignment].id] return self._create_object(assignment, **kwargs) @@ -1275,8 +1276,8 @@ def create_udm( >>> oEditor.CreateUserDefinedModel """ - vArg1 = ["NAME:UserDefinedModelParameters", ["NAME:Definition"], ["NAME:Options"]] - vArgParamVector = ["NAME:GeometryParams"] + arg_1 = ["NAME:UserDefinedModelParameters", ["NAME:Definition"], ["NAME:Options"]] + arg_param_vector = ["NAME:GeometryParams"] for pair in parameters: if isinstance(pair, list): @@ -1286,44 +1287,36 @@ def create_udm( name_param = pair.Name val = pair.Value if isinstance(val, int): - vArgParamVector.append( + arg_param_vector += [ ["NAME:UDMParam", "Name:=", name_param, "Value:=", str(val), "PropType2:=", 3, "PropFlag2:=", 2] - ) + ] elif str(val)[0] in "0123456789": - vArgParamVector.append( + arg_param_vector += [ ["NAME:UDMParam", "Name:=", name_param, "Value:=", str(val), "PropType2:=", 3, "PropFlag2:=", 4] - ) + ] elif val in self._app.variable_manager.variables: - vArgParamVector.append( + arg_param_vector += [ ["NAME:UDMParam", "Name:=", name_param, "Value:=", str(val), "PropType2:=", 3, "PropFlag2:=", 2] - ) + ] else: - vArgParamVector.append( + arg_param_vector += [ [ "NAME:UDMParam", - "Name:=", - name_param, - "Value:=", - str(val), - "DataType:=", - "String", - "PropType2:=", - 1, - "PropFlag2:=", - 0, + "Name:=", name_param, + "Value:=", str(val), + "DataType:=", "String", + "PropType2:=", 1, + "PropFlag2:=", 0, ] - ) - - vArg1.append(vArgParamVector) - vArg1.append("DllName:=") - vArg1.append(udm_full_name) - vArg1.append("Library:=") - vArg1.append(library) - vArg1.append("Version:=") - vArg1.append("2.0") - vArg1.append("ConnectionID:=") - vArg1.append("") - oname = self.oeditor.CreateUserDefinedModel(vArg1) + ] + arg_1 += [ + arg_param_vector, + "DllName:=", udm_full_name, + "Library:=", library, + "Version:=", "2.0", + "ConnectionID:=", "", + ] + oname = self.oeditor.CreateUserDefinedModel(arg_1) if oname: obj_list = list(self.oeditor.GetPartsForUserDefinedModel(oname)) for new_name in obj_list: @@ -1588,10 +1581,10 @@ def insert_3d_component( for line in _all_lines: if "IsEncrypted" in line: line_list = line.split("=") - if line_list[1] in ["true", "True", True] and password == "": - self.logger.warning("Encrypted model.") + if line_list[1] in ["true", "True", True] and not password: + self.logger.warning("Encrypted model but no password provided.") aedt_fh.close() - vArg1 = ["NAME:InsertComponentData"] + sz_geo_params = "" if not geometry_parameters: geometryparams = self._app.get_components3d_vars(input_file) @@ -1600,28 +1593,22 @@ def insert_3d_component( if geometry_parameters: sz_geo_params = "".join([f"{par}='{val}' " for par, val in geometry_parameters.items()]) - vArg1.append("TargetCS:=") - vArg1.append(coordinate_system) - vArg1.append("ComponentFile:=") - vArg1.append(input_file) - vArg1.append("IsLocal:=") - vArg1.append(False) - vArg1.append("UniqueIdentifier:=") - vArg1.append("") - varg2 = [ + arg_1 = [ + "NAME:InsertComponentData", + "TargetCS:=", coordinate_system, + "ComponentFile:=", input_file, + "IsLocal:=", False, + "UniqueIdentifier:=", "" + ] + arg_2 = [ "NAME:InstanceParameters", - "GeometryParameters:=", - sz_geo_params, - "MaterialParameters:=", - material_parameters, - "DesignParameters:=", - design_parameters, + "GeometryParameters:=", sz_geo_params, + "MaterialParameters:=", material_parameters, + "DesignParameters:=", design_parameters, ] - vArg1.append(varg2) - vArg1.append("Password:=") - vArg1.append(password) + arg_1 += [arg_2, "Password:=", password] try: - new_object_name = self.oeditor.Insert3DComponent(vArg1) + new_object_name = self.oeditor.Insert3DComponent(arg_1) if new_object_name: obj_list = list(self.oeditor.Get3DComponentPartNames(new_object_name)) for new_name in obj_list: @@ -1865,133 +1852,94 @@ def insert_layout_component( component_obj.close() - vArg1 = ["NAME:InsertNativeComponentData"] - vArg1.append("TargetCS:=") - vArg1.append(coordinate_system) - vArg1.append("SubmodelDefinitionName:=") - vArg1.append("LC") - varg2 = ["NAME:ComponentPriorityLists"] - vArg1.append(varg2) - vArg1.append("NextUniqueID:=") - vArg1.append(0) - vArg1.append("MoveBackwards:=") - vArg1.append(False) - vArg1.append("DatasetType:=") - vArg1.append("ComponentDatasetType") - varg3 = ["NAME:DatasetDefinitions"] - vArg1.append(varg3) - varg4 = [ - "NAME:BasicComponentInfo", - "ComponentName:=", - "LC", - "Company:=", - "", - "Company URL:=", - "", - "Model Number:=", - "", - "Help URL:=", - "", - "Version:=", - "1.0", - "Notes:=", - "", - "IconType:=", - "Layout Component", + arg_1 = [ + "NAME:InsertNativeComponentData", + "TargetCS:=", coordinate_system, + "SubmodelDefinitionName:=", "LC", + ["NAME:ComponentPriorityLists"], + "NextUniqueID:=", 0, + "MoveBackwards:=", False, + "DatasetType:=", "ComponentDatasetType", + ["NAME:DatasetDefinitions"], + [ + "NAME:BasicComponentInfo", + "ComponentName:=", "LC", + "Company:=", "", + "Company URL:=", "", + "Model Number:=", "", + "Help URL:=", "", + "Version:=", "1.0", + "Notes:=", "", + "IconType:=", "Layout Component", + ], ] - vArg1.append(varg4) - varg5 = [ + sub_arg_0 = [ "NAME:GeometryDefinitionParameters", ] if parameters and parameter_mapping: for param in parameters: - varg5.append("VariableProp:=") - varg5.append([parameters[param][0], "D", "", parameters[param][1]]) - - varg5.append(["NAME:VariableOrders"]) - vArg1.append(varg5) - - varg6 = ["NAME:DesignDefinitionParameters", ["NAME:VariableOrders"]] - vArg1.append(varg6) - - varg7 = ["NAME:MaterialDefinitionParameters", ["NAME:VariableOrders"]] - vArg1.append(varg7) - - vArg1.append("DefReferenceCSID:=") - vArg1.append(1) - vArg1.append("MapInstanceParameters:=") - vArg1.append("DesignVariable") - vArg1.append("UniqueDefinitionIdentifier:=") - vArg1.append("") - vArg1.append("OriginFilePath:=") - vArg1.append("") - vArg1.append("IsLocal:=") - vArg1.append(False) - vArg1.append("ChecksumString:=") - vArg1.append("") - vArg1.append("ChecksumHistory:=") - vArg1.append([]) - vArg1.append("VersionHistory:=") - vArg1.append([]) - - varg8 = ["NAME:VariableMap"] - + sub_arg_0 += ["VariableProp:=", [parameters[param][0], "D", "", parameters[param][1]]] + sub_arg_0.append(["NAME:VariableOrders"]) + arg_1.append(sub_arg_0) + arg_1.append(["NAME:DesignDefinitionParameters", ["NAME:VariableOrders"]]) + arg_1.append(["NAME:MaterialDefinitionParameters", ["NAME:VariableOrders"]]) + arg_1 += [ + "DefReferenceCSID:=", 1, + "MapInstanceParameters:=", "DesignVariable", + "UniqueDefinitionIdentifier:=", "", + "OriginFilePath:=", "", + "IsLocal:=", False, + "ChecksumString:=", "", + "ChecksumHistory:=", [], + "VersionHistory:=", [], + ] + sub_arg_1 = ["NAME:VariableMap"] for param in parameters: - varg8.append(param + ":=") + sub_arg_1.append(param + ":=") if parameter_mapping: - varg8.append(parameters[param][0]) + sub_arg_1.append(parameters[param][0]) else: - varg8.append(parameters[param][1]) - - varg9 = [ + sub_arg_1.append(parameters[param][1]) + sub_arg_2 = [ "NAME:NativeComponentDefinitionProvider", - "Type:=", - "Layout Component", - "Unit:=", - "mm", - "Version:=", - 1.1, - "EDBDefinition:=", - aedt_component_name, - varg8, - "ReferenceCS:=", - reference_coordinate_system, + "Type:=", "Layout Component", + "Unit:=", "mm", + "Version:=", 1.1, + "EDBDefinition:=", aedt_component_name, + sub_arg_1, + "ReferenceCS:=", reference_coordinate_system, "CSToImport:=", ] - if component_cs and not layout_coordinate_systems: # pragma: no cover - varg10 = component_cs - varg10.append("Global") + sub_arg_3 = component_cs + sub_arg_3.append("Global") elif component_cs and layout_coordinate_systems: # pragma: no cover - varg10 = ["Global"] + sub_arg_3 = ["Global"] for cs in layout_coordinate_systems: if cs in component_cs: - varg10.append(cs) + sub_arg_3.append(cs) else: - varg10 = ["Global"] - - varg9.append(varg10) - vArg1.append(varg9) + sub_arg_3 = ["Global"] - varg11 = ["NAME:InstanceParameters"] - varg11.append("GeometryParameters:=") + sub_arg_2.append(sub_arg_3) + arg_1.append(sub_arg_2) + sub_arg_4 = ["NAME:InstanceParameters", "GeometryParameters:="] if parameters and parameter_mapping: - varg12 = "" + sub_arg_5 = "" for param in parameters: - varg12 += f" {parameters[param][0]}='{parameters[param][0]}'" + sub_arg_5 += f" {parameters[param][0]}='{parameters[param][0]}'" else: - varg12 = "" - varg11.append(varg12[1:]) - - varg11.append("MaterialParameters:=") - varg11.append("") - varg11.append("DesignParameters:=") - varg11.append("") - vArg1.append(varg11) + sub_arg_5 = "" + sub_arg_4 += [ + sub_arg_5[1:], + "MaterialParameters:=", "", + "DesignParameters:=", "" + ] + arg_1.append(sub_arg_4) try: - new_object_name = self.oeditor.InsertNativeComponent(vArg1) + new_object_name = self.oeditor.InsertNativeComponent(arg_1) udm_obj = False if new_object_name: obj_list = list(self.oeditor.Get3DComponentPartNames(new_object_name)) diff --git a/src/ansys/aedt/core/modeler/circuits/object_3d_circuit.py b/src/ansys/aedt/core/modeler/circuits/object_3d_circuit.py index b388526f251..324640a4364 100644 --- a/src/ansys/aedt/core/modeler/circuits/object_3d_circuit.py +++ b/src/ansys/aedt/core/modeler/circuits/object_3d_circuit.py @@ -283,7 +283,7 @@ def connect_to_component( try: page_name = self._circuit_comp.name.split("@")[1].replace(";", "_") except Exception: - pass + self._component._circuit_components.logger.debug("Cannot parse page name from circuit component name") else: for cmp in assignment: if "Port" in cmp._circuit_comp.composed_name: @@ -291,7 +291,9 @@ def connect_to_component( page_name = cmp._circuit_comp.name.split("@")[1].replace(";", "_") break except Exception: - continue + self._component._circuit_components.logger.debug( + "Cannot parse page name from circuit component name" + ) try: x_loc = AEDT_UNITS["Length"][decompose_variable_value(self._circuit_comp.location[0])[1]] * float( decompose_variable_value(self._circuit_comp.location[1])[0]