### Install and Install pre-commit Hooks Source: https://github.com/ansys/pymotorcad/blob/main/README.rst Install pre-commit to enforce coding style. This command installs the tool and then sets up the git hooks. ```bash python -m pip install pre-commit && pre-commit install ``` -------------------------------- ### Clone and Install PyMotorCAD in Development Mode Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/contributing.rst Clone the repository and install PyMotorCAD with development and documentation dependencies. This setup is for contributing to the library. ```console git clone https://github.com/ansys/pymotorcad cd pymotorcad pip install --editable .[tests,doc] ``` -------------------------------- ### Verify Development Installation Source: https://github.com/ansys/pymotorcad/blob/main/README.rst Run this command to verify your development installation. ```bash ``` -------------------------------- ### Install Build System and Tools Source: https://github.com/ansys/pymotorcad/blob/main/README.rst Install the latest required build system and documentation, testing, and CI tools. ```bash python -m pip install -U pip tox ``` -------------------------------- ### Install and Run Pre-commit for Code Style Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/contributing.rst Install the pre-commit tool to enforce code style. Run pre-commit to check all files or install it as a hook to automatically check code before committing. ```console pip install pre-commit pre-commit run --all-files ``` ```console pre-commit install ``` -------------------------------- ### Install Project in Editable Mode Source: https://github.com/ansys/pymotorcad/blob/main/README.rst Install the project in editable mode with test and documentation dependencies. ```bash python -m pip install --editable .[tests,doc] ``` -------------------------------- ### Launch Motor-CAD Locally with PyAnsys Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/getting_started/running_motorcad.rst Use this method to start a new instance of Motor-CAD and automatically connect to it from Python. Ensure you have a local Ansys license server installed. ```pycon >>> import ansys.motorcad.core as pymotorcad >>> mcApp = pymotorcad.MotorCAD() ``` -------------------------------- ### Prepare for Distribution Source: https://github.com/ansys/pymotorcad/blob/main/README.rst Installs the latest pip, builds source and wheel distribution files, and checks the distribution files for errors. ```bash python -m pip install -U pip ``` ```bash python -m build ``` ```bash python -m twine check dist/* ``` -------------------------------- ### Install PyMotorCAD (User Mode) Source: https://github.com/ansys/pymotorcad/blob/main/README.rst Install the PyMotorCAD package for general use. ```bash python -m pip install ansys-motorcad-core ``` -------------------------------- ### Install PyMotorCAD from PyPI Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/getting_started/index.rst Use this command to install the latest stable release of the PyMotorCAD package from the Python Package Index. ```console pip install ansys-motorcad-core ``` -------------------------------- ### Install PyMotorCAD from GitHub Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/getting_started/index.rst Install the latest version of PyMotorCAD directly from its GitHub repository. This is useful for accessing the most recent features or development versions. ```console pip install git+https://github.com/ansys/pymotorcad.git ``` -------------------------------- ### Check Python Version Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/user_guide/virtual_env_motorcad.rst Verify the installed Python version in your terminal before creating a virtual environment. ```console python --version ``` -------------------------------- ### Install Packages in Virtual Environment Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/user_guide/virtual_env_motorcad.rst Install necessary Python packages, such as Motor-CAD core libraries and dependencies, into the active virtual environment using pip. ```console pip install ansys.motorcad.core bezier numpy ``` -------------------------------- ### Install PyMotorCAD for Local Development Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/getting_started/index.rst Install PyMotorCAD in editable mode for local development. This allows you to modify the source code and have changes reflected immediately after restarting the Python kernel. ```console git clone https://github.com/ansys/pymotorcad.git cd pymotorcad pip install -e . ``` -------------------------------- ### Get Variable using ActiveX syntax Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/user_guide/backwards_compatibility.rst Illustrates the function call for retrieving a variable in an old ActiveX script. ```python McApp.GetVariable() ``` -------------------------------- ### Get Variable using PyMotorCAD syntax Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/user_guide/backwards_compatibility.rst Demonstrates the snake_case equivalent for getting a variable in PyMotorCAD. ```python mcApp.get_variable() ``` -------------------------------- ### Verify PyMotorCAD Installation Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/getting_started/index.rst Run this Python code to check if PyMotorCAD can successfully launch an instance of Ansys Motor-CAD. A successful execution will open Motor-CAD on your taskbar. ```python import ansys.motorcad.core as pymotorcad mcApp = pymotorcad.MotorCAD() ``` -------------------------------- ### Update Pip Source: https://github.com/ansys/pymotorcad/blob/main/README.rst Ensure you have the latest version of pip before installing PyMotorCAD. ```bash python -m pip install -U pip ``` -------------------------------- ### MATLAB script for E-magnetic scripting in Motor-CAD Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/user_guide/matlab_scripting.rst An example MATLAB script demonstrating how to control Motor-CAD for E-magnetic analysis. It covers setting motor geometry, materials, calculation preferences, running calculations, and preparing for data retrieval. ```matlab % Use pymotorcad as an alias to access functionality in ansys.motorcad.core pymotorcad = py.importlib.import_module('ansys.motorcad.core'); % Launch an instance of Motor-CAD mcApp = pymotorcad.MotorCAD(); % Turn off popups mcApp.set_variable('MessageDisplayState', 2) % Change tab to scripting so that there are no conflicts when changing % variables mcApp.show_magnetic_context() mcApp.display_screen('scripting') % change to default BPM motor mcApp.set_variable('Motor_Type', 0) % Geometry changes mcApp.set_variable('Slot_Number', 24) mcApp.set_variable('Tooth_Width', 6) mcApp.set_variable('Magnet_Thickness', 4.5) % Coil changes mcApp.set_variable('MagPhases',3); mcApp.set_variable('ParallelPaths',1); mcApp.set_variable('WindingLayers',2); mcApp.set_variable('MagWindingType',1); mcApp.set_variable('MagPathType',1); mcApp.set_winding_coil(int64(2), int64(1), int64(3), int64(4), 'b', int64(18), 'a', int64(60)); % Material changes mcApp.set_component_material('Stator Lam (Back Iron)', 'M250-35A') mcApp.set_component_material('Rotor Lam (Back Iron)', 'M250-35A') % Set calculation preferences PointsPerCycle = 30; NumberCycles = 1; mcApp.set_variable('TorquePointsPerCycle', PointsPerCycle); mcApp.set_variable('TorqueNumberCycles', NumberCycles); % Turn off performance tests mcApp.set_variable('BackEMFCalculation', false); mcApp.set_variable('CoggingTorqueCalculation', false); mcApp.set_variable('ElectromagneticForcesCalc_OC', false); mcApp.set_variable('TorqueSpeedCalculation', false); mcApp.set_variable('DemagnetizationCalc', false); mcApp.set_variable('ElectromagneticForcesCalc_Load', false); mcApp.set_variable('InductanceCalc', false); mcApp.set_variable('BPMShortCircuitCalc', false); % Enable transient torque mcApp.set_variable('TorqueCalculation', true); % Emangetic calculation settings mcApp.set_variable('Shaft_Speed_[RPM]', 1000); mcApp.set_variable('CurrentDefinition', 0); mcApp.set_variable('PeakCurrent', 3); mcApp.set_variable('DCBusVoltage', 350); mcApp.set_variable('PhaseAdvance', 45); % Save file and calculate mcApp.save_to_file('C:\ANSYS_Motor-CAD\2023_1_1\Motor-CAD Data\MATLAB_Tutorial\automation_scripting_MATLAB_EMagnetic.mot'); mcApp.do_magnetic_calculation() % data retrieval and export ``` -------------------------------- ### Get Variable with success check in ActiveX Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/user_guide/backwards_compatibility.rst Shows how ActiveX scripts handled API call success by checking a 'success' variable. ```python success, VariableValue = mcApp.GetVariable("Not_A_Real_Var") ``` -------------------------------- ### Reset Adaptive Geometry Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/user_guide/adaptive_templates.rst Ensure this method is called before getting or setting any Motor-CAD geometry within an Adaptive Template script. ```python mc.reset_adaptive_geometry() ``` -------------------------------- ### Get Adaptive Parameter Value Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/user_guide/adaptive_templates.rst Retrieve the current value of an Adaptive Parameter using get_adaptive_parameter_value(). This is useful for dynamically defining geometry based on parameter values. ```python number_notches = int(mc.get_adaptive_parameter_value("Notches per Pole")) ``` -------------------------------- ### Get Motor-CAD Variable Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/user_guide/adaptive_templates.rst Retrieve any Motor-CAD variable using get_variable(). This is useful for accessing parameters like rotor radius for geometry modifications. ```python rotor_radius = mc.get_variable("RotorDiameter") / 2 ``` -------------------------------- ### Get Variable without success check in PyMotorCAD Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/user_guide/backwards_compatibility.rst PyMotorCAD simplifies API calls by raising exceptions on failure, removing the need for a manual success check. ```python variable_value = mcApp.get_variable("Not_A_Real_Var") ``` -------------------------------- ### Build Documentation with Sphinx Makefile Source: https://github.com/ansys/pymotorcad/blob/main/README.rst Builds the HTML documentation using Sphinx and opens the index file in the browser. This is an alternative to the tox method. ```bash make -C doc/ html && your_browser_name doc/html/index.html ``` -------------------------------- ### Build Documentation with Tox Source: https://github.com/ansys/pymotorcad/blob/main/README.rst Builds the documentation using tox and opens the index file from the tox output directory in the browser. This is the recommended method for checking documentation integrity. ```bash tox -e doc && your_browser_name .tox/doc_out/index.html ``` -------------------------------- ### Create and Activate Virtual Environment (POSIX) Source: https://github.com/ansys/pymotorcad/blob/main/README.rst Create and activate a Python virtual environment for development on POSIX systems. ```bash # Create a virtual environment python -m venv .venv # Activate it in a POSIX system source .venv/bin/activate ``` -------------------------------- ### Create and Activate Virtual Environment (Windows CMD) Source: https://github.com/ansys/pymotorcad/blob/main/README.rst Create and activate a Python virtual environment for development on Windows CMD. ```bash # Create a virtual environment python -m venv .venv # Activate it in Windows CMD environment .venv\Scripts\activate.bat ``` -------------------------------- ### Create and Activate Virtual Environment (Windows Powershell) Source: https://github.com/ansys/pymotorcad/blob/main/README.rst Create and activate a Python virtual environment for development on Windows Powershell. ```bash # Create a virtual environment python -m venv .venv # Activate it in Windows Powershell .venv\Scripts\Activate.ps1 ``` -------------------------------- ### Connect to Motor-CAD Instance Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/user_guide/adaptive_templates.rst When working with Adaptive Templates scripts, use the 'open_new_instance=False' option to connect to an existing Motor-CAD instance. This allows scripts run from an IDE to communicate with the open Motor-CAD application. ```python mc = pymotorcad.MotorCAD(open_new_instance=False) ``` -------------------------------- ### Activate Virtual Environment (Command Prompt) Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/user_guide/virtual_env_motorcad.rst Activate the created virtual environment using the Windows Command Prompt. This command must be run in the terminal. ```cmd .\virtual_environment_folder_location\Scripts\activate.bat ``` -------------------------------- ### Demo Function for Thermal Analysis Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/user_guide/internal_scripting.rst This function demonstrates setting a variable, running a steady-state thermal analysis, and retrieving results. It also shows how to control message display. ```python def demo_func(): array_tooth_widths = [1, 1.5, 2.0] mcApp.set_variable("MessageDisplayState", 2) for toothWidth in array_tooth_widths: mcApp.show_message("Tooth width = " + str(toothWidth)) mcApp.set_variable("Tooth_Width", toothWidth) mcApp.do_steady_state_analysis() temperature = mcApp.get_variable( "T_[WINDING_AVERAGE]", ) mcApp.show_message("Winding temperature = " + str(temperature)) mcApp.set_variable("MessageDisplayState", 0) ``` -------------------------------- ### Connect to Motor-CAD Instance Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/user_guide/internal_scripting.rst Import the PyMotorCAD library and instantiate the MotorCAD() object to connect to the current Motor-CAD instance from an internal script. ```python import ansys.motorcad.core as pymotorcad mcApp = pymotorcad.MotorCAD() ``` -------------------------------- ### Activate Virtual Environment (PowerShell) Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/user_guide/virtual_env_motorcad.rst Activate the created virtual environment using PowerShell. This command must be run in the terminal. ```powershell .\virtual_environment_folder_location\Scripts\activate.ps1 ``` -------------------------------- ### Create Python Virtual Environment Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/user_guide/virtual_env_motorcad.rst Create a new Python virtual environment in a specified folder. This isolates project dependencies. ```console python -m venv virtual_environment_folder_location ``` -------------------------------- ### Launch Motor-CAD instance in MATLAB Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/user_guide/matlab_scripting.rst Instantiate the MotorCAD object from the imported pymotorcad module to establish a connection with a Motor-CAD application. ```matlab mcApp = pymotorcad.MotorCAD(); ``` -------------------------------- ### Clone PyMotorCAD Repository Source: https://github.com/ansys/pymotorcad/blob/main/README.rst Clone the PyMotorCAD repository to set up a development environment. ```bash git clone https://github.com/ansys/pymotorcad cd pymotorcad ``` -------------------------------- ### Import Geometry Library Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/user_guide/adaptive_templates.rst Import the entire ansys.motorcad.core.geometry library for use in adaptive scripts. ```python import ansys.motorcad.core.geometry as geometry ``` -------------------------------- ### Connect to Motor-CAD using ActiveX Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/user_guide/backwards_compatibility.rst This code demonstrates the traditional method of connecting to Motor-CAD using ActiveX. ```python import win32com.client mcApp = win32com.client.Dispatch("MotorCAD.AppAutomation") ``` -------------------------------- ### Import PyMotorCAD Library Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/user_guide/internal_scripting.rst Import the PyMotorCAD library to access Motor-CAD functionalities within your scripts. ```python import ansys.motorcad.core as pymotorcad ``` -------------------------------- ### Thermal Steady Class Definition Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/user_guide/internal_scripting.rst Defines the 'thermal_steady' class, which includes 'initial' and 'main' functions for managing steady-state thermal calculations. The 'initial' function sets up a step counter. ```python class thermal_steady: def initial(self): self.step = 0 print("Thermal Steady State - Initial") def main(self): self.step = self.step + 1 ``` -------------------------------- ### Import Triangular Notch Function Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/user_guide/adaptive_templates.rst Import the triangular_notch function from the ansys.motorcad.core.geometry_shapes library. ```python from ansys.motorcad.core.geometry_shapes import triangular_notch ``` -------------------------------- ### Thermal Steady State Class Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/user_guide/internal_scripting.rst Defines initial, main, and final functions for thermal steady-state calculations. ```python class thermal_steady_state: def initial(self): print("Thermal Steady State - Initial") def main(self): self.step = self.step + 1 print("Step: " + str(self.step) + ". Thermal Steady State - Main") def final(self): print("Thermal Steady State - Final") ``` -------------------------------- ### Import PyMotorCAD module in MATLAB Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/user_guide/matlab_scripting.rst Import the ansys.motorcad.core package into MATLAB to make its functionalities available under the 'pymotorcad' alias. ```matlab pymotorcad = py.importlib.import_module('ansys.motorcad.core'); ``` -------------------------------- ### Display Motor-CAD Screen and Extract Harmonic Data in MATLAB Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/user_guide/matlab_scripting.rst Initializes tab names, displays a specific screen in Motor-CAD, and then iterates through harmonic data points for a cycle. Requires 'PointsPerCycle' and 'NumberCycles' to be defined. ```matlab mcApp.initialise_tab_names(); mcApp.display_screen('Graphs;Harmonics;Torque'); NumHarmonicPoints = (PointsPerCycle * NumberCycles)+1 ; for loop = 0:NumHarmonicPoints - 1 params = mcApp.get_magnetic_graph_point('HarmonicDataCycle',int64(loop)); params = double(params); x = params(1); y = params(2); Datapoint(loop+1) = x; Torque(loop+1) = y; end ``` -------------------------------- ### Thermal Transient Class Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/user_guide/internal_scripting.rst Defines initial, main, and final functions for transient thermal calculations. ```python class thermal_transient: def initial(self): self.step = 0 print("Thermal Transient - Initial") def main(self): self.step = self.step + 1 print("Step: " + str(self.step) + ". Thermal Transient State - Main") def final(self): print("Thermal Transient - Final") ``` -------------------------------- ### Main Function for Script Execution Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/user_guide/internal_scripting.rst The 'main' function is executed when 'Run' is pressed in the Motor-CAD GUI. It can be used to test other functions or initiate calculations. ```python def main(): user_func = thermal_steady() user_func.initial() demo_func() ``` -------------------------------- ### Extract Air Gap Flux Density Data in MATLAB Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/user_guide/matlab_scripting.rst Continuously retrieves 'B Gap (on load)' data points until an error occurs, indicating the end of the data. Uses a while loop with a try-catch block. ```matlab loop = 0; success = 0; while true try params = mcApp.get_fea_graph_point('B Gap (on load)', int64(1), int64(loop), int64(0)); params = double(params); x = params(1); y = params(2); MechAngle(loop+1) = x; AirgapFluxDensity(loop+1) = y; loop = loop + 1; catch break end end ``` -------------------------------- ### set_motorcad_exe Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/methods/utility_functions.rst Specifies the path to the MotorCAD executable. ```APIDOC ## set_motorcad_exe ### Description Specifies the path to the MotorCAD executable. ### Method `set_motorcad_exe(motorcad_exe_path: str)` ### Parameters #### Path Parameters - **motorcad_exe_path** (str) - Required - The full path to the MotorCAD executable. ``` -------------------------------- ### set_server_ip Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/methods/utility_functions.rst Configures the IP address of the MotorCAD server. ```APIDOC ## set_server_ip ### Description Configures the IP address of the MotorCAD server. ### Method `set_server_ip(ip_address: str)` ### Parameters #### Path Parameters - **ip_address** (str) - Required - The IP address of the MotorCAD server. ``` -------------------------------- ### Iterate and Extract Torque Data in MATLAB Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/user_guide/matlab_scripting.rst Loops through torque data points for a cycle and stores them. Requires 'PointsPerCycle' and 'NumberCycles' to be defined. ```matlab NumTorquePoints = (PointsPerCycle * NumberCycles) + 1; for loop = 0:NumTorquePoints-1 params = mcApp.get_magnetic_graph_point('TorqueVW', int64(loop)); params = double(params); x = params(1); y = params(2); RotorPosition(loop+1) = x; TorqueVW(loop+1) = y; end ``` -------------------------------- ### Connect to Motor-CAD and Edit Region Properties Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/user_guide/adaptive_templates.rst Connect to an active Motor-CAD session, retrieve a specific region object (e.g., 'Rotor'), and modify its properties like color. This demonstrates basic interaction with Motor-CAD geometry via PyMotorCAD. ```python # Connect to Motor-CAD mc = pymotorcad.MotorCAD() # Get rotor region from Motor-CAD rotor = mc.get_region("Rotor") # Edit region properties rotor.colour = (186, 85, 211) ``` -------------------------------- ### Create Triangular Rotor Notch Region Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/user_guide/adaptive_templates.rst Create a triangular rotor notch region using the triangular_notch() function with calculated parameters. ```python notch = triangular_notch( rotor_radius, notch_angular_width, notch_centre_angle, notch_depth ) ``` -------------------------------- ### Set Default Adaptive Parameter Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/user_guide/adaptive_templates.rst Define an Adaptive Parameter with a default value using set_adaptive_parameter_default(). This method creates the parameter if it doesn't exist, otherwise it keeps the existing value. ```python mc.set_adaptive_parameter_default("Notches per Pole", 2) ``` -------------------------------- ### Set Region Properties Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/user_guide/adaptive_templates.rst Set properties like name, color, and material for a region object. ```python notch.name = "Rotor_Notch_1" notch.colour = (255, 255, 255) notch.material = "Air" ``` -------------------------------- ### get_bezier_points Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/methods/geometry_functions.rst Retrieves control points for a Bezier curve. ```APIDOC ## get_bezier_points ### Description Retrieves control points for a Bezier curve. ### Method (Not specified in source) ### Endpoint (Not specified in source) ### Parameters (Not specified in source) ### Request Example (Not specified in source) ### Response #### Success Response (200) (Not specified in source) #### Response Example (Not specified in source) ``` -------------------------------- ### Check Python environment in MATLAB Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/user_guide/matlab_scripting.rst Verify the Python version MATLAB is configured to use. This is essential before attempting to use Python packages like PyMotorCAD. ```matlab pe = pyenv; pe.Version ``` -------------------------------- ### Set Region Duplications and Parent Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/user_guide/adaptive_templates.rst Assign symmetry properties and set a parent region for a sub-region. ```python notch.duplications = rotor_region.duplications notch.parent = rotor_region ``` -------------------------------- ### Connect to Motor-CAD using PyMotorCAD Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/user_guide/backwards_compatibility.rst This code shows the PyMotorCAD equivalent for connecting to Motor-CAD, ensuring compatibility with older scripts. ```python import ansys.motorcad.core as pymotorcad mcApp = pymotorcad.MotorCADCompatibility() ``` -------------------------------- ### set_default_instance Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/methods/utility_functions.rst Sets the default MotorCAD instance to use for subsequent operations. ```APIDOC ## set_default_instance ### Description Sets the default MotorCAD instance to use for subsequent operations. ### Method `set_default_instance(instance_number: int)` ### Parameters #### Path Parameters - **instance_number** (int) - Required - The number of the MotorCAD instance to set as default. ``` -------------------------------- ### Display Scripting Tab in Motor-CAD Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/user_guide/troubleshooting.rst Use this command to switch the Motor-CAD UI to the Scripting tab. This is recommended when changing parameters via automation to ensure the UI does not interfere. ```python mcApp.display_screen("scripting") ``` -------------------------------- ### Import Geometry Drawing Function Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/user_guide/adaptive_templates.rst Import the 'draw_objects' function from the 'ansys.motorcad.core.geometry_drawing' module to plot geometry objects and regions. ```python from ansys.motorcad.core.geometry_drawing import draw_objects ``` -------------------------------- ### E-Magnetic Class Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/user_guide/internal_scripting.rst Defines initial and final functions for E-Magnetic calculations. ```python class emagnetic: def initial(self): print("E-Magnetic - Initial") def final(self): print("E-Magnetic - Final") ``` -------------------------------- ### Import Specific Geometry Functions Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/user_guide/adaptive_templates.rst Import specific functions like Line and Arc from the ansys.motorcad.core.geometry package. ```python from ansys.motorcad.core.geometry import Line, Arc ``` -------------------------------- ### Mechanical Stress Class Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/user_guide/internal_scripting.rst Defines initial and final functions for Mechanical stress calculations. ```python class mechanical_stress: def initial(self): print("Mech Stress - Initial") def final(self): print("Mech Stress - Final") ``` -------------------------------- ### Read graph points with exception handling Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/user_guide/backwards_compatibility.rst This script demonstrates robust API usage in PyMotorCAD by wrapping potentially failing calls in a try/except block to catch MotorCADError. ```python import ansys.motorcad.core as pymotorcad from ansys.motorcad.core import MotorCADError mcApp = pymotorcad.MotorCAD() mcApp.do_magnetic_calculation() i = 0 torque = [] reading_graph = True while reading_graph is True: try: x, y = mcApp.get_magnetic_graph_point("TorqueVW", i) torque.append(y) i = i + 1 except MotorCADError: reading_graph = False ``` -------------------------------- ### Modify and Round Duct Corners with Adaptive Templates Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/user_guide/adaptive_templates.rst Use Region.edit_point to modify duct geometry into a trapezoid, then Region.round_corners to apply a uniform radius to all corners. Finally, set the modified region in Motor-CAD. ```python duct_region.edit_point(entity.start, new_start_point) duct_region.edit_point(entity.end, new_end_point) draw_objects(duct_region, label_regions=True, draw_points=True) duct_region.round_corners(duct_region.points, 1.5) draw_objects(duct_region, label_regions=True, draw_points=True) mc.set_region(duct_region) ``` -------------------------------- ### Draw Geometry Regions with Labels and Points Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/user_guide/adaptive_templates.rst Use the 'draw_objects' function to plot defined geometry regions. Options 'label_regions=True' and 'draw_points=True' can be used to display region labels and points, respectively. This is particularly useful for debugging scripts in an external IDE. ```python draw_objects(pockets_all_layers, label_regions=True, draw_points=True) ``` -------------------------------- ### Export EMagnetic Results in MATLAB Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/user_guide/matlab_scripting.rst Exports electromagnetic results to a CSV file. Ensure the file path is correct. ```matlab mcApp.export_results('EMagnetic','C:\ANSYS_Motor-CAD\2023_1_1\Motor-CAD Data\MATLAB_Tutorial\automation_scripting_MATLAB_EMagnetic\Export EMag Results.csv'); ``` -------------------------------- ### Create New Region Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/user_guide/adaptive_templates.rst Create a new region to represent a geometry feature, such as a notch, using the Region object and specifying the appropriate RegionType. ```python from ansys.motorcad.core.geometry import Region, RegionType notch = Region(region_type=RegionType.rotor_air) ``` -------------------------------- ### Mechanical Forces Class Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/user_guide/internal_scripting.rst Defines initial and final functions for Mechanical force calculations. ```python class mechanical_forces: def initial(self): print("Mech Forces - Initial") def final(self): print("Mech Forces - Final") ``` -------------------------------- ### Add Entities to a Region Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/user_guide/adaptive_templates.rst Add Line and Arc entities to a region in anticlockwise order using the add_entity() function. ```python notch.add_entity(line_1) notch.add_entity(line_2) notch.add_entity(airgap_arc) ``` -------------------------------- ### Retrieve Motor-CAD Variables in MATLAB Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/user_guide/matlab_scripting.rst Retrieves specific variable values from Motor-CAD. Use exact variable names. ```matlab ShaftTorque = mcApp.get_variable('ShaftTorque'); LineVoltage = mcApp.get_variable('PeakLineLineVoltage'); ``` -------------------------------- ### Quit Motor-CAD Application in MATLAB Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/user_guide/matlab_scripting.rst Closes the Motor-CAD application. This should typically be the last command in a script. ```matlab mcApp.quit(); ``` -------------------------------- ### Retrieve Motor-CAD Messages Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/user_guide/troubleshooting.rst Fetch messages from Motor-CAD's history. Specify the number of messages to retrieve. A value of 0 retrieves all messages. ```python num_messages = 100 messages = mcApp.get_messages(num_messages) ``` -------------------------------- ### Modify Wedge Region by Subtracting Stator Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/user_guide/adaptive_templates.rst Subtracts a modified stator region from the wedge region to customize the stator slot geometry. Ensure the `wedge` and `modified_stator` objects are correctly defined before use. ```python wedge = mc.get_region("Wedge") wedge.subtract(modified_stator) mc.set_region(wedge) ``` -------------------------------- ### xy_to_rt Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/methods/geometry_functions.rst Converts Cartesian coordinates (x, y) to polar coordinates (r, theta). ```APIDOC ## xy_to_rt ### Description Converts Cartesian coordinates (x, y) to polar coordinates (r, theta). ### Method (Not specified in source) ### Endpoint (Not specified in source) ### Parameters (Not specified in source) ### Request Example (Not specified in source) ### Response #### Success Response (200) (Not specified in source) #### Response Example (Not specified in source) ``` -------------------------------- ### Disable Motor-CAD Pop-up Messages Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/user_guide/troubleshooting.rst Set the 'MessageDisplayState' variable to 2 to disable all pop-up messages in Motor-CAD. Be aware that this also disables crucial prompts like saving or overwriting data. ```python mcApp.set_variable("MessageDisplayState", 2) ``` -------------------------------- ### Set Region in Motor-CAD Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/user_guide/adaptive_templates.rst Check if a region is closed and then set it in the Motor-CAD model using set_region(). ```python if notch.is_closed(): mc.set_region(notch) ``` -------------------------------- ### rt_to_xy Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/methods/geometry_functions.rst Converts polar coordinates (r, theta) to Cartesian coordinates (x, y). ```APIDOC ## rt_to_xy ### Description Converts polar coordinates (r, theta) to Cartesian coordinates (x, y). ### Method (Not specified in source) ### Endpoint (Not specified in source) ### Parameters (Not specified in source) ### Request Example (Not specified in source) ### Response #### Success Response (200) (Not specified in source) #### Response Example (Not specified in source) ``` -------------------------------- ### get_entities_have_common_coordinate Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/methods/geometry_functions.rst Retrieves entities that share a common coordinate. ```APIDOC ## get_entities_have_common_coordinate ### Description Retrieves entities that share a common coordinate. ### Method (Not specified in source) ### Endpoint (Not specified in source) ### Parameters (Not specified in source) ### Request Example (Not specified in source) ### Response #### Success Response (200) (Not specified in source) #### Response Example (Not specified in source) ``` -------------------------------- ### Clear Motor-CAD Message Log Source: https://github.com/ansys/pymotorcad/blob/main/doc/source/user_guide/troubleshooting.rst Clear the message history log in Motor-CAD. This is useful after retrieving messages to simplify future calls to get_messages. ```python mcApp.clear_message_log() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.