[S0002] Set the rotation motion condition to all parts within a specified radius from the origin

 

In magnetic field transient analysis, motion conditions are applied when there is time-dependent motion. In the analysis for rotating machines such as motors, parts within a certain radius from the center of rotation are typically rotating. This script does not specify each part individually by name, but instead identifies parts within a specified radius from the center of rotation, assuming an inner rotor, and sets the rotation motion conditions.

Preconditions

  • One or more magnetic field transient analysis studies must be created.
    This script is run for the first study of the first model in the project tree.
  • The rotation axis is the Z axis passing through the origin, and the model is an inner rotor type that parts within the specified radius are rotating.
  • The units of the setting values ​​follow the unit system set for the model.

Script Function

  • Identify parts in the model that are within the specified radius and create a Selection of picked up part IDs.
  • Create rotation motion condition and apply them to the previously created Selection.
  • Other parameters for the rotation motion condition in this example are: constant rotation speed is set to 600, initial position is set to 15, and the center of rotation is set to the origin.
# Copyright (c) 2026 JSOL CORPORATION
#
# This script is released under the MIT License.
# See the full license text at:
# https://www.jmag-international.com/scriptlibrary/jmag_script_library_mit/


import math

def selectPartsWithinRadius(targetModel, targetRadius):
    """Select all parts within the argument radius"""
    sel = targetModel.CreateSelection()
    numParts = targetModel.NumParts()
    for i in range(numParts):
        targetPart = targetModel.GetPartByIndex(i)
        # Get a position within a part
        pointInPart = targetPart.PointInPart()
        # Calculate the r component at the origin center of the above position
        rad = math.sqrt((pointInPart.GetX()**2)+(pointInPart.GetY()**2))
        if rad <= targetRadius:
            sel.SelectPart(targetPart.ID())
    return sel

def createMotionConditionOfInnerRotor(targetStudy, selectedTargets):
    """Create a rotation motion condition to the parts passed as the 2nd argument"""
    RotMotionCond = targetStudy.CreateCondition(u"RotationMotion", u"rotMotion")
    RotMotionCond.SetValue(u"MotionGroupType", u"ConstantVelocity")
    RotMotionCond.SetValue(u"AngularVelocity", 600)
    RotMotionCond.SetValue(u"InitialRotationAngleType", u"Manual")
    RotMotionCond.SetValue(u"InitialRotationAngle", 15)
    RotMotionCond.SetXYZPoint(u"Origin", 0, 0, 0)
    RotMotionCond.ClearParts()
    RotMotionCond.AddSelected(selectedTargets)


app = designer.GetApplication()

model = app.GetModel(0)
rad = 0.01175
sel = selectPartsWithinRadius(model, rad)
study = model.GetStudy(0)
createMotionConditionOfInnerRotor(study, sel)

Download Python source code

How to use script file

Use the JMAG Script Library after reading and agreeing to the following terms of use.

Search Filter

  • All Categories

An engineer's diary
JMAG-Express Online