|
| 1 | +# Copyright (C) 2022 - 2025 ANSYS, Inc. and/or its affiliates. |
| 2 | +# SPDX-License-Identifier: MIT |
| 3 | +# |
| 4 | +# |
| 5 | +# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 | +# of this software and associated documentation files (the "Software"), to deal |
| 7 | +# in the Software without restriction, including without limitation the rights |
| 8 | +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 | +# copies of the Software, and to permit persons to whom the Software is |
| 10 | +# furnished to do so, subject to the following conditions: |
| 11 | +# |
| 12 | +# The above copyright notice and this permission notice shall be included in all |
| 13 | +# copies or substantial portions of the Software. |
| 14 | +# |
| 15 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 18 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 20 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 21 | +# SOFTWARE. |
| 22 | + |
| 23 | +# Keywords: **Tapered Bar**, **Induction Motor**, **motor** |
| 24 | +""" |
| 25 | +Converting IM parallel tooth bar to tapered tooth bar |
| 26 | +========================================= |
| 27 | +
|
| 28 | +This script applies the adaptive templates functionality to change |
| 29 | +the points at the bottom of parallel tooth to create a tapered tooth bar geometry. |
| 30 | +""" |
| 31 | + |
| 32 | + |
| 33 | +import math |
| 34 | +import sys |
| 35 | + |
| 36 | +import ansys.motorcad.core as pymotorcad |
| 37 | +from ansys.motorcad.core.geometry import Coordinate, rt_to_xy, xy_to_rt |
| 38 | + |
| 39 | +# Connect to Motor-CAD, using existing instance |
| 40 | +# Alternatively, we could open a new instance and load a file with mc.load_from_file() |
| 41 | +mc = pymotorcad.MotorCAD() |
| 42 | + |
| 43 | +# Reset geometry to default |
| 44 | +mc.reset_adaptive_geometry() |
| 45 | + |
| 46 | +# Disable popup messages |
| 47 | +mc.set_variable("MessageDisplayState", 2) |
| 48 | + |
| 49 | + |
| 50 | +# function to return angle based on chord length |
| 51 | +# Used for finding new point based on tooth width at bottom of bar |
| 52 | +def chord_angle(cord_length, r): |
| 53 | + angle = 2 * math.asin(cord_length / (2 * r)) |
| 54 | + return angle * 180 / math.pi |
| 55 | + |
| 56 | + |
| 57 | +# Set IM motor type if not already |
| 58 | +if not pymotorcad.is_running_in_internal_scripting(): |
| 59 | + mc.load_template("i6a") |
| 60 | + |
| 61 | + |
| 62 | +# Get the bar region |
| 63 | +bar = mc.get_region("TopRotorBar") |
| 64 | + |
| 65 | +# Get the points at the bottom corners of bar |
| 66 | +# Point1 is away from x axis |
| 67 | +point1 = bar.points[3] |
| 68 | +point2 = bar.points[5] |
| 69 | + |
| 70 | +# Get the top bar tooth width |
| 71 | +# Define adaptive parameter for booth bar tooth width |
| 72 | +tooth_width_top = mc.get_variable("Rotor_Tooth_Width_T") |
| 73 | +mc.set_adaptive_parameter_default("Rotor Tooth Width Bottom", 4) |
| 74 | +tooth_width_bottom = mc.get_adaptive_parameter_value("Rotor Tooth Width Bottom") |
| 75 | + |
| 76 | +# Get the point 1 polar coordinates and modify |
| 77 | +point1_r, point_1_t = xy_to_rt(point1.x, point1.y) |
| 78 | +chord_length = (tooth_width_top - tooth_width_bottom) / 2 |
| 79 | +del_angle = chord_angle(chord_length, point1_r) |
| 80 | +point1_t_new = point_1_t + del_angle |
| 81 | + |
| 82 | +# Get the point 2 polar coordinates and modify |
| 83 | +point2_r, point_2_t = xy_to_rt(point2.x, point2.y) |
| 84 | +chord_length = (tooth_width_top - tooth_width_bottom) / 2 |
| 85 | +del_angle = chord_angle(chord_length, point2_r) |
| 86 | +point_2_t_new = point_2_t - del_angle |
| 87 | + |
| 88 | +# Get new region coordinates |
| 89 | +x, y = rt_to_xy(point1_r, point1_t_new) |
| 90 | +point1_new = Coordinate(x, y) |
| 91 | +x, y = rt_to_xy(point2_r, point_2_t_new) |
| 92 | +point2_new = Coordinate(x, y) |
| 93 | + |
| 94 | +# Edit points at the bottom of the bar |
| 95 | +bar.edit_point(point1, point1_new) |
| 96 | +bar.edit_point(point2, point2_new) |
| 97 | + |
| 98 | +# Set corner rounding if needed |
| 99 | +bar.round_corner(point1_new, 0.2) |
| 100 | +bar.round_corner(point2_new, 0.2) |
| 101 | + |
| 102 | +# Set new region |
| 103 | +mc.set_region(bar) |
| 104 | + |
| 105 | +# If we're running this externally, load adaptive template script into Motor-CAD |
| 106 | +if not pymotorcad.is_running_in_internal_scripting(): |
| 107 | + mc.set_variable("GeometryTemplateType", 1) |
| 108 | + mc.load_adaptive_script(sys.argv[0]) |
0 commit comments