JMAG-Designer Geometry Editor has the function to draw ellipses and elliptical arcs as basic shapes.
An ellipse is defined by its center coordinates, the radii of the major and minor axes and the rotation angle of the major axis. The major angle is relative to a coordinate axis or a straight line.
This script creates an elliptical region shape.
Preconditions
- The center coordinates, major radius, minor radius and major angle of the ellipse are set using the equation.
Script Function
- Register variables for the ellipse's center coordinates, major radius, minor radius and major angle as equation parameters.
- Create a sketch on the XY plane.
- Create an ellipse by specifying the center coordinates, major radius and minor radius with the major angle set to 0.
- Create a horizontal line to define the major angle of the ellipse.
- Apply constraints.
Apply an angle constraint between the horizontal line and the ellipse to define the major angle of ellipse and assign variables.
Apply radius constraints to the major and minor axes and assign variables.
Constrain the center point by distances from the X-axis and Y-axis, assigning the corresponding center coordinate variables to these distances. - Create an elliptical region from the created ellipse.
# 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/
app = designer.GetApplication()
geomApp = app.CreateGeometryEditor()
geomDoc = geomApp.GetDocument()
# Dimensional parameters
EllipseCenterX = 0
EllipseCenterY = 0
EllipseMajorRadius = 100
EllipseMinorRadius = 50
EllipseMajorAngle = 0
# Equation names
EqCenterX = u"center_x"
EqCenterY = u"center_y"
EqMajorRadius = u"major_radius"
EqMinorRadius = u"minor_radius"
EqMajorAngle = u"major_angle"
def setupEquation(equation, expression):
"""Configure the basic settings for equations in DesignTable."""
# The argument of SetType
# 0: Value
# 1: Expression
equation.SetType(0)
equation.SetExpression(str(expression))
def createEllipseEquations():
"""Register the center coordinates, major radius, minor radius, and major-axis angle of the ellipse as equations."""
designTable = geomDoc.GetDesignTable()
equationDataList = [
(EqMajorRadius, EllipseMajorRadius),
(EqMinorRadius, EllipseMinorRadius),
(EqMajorAngle, EllipseMajorAngle),
(EqCenterX, EllipseCenterX),
(EqCenterY, EllipseCenterY),
]
designTable.EditStart()
for equationName, expression in equationDataList:
designTable.AddEquation(equationName)
equation = designTable.GetEquation(equationName)
setupEquation(equation, expression)
designTable.EditEnd()
def createSketchOnXYPlane():
"""Create a sketch on the XY plane."""
assm = geomDoc.GetAssembly()
refXYPlane = assm.GetPlaneXY()
sketch = assm.CreateSketch(refXYPlane)
return sketch
def createRegionFromItems(sketch, itemList):
"""Create a region on the sketch from all items in the argument's itemList."""
selection = geomDoc.GetSelection()
selection.Clear()
for item in itemList:
selection.Add(item)
sketch.CreateRegions()
selection.Clear()
def setConstraintExpression(constraint, propertyName, equationName):
"""Set an equation name to the specified constraint property."""
constraint.SetProperty(propertyName, equationName)
def getDistanceExpressionFromSignedValue(equationName, value):
"""Return a distance expression for a signed coordinate value."""
if value < 0:
return u"-" + equationName
return equationName
def drawBaseShapeForEllipse(sketch, majorRadius, minorRadius, majorAngle):
"""Create an ellipse and an angle reference line, apply constraints, and generate a region."""
sketch.OpenSketch()
# Ellipse
ellipse = sketch.CreateEllipse(
EllipseCenterX,
EllipseCenterY,
majorRadius,
minorRadius,
majorAngle
)
ellipseRef = geomDoc.CreateReferenceFromItem(ellipse)
# Center of the ellipse
centerVertex = ellipse.GetCenterVertex()
centerRef = geomDoc.CreateReferenceFromItem(centerVertex)
# Reference point used to define the major-axis direction
referencePointVertex = sketch.CreateVertex(
EllipseCenterX + majorRadius,
EllipseCenterY
)
referencePointRef = geomDoc.CreateReferenceFromItem(
referencePointVertex
)
# Horizontal reference line used to define the major-axis angle
referenceLine = sketch.CreateLine(
EllipseCenterX,
EllipseCenterY,
EllipseCenterX + majorRadius,
EllipseCenterY
)
referenceLineRef = geomDoc.CreateReferenceFromItem(referenceLine)
# Constrain the reference line to be horizontal
sketch.CreateMonoConstraint(
u"horizontality",
referenceLineRef
)
# Place the reference point on the ellipse
sketch.CreateBiConstraint(
u"coincident",
referencePointRef,
ellipseRef
)
# Constrain the angle between the reference line and the major axis of the ellipse using an equation
majorAngleConstraint = sketch.CreateBiConstraint(
u"angle",
referenceLineRef,
ellipseRef
)
setConstraintExpression(
majorAngleConstraint,
u"Angle",
EqMajorAngle
)
# Constrain the major radius of the ellipse using an equation
majorRadiusConstraint = sketch.CreateMonoConstraint(
u"major_radius",
ellipseRef
)
setConstraintExpression(
majorRadiusConstraint,
u"Radius",
EqMajorRadius
)
# Constrain the minor radius of the ellipse using an equation
minorRadiusConstraint = sketch.CreateMonoConstraint(
u"minor_radius",
ellipseRef
)
setConstraintExpression(
minorRadiusConstraint,
u"Radius",
EqMinorRadius
)
# Constrain the X position of the ellipse center using an equation
centerXConstraint = sketch.CreateMonoConstraint(
u"distancefromyaxis",
centerRef
)
centerXDistanceExpression = getDistanceExpressionFromSignedValue(
EqCenterX,
EllipseCenterX
)
setConstraintExpression(
centerXConstraint,
u"Distance",
centerXDistanceExpression
)
# Constrain the Y position of the ellipse center using an equation
centerYConstraint = sketch.CreateMonoConstraint(
u"distancefromxaxis",
centerRef
)
centerYDistanceExpression = getDistanceExpressionFromSignedValue(
EqCenterY,
EllipseCenterY
)
setConstraintExpression(
centerYConstraint,
u"Distance",
centerYDistanceExpression
)
# Create a region from the ellipse and its internal reference line
createRegionFromItems(
sketch,
[ellipse]
)
sketch.CloseSketch()
def createEllipseShape():
"""Create an ellipse with equations in the sketch."""
sketch = createSketchOnXYPlane()
drawBaseShapeForEllipse(
sketch,
EllipseMajorRadius,
EllipseMinorRadius,
EllipseMajorAngle
)
def main():
"""Create a two-dimensional ellipse with equations."""
createEllipseEquations()
createEllipseShape()
main()


