# 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()