# 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 ShellWidth = 100 ShellHeight = 100 ShellStartX = 0 ShellStartY = 0 ShellStartZ = 0 # Equation names EqWidth = u"width" EqHeight = u"height" EqStartX = u"start_x" EqStartY = u"start_y" EqStartZ = u"start_z" def createNewPart(): """Create a new Part and open it in edit mode.""" assm = geomDoc.GetAssembly() part = assm.CreatePart() part.OpenPart() return part 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 createShellEquations(): """Register the width, height, and start coordinates of the shell as equations.""" designTable = geomDoc.GetDesignTable() equationDataList = [ (EqWidth, ShellWidth), (EqHeight, ShellHeight), (EqStartX, ShellStartX), (EqStartY, ShellStartY), (EqStartZ, ShellStartZ), ] designTable.EditStart() for equationName, expression in equationDataList: designTable.AddEquation(equationName) equation = designTable.GetEquation(equationName) setupEquation(equation, expression) designTable.EditEnd() def createOffsetZXPlane(part): """Create a ZX plane offset by start_y.""" refZXPlane = part.GetPlaneZX() offsetPlane = part.CreateReferencePlane() offsetPlane.SetTypeByString(u"Distance") offsetPlane.SetPropertyByReference(u"Plane", refZXPlane) offsetPlane.SetProperty(u"Distance", EqStartY) return offsetPlane def createSketchOnShellPlane(part): """Create a sketch on the ZX plane offset by start_y.""" offsetPlane = createOffsetZXPlane(part) offsetPlaneRef = geomDoc.CreateReferenceFromItem(offsetPlane) sketch = part.CreateSketch(offsetPlaneRef) return sketch 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 drawBaseShapeForShell(sketch, width): """Create a line used as the basis of the shell and constrain its dimensions and position.""" sketch.OpenSketch() # In a sketch on the ZX plane, the sketch X direction is treated as the Z direction and the sketch Y direction is treated as the X direction. sketchStartX = ShellStartZ sketchStartY = ShellStartX # Line representing the width of the shell startVertex = sketch.CreateVertex(sketchStartX, sketchStartY) endVertex = sketch.CreateVertex(sketchStartX, sketchStartY + width) startRef = geomDoc.CreateReferenceFromItem(startVertex) endRef = geomDoc.CreateReferenceFromItem(endVertex) widthLine = sketch.CreateLine( sketchStartX, sketchStartY, sketchStartX, sketchStartY + width ) widthLineRef = geomDoc.CreateReferenceFromItem(widthLine) sketch.CreateMonoConstraint(u"verticality", widthLineRef) # Constrain the length of the line using an equation. widthConstraint = sketch.CreateBiConstraint(u"distance", startRef, endRef) setConstraintExpression(widthConstraint, u"Distance", EqWidth) # Constrain the X position of the start point using an equation. startXConstraint = sketch.CreateMonoConstraint(u"distancefromxaxis", startRef) startXDistanceExpression = getDistanceExpressionFromSignedValue(EqStartX, ShellStartX) setConstraintExpression(startXConstraint, u"Distance", startXDistanceExpression) # Constrain the Z position of the line using an equation. startZConstraint = sketch.CreateMonoConstraint(u"distancefromyaxis", startRef) startZDistanceExpression = getDistanceExpressionFromSignedValue(EqStartZ, ShellStartZ) setConstraintExpression(startZConstraint, u"Distance", startZDistanceExpression) sketch.CloseSketch() def createShellByExtrude(part, sketch): """Create a rectangular shell by extruding the line in the Y-axis direction.""" extrudeSurface = part.CreateExtrudeSurface(sketch) extrudeSurface.SetTypeByName(u"OneSide") extrudeSurface.SetReverse(False) extrudeSurface.SetProperty(u"Height", EqHeight) return extrudeSurface def createShellPart(part): """Create a shell with equations in the specified Part.""" sketch = createSketchOnShellPlane(part) drawBaseShapeForShell(sketch, ShellWidth) createShellByExtrude(part, sketch) def main(): """Create a Part containing a shell with equations.""" createShellEquations() part = createNewPart() createShellPart(part) part.ClosePart() main()