.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples\01-Modeling-Setup\Polyline_Primitives.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_01-Modeling-Setup_Polyline_Primitives.py: General: polyline creation -------------------------- This example shows how you can use PyAEDT to create and manipulate polylines. .. GENERATED FROM PYTHON SOURCE LINES 8-11 Perform required imports ~~~~~~~~~~~~~~~~~~~~~~~~ Perform required imports. .. GENERATED FROM PYTHON SOURCE LINES 11-15 .. code-block:: Python import os import pyaedt .. GENERATED FROM PYTHON SOURCE LINES 16-19 Set AEDT version ~~~~~~~~~~~~~~~~ Set AEDT version. .. GENERATED FROM PYTHON SOURCE LINES 19-22 .. code-block:: Python aedt_version = "2024.1" .. GENERATED FROM PYTHON SOURCE LINES 23-27 Set non-graphical mode ~~~~~~~~~~~~~~~~~~~~~~ Set non-graphical mode. You can set ``non_graphical`` either to ``True`` or ``False``. .. GENERATED FROM PYTHON SOURCE LINES 27-30 .. code-block:: Python non_graphical = False .. GENERATED FROM PYTHON SOURCE LINES 31-34 Create Maxwell 3D object ~~~~~~~~~~~~~~~~~~~~~~~~ Create a :class:`pyaedt.maxwell.Maxwell3d` object and set the unit type to ``"mm"``. .. GENERATED FROM PYTHON SOURCE LINES 34-40 .. code-block:: Python M3D = pyaedt.Maxwell3d(solution_type="Transient", designname="test_polyline_3D", specified_version=aedt_version, new_desktop_session=True, non_graphical=non_graphical, ) M3D.modeler.model_units = "mm" prim3D = M3D.modeler .. GENERATED FROM PYTHON SOURCE LINES 41-44 Define variables ~~~~~~~~~~~~~~~~ Define two design variables as parameters for the polyline objects. .. GENERATED FROM PYTHON SOURCE LINES 44-48 .. code-block:: Python M3D["p1"] = "100mm" M3D["p2"] = "71mm" .. GENERATED FROM PYTHON SOURCE LINES 49-54 Input data ~~~~~~~~~~ Input data. All data for the polyline functions can be entered as either floating point values or strings. Floating point values are assumed to be in model units (``M3D.modeler.model_units``). .. GENERATED FROM PYTHON SOURCE LINES 54-57 .. code-block:: Python test_points = [["0mm", "p1", "0mm"], ["-p1", "0mm", "0mm"], ["-p1/2", "-p1/2", "0mm"], ["0mm", "0mm", "0mm"]] .. GENERATED FROM PYTHON SOURCE LINES 58-61 Polyline primitives ------------------- The following examples are for creating polyline primitives. .. GENERATED FROM PYTHON SOURCE LINES 61-75 .. code-block:: Python # Create line primitive # ~~~~~~~~~~~~~~~~~~~~~ # Create a line primitive. The basic polyline command takes a list of positions # (``[X, Y, Z]`` coordinates) and creates a polyline object with one or more # segments. The supported segment types are ``Line``, ``Arc`` (3 points), # ``AngularArc`` (center-point + angle), and ``Spline``. P = prim3D.create_polyline(points=test_points[0:2], name="PL01_line") print("Created Polyline with name: {}".format(prim3D.objects[P.id].name)) print("Segment types : {}".format([s.type for s in P.segment_types])) print("primitive id = {}".format(P.id)) .. rst-class:: sphx-glr-script-out .. code-block:: none Created Polyline with name: PL01_line Segment types : ['Line'] primitive id = 6 .. GENERATED FROM PYTHON SOURCE LINES 76-80 Create arc primitive ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Create an arc primitive. The parameter ``position_list`` must contain at least three position values. The first three position values are used. .. GENERATED FROM PYTHON SOURCE LINES 80-85 .. code-block:: Python P = prim3D.create_polyline(points=test_points[0:3], segment_type="Arc", name="PL02_arc") print("Created object with id {} and name {}.".format(P.id, prim3D.objects[P.id].name)) .. rst-class:: sphx-glr-script-out .. code-block:: none Created object with id 11 and name PL02_arc. .. GENERATED FROM PYTHON SOURCE LINES 86-92 Create spline primitive ~~~~~~~~~~~~~~~~~~~~~~~~~ Create a spline primitive. Defining the segment using a ``PolylineSegment`` object allows you to provide additional input parameters for the spine, such as the number of points (in this case 4). The parameter ``position_list`` must contain at least four position values. .. GENERATED FROM PYTHON SOURCE LINES 92-96 .. code-block:: Python P = prim3D.create_polyline(points=test_points, segment_type=prim3D.polyline_segment("Spline", num_points=4), name="PL03_spline_4pt") .. GENERATED FROM PYTHON SOURCE LINES 97-107 Create center-point arc primitive ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Create a center-point arc primitive. A center-point arc segment is defined by a starting point, a center point, and an angle of rotation around the center point. The rotation occurs in a plane parallel to the XY, YZ, or ZX plane of the active coordinate system. The starting point and the center point must therefore have one coordinate value (X, Y, or Z) with the same value. Here ``start-point`` and ``center-point`` have a common Z coordinate, ``"0mm"``. The curve is therefore rotated in the XY plane with Z = ``"0mm"``. .. GENERATED FROM PYTHON SOURCE LINES 107-114 .. code-block:: Python start_point = [100, 100, 0] center_point = [0, 0, 0] P = prim3D.create_polyline(points=[start_point], segment_type=prim3D.polyline_segment("AngularArc", arc_center=center_point, arc_angle="30deg"), name="PL04_center_point_arc") .. GENERATED FROM PYTHON SOURCE LINES 115-119 Here ``start_point`` and ``center_point`` have the same values for the Y and Z coordinates, so the plane or rotation could be either XY or ZX. For these special cases when the rotation plane is ambiguous, you can specify the plane explicitly. .. GENERATED FROM PYTHON SOURCE LINES 119-131 .. code-block:: Python start_point = [100, 0, 0] center_point = [0, 0, 0] P = prim3D.create_polyline(points=[start_point], segment_type=prim3D.polyline_segment("AngularArc", arc_center=center_point, arc_angle="30deg", arc_plane="XY"), name="PL04_center_point_arc_rot_XY") P = prim3D.create_polyline(points=[start_point], segment_type=prim3D.polyline_segment("AngularArc", arc_center=center_point, arc_angle="30deg", arc_plane="ZX"), name="PL04_center_point_arc_rot_ZX") .. GENERATED FROM PYTHON SOURCE LINES 132-139 Compound polylines ------------------ You can use a list of points in a single command to create a multi-segment polyline. By default, if no specification of the type of segments is given, all points are connected by line segments. .. GENERATED FROM PYTHON SOURCE LINES 139-142 .. code-block:: Python P = prim3D.create_polyline(points=test_points, name="PL06_segmented_compound_line") .. GENERATED FROM PYTHON SOURCE LINES 143-146 You can specify the segment type with the parameter ``segment_type``. In this case, you must specify that the four input points in ``position_list`` are to be connected as a line segment followed by a 3-point arc segment. .. GENERATED FROM PYTHON SOURCE LINES 146-149 .. code-block:: Python P = prim3D.create_polyline(points=test_points, segment_type=["Line", "Arc"], name="PL05_compound_line_arc") .. GENERATED FROM PYTHON SOURCE LINES 150-153 The parameter ``close_surface`` ensures that the polyline starting point and ending point are the same. If necessary, you can add an additional line segment to achieve this. .. GENERATED FROM PYTHON SOURCE LINES 153-156 .. code-block:: Python P = prim3D.create_polyline(points=test_points, close_surface=True, name="PL07_segmented_compound_line_closed") .. GENERATED FROM PYTHON SOURCE LINES 157-160 The parameter ``cover_surface=True`` also performs the modeler command ``cover_surface``. Note that specifying ``cover_surface=True`` automatically results in the polyline being closed. .. GENERATED FROM PYTHON SOURCE LINES 160-163 .. code-block:: Python P = prim3D.create_polyline(points=test_points, cover_surface=True, name="SPL01_segmented_compound_line") .. GENERATED FROM PYTHON SOURCE LINES 164-175 Compound lines -------------- The following examples are for inserting compound lines. Insert line segment ~~~~~~~~~~~~~~~~~~~ Insert a line segment starting at vertex 1 ``["100mm", "0mm", "0mm"]`` of an existing polyline and ending at some new point ``["90mm", "20mm", "0mm"].`` By numerical comparison of the starting point with the existing vertices of the original polyline object, it is determined automatically that the segment is inserted after the first segment of the original polyline. .. GENERATED FROM PYTHON SOURCE LINES 175-183 .. code-block:: Python P = prim3D.create_polyline(points=test_points, close_surface=True, name="PL08_segmented_compound_insert_segment") p2 = P.points[1] insert_point = ["-100mm", "20mm", "0mm"] P.insert_segment(points=[insert_point, p2]) .. rst-class:: sphx-glr-script-out .. code-block:: none True .. GENERATED FROM PYTHON SOURCE LINES 184-190 Insert compound line with insert curve ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Insert a compound line starting a line segment at vertex 1 ``["100mm", "0mm", "0mm"]`` of an existing polyline and end at some new point ``["90mm", "20mm", "0mm"]``. By numerical comparison of the starting point, it is determined automatically that the segment is inserted after the first segment of the original polyline. .. GENERATED FROM PYTHON SOURCE LINES 190-199 .. code-block:: Python P = prim3D.create_polyline(points=test_points, close_surface=False, name="PL08_segmented_compound_insert_arc") start_point = P.vertex_positions[1] insert_point1 = ["90mm", "20mm", "0mm"] insert_point2 = [40, 40, 0] P.insert_segment(points=[start_point, insert_point1, insert_point2], segment="Arc") .. rst-class:: sphx-glr-script-out .. code-block:: none True .. GENERATED FROM PYTHON SOURCE LINES 200-206 Insert compound line at end of a center-point arc ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Insert a compound line at the end of a center-point arc (``type="AngularArc"``). This is a special case. Step 1: Draw a center-point arc. .. GENERATED FROM PYTHON SOURCE LINES 206-215 .. code-block:: Python start_point = [2200.0, 0.0, 1200.0] arc_center_1 = [1400, 0, 800] arc_angle_1 = "43.47deg" P = prim3D.create_polyline(points=[start_point], segment_type=prim3D.polyline_segment(type="AngularArc", arc_angle=arc_angle_1, arc_center=arc_center_1), name="First_Arc") .. GENERATED FROM PYTHON SOURCE LINES 216-217 Step 2: Insert a line segment at the end of the arc with a specified end point. .. GENERATED FROM PYTHON SOURCE LINES 217-223 .. code-block:: Python start_of_line_segment = P.end_point end_of_line_segment = [3600, 200, 30] P.insert_segment(points=[start_of_line_segment, end_of_line_segment]) .. rst-class:: sphx-glr-script-out .. code-block:: none True .. GENERATED FROM PYTHON SOURCE LINES 224-225 Step 3: Append a center-point arc segment to the line object. .. GENERATED FROM PYTHON SOURCE LINES 225-232 .. code-block:: Python arc_angle_2 = "39.716deg" arc_center_2 = [3400, 200, 3800] P.insert_segment(points=[end_of_line_segment], segment=prim3D.polyline_segment(type="AngularArc", arc_center=arc_center_2, arc_angle=arc_angle_2)) .. rst-class:: sphx-glr-script-out .. code-block:: none True .. GENERATED FROM PYTHON SOURCE LINES 233-235 You can use the compound polyline definition to complete all three steps in a single step. .. GENERATED FROM PYTHON SOURCE LINES 235-242 .. code-block:: Python prim3D.create_polyline(points=[start_point, end_of_line_segment], segment_type=[ prim3D.polyline_segment(type="AngularArc", arc_angle="43.47deg", arc_center=arc_center_1), prim3D.polyline_segment(type="Line"), prim3D.polyline_segment(type="AngularArc", arc_angle=arc_angle_2, arc_center=arc_center_2), ], name="Compound_Polyline_One_Command") .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 243-248 Insert two 3-point arcs forming a circle and covered ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Insert two 3-point arcs forming a circle and covered. Note that the last point of the second arc segment is not defined in the position list. .. GENERATED FROM PYTHON SOURCE LINES 248-253 .. code-block:: Python P = prim3D.create_polyline( points=[[34.1004, 14.1248, 0], [27.646, 16.7984, 0], [24.9725, 10.3439, 0], [31.4269, 7.6704, 0]], segment_type=["Arc", "Arc"], cover_surface=True, close_surface=True, name="Rotor_Subtract_25_0", material="vacuum") .. GENERATED FROM PYTHON SOURCE LINES 254-259 Here is an example of a complex polyline where the number of points is insufficient to populate the requested segments. This results in an ``IndexError`` that PyAEDT catches silently. The return value of the command is ``False``, which can be caught at the app level. While this example might not be so useful in a Jupyter Notebook, it is important for unit tests. .. GENERATED FROM PYTHON SOURCE LINES 259-276 .. code-block:: Python MDL_points = [ ["67.1332mm", "2.9901mm", "0mm"], ["65.9357mm", "2.9116mm", "0mm"], ["65.9839mm", "1.4562mm", "0mm"], ["66mm", "0mm", "0mm"], ["99mm", "0mm", "0mm"], ["98.788mm", "6.4749mm", "0mm"], ["98.153mm", "12.9221mm", "0mm"], ["97.0977mm", "19.3139mm", "0mm"], ] MDL_segments = ["Line", "Arc", "Line", "Arc", "Line"] return_value = prim3D.create_polyline(MDL_points, segment_type=MDL_segments, name="MDL_Polyline") assert return_value # triggers an error at the application error .. GENERATED FROM PYTHON SOURCE LINES 277-279 Here is an example that provides more points than the segment list requires. This is valid usage. The remaining points are ignored. .. GENERATED FROM PYTHON SOURCE LINES 279-284 .. code-block:: Python MDL_segments = ["Line", "Arc", "Line", "Arc"] P = prim3D.create_polyline(MDL_points, segment_type=MDL_segments, name="MDL_Polyline") .. GENERATED FROM PYTHON SOURCE LINES 285-288 Save project ------------ Save the project. .. GENERATED FROM PYTHON SOURCE LINES 288-296 .. code-block:: Python project_dir = r"C:\temp" project_name = "Polylines" project_file = os.path.join(project_dir, project_name + ".aedt") M3D.save_project(project_file) M3D.release_desktop() .. rst-class:: sphx-glr-script-out .. code-block:: none True .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 56.360 seconds) .. _sphx_glr_download_examples_01-Modeling-Setup_Polyline_Primitives.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: Polyline_Primitives.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: Polyline_Primitives.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_