A beam shape is a linear solid with no volume.
In analysis, it can be used for structural analysis or as a conductor in magnetic field analysis.
In the Geometry Editor, basic shapes in a sketch can be converted into beams.
This script creates a straight beam.
Preconditions
- The start coordinates and length of the beam are set using the equation.
Script Function
- Register variables for the beam's start coordinates and length as equation parameters.
- Create a reference plane offset from the XY plane along the Z-axis and create a sketch on this plane.
Set the variable representing the Z-coordinate of the start to the Z-axis offset distance. - Create a straight line on the XY plane representing the beam length based on the specified start position and apply constraints.
- Make beam from the created line to create a beam shape.
# 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
BeamLength = 100
BeamStartX = 0
BeamStartY = 0
BeamStartZ = 0
# Equation names
EqLength = u"length"
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 createBeamEquations():
"""Register the start coordinates and length of the beam as equations."""
designTable = geomDoc.GetDesignTable()
equationDataList = [
(EqLength, BeamLength),
(EqStartX, BeamStartX),
(EqStartY, BeamStartY),
(EqStartZ, BeamStartZ),
]
designTable.EditStart()
for equationName, expression in equationDataList:
designTable.AddEquation(equationName)
equation = designTable.GetEquation(equationName)
setupEquation(equation, expression)
designTable.EditEnd()
def createOffsetXYPlane(part):
"""Create an XY plane offset by start_z."""
refXYPlane = part.GetPlaneXY()
offsetPlane = part.CreateReferencePlane()
offsetPlane.SetTypeByString(u"Distance")
offsetPlane.SetPropertyByReference(u"Plane", refXYPlane)
offsetPlane.SetProperty(u"Distance", EqStartZ)
return offsetPlane
def createSketchOnBeamPlane(part):
"""Create a sketch on the XY plane offset by start_z."""
offsetPlane = createOffsetXYPlane(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 drawBaseShapeForBeam(sketch, length):
"""Create the beam reference line and constrain its start position and length."""
sketch.OpenSketch()
# Start and end points of the beam
startVertex = sketch.CreateVertex(BeamStartX, BeamStartY)
startRef = geomDoc.CreateReferenceFromItem(startVertex)
endVertex = sketch.CreateVertex(BeamStartX, BeamStartY + length)
endRef = geomDoc.CreateReferenceFromItem(endVertex)
# Beam reference line in the Y-axis direction
beamLine = sketch.CreateLine(
BeamStartX,
BeamStartY,
BeamStartX,
BeamStartY + length
)
beamLineRef = geomDoc.CreateReferenceFromItem(beamLine)
sketch.CreateMonoConstraint(u"verticality", beamLineRef)
# Constrain the beam length using an equation.
lengthConstraint = sketch.CreateBiConstraint(u"distance", startRef, endRef)
setConstraintExpression(lengthConstraint, u"Distance", EqLength)
# Constrain the X position of the beam start point using an equation.
startXConstraint = sketch.CreateMonoConstraint(u"distancefromyaxis", startRef)
startXDistanceExpression = getDistanceExpressionFromSignedValue(EqStartX, BeamStartX)
setConstraintExpression(startXConstraint, u"Distance", startXDistanceExpression)
# Constrain the Y position of the beam start point using an equation.
startYConstraint = sketch.CreateMonoConstraint(u"distancefromxaxis", startRef)
startYDistanceExpression = getDistanceExpressionFromSignedValue(EqStartY, BeamStartY)
setConstraintExpression(startYConstraint, u"Distance", startYDistanceExpression)
sketch.CloseSketch()
def createBeamFromSketch(part, sketch):
"""Create a beam from the line in the sketch."""
beam = part.CreateMakeBeam(sketch)
return beam
def createBeamPart(part):
"""Create a beam with equations in the specified Part."""
sketch = createSketchOnBeamPlane(part)
drawBaseShapeForBeam(sketch, BeamLength)
createBeamFromSketch(part, sketch)
def main():
"""Create a Part containing a beam geometry with equations."""
createBeamEquations()
part = createNewPart()
createBeamPart(part)
part.ClosePart()
main()


