[S0060] Create a flux line for a 3D result by specifying a face as a rendering start

The flux line function can visualize the flow of magnetic flux and other quantities obtained from the analysis.
It can be displayed together with contour or vector plot so that it enables to understand not only the magnitude of the density but also the direction of the flow.
For 3D models, in addition to displaying a flux line that passes through a specified point, flux lines that pass through a specified plane can be displayed.
This script creates the definition to display flux lines passing through a plane.

Preconditions

  • One or more magnetic field analysis, transformer analysis, thermal analysis or electric field analysis studies have been created.
    The rendering start type option is the setting for 3D.
    This script runs on the active magnetic field analysis study in the project tree.
  • The name of the part set for displaying must be known.
  • The units of the setting values ​​follow the unit system set for the model.
  • To display the defined flux line, the study has been calculated.

Script Function

  • Get the part set with the specified name
    Designate the parts within the set as the targets for flux line displaying.
  • Create flux line definition
    Set the result type to magnetic flux density.
    Set the rendering start type to "Plane".
  • Define the rendering start plane
    Normal vector: (1, 0, 0)
    Point on the plane: (8, 7, 8)
    Plane dimensions: Width 15, Height 15
  • Specify the previously retrieved part set as the displaying target
  • Turn on display the defined flux line
# 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()

def createFluxLineFromPlane(study, fluxLineParam, planeParam):
    """Create a flux line."""
    fluxLineDef = study.CreateFluxLine(fluxLineParam[u"title"])
    fluxLineDef.SetResultType(fluxLineParam[u"resultType"])
    # Display type
    # 0 : Shading
    # 1 : No hidden lines
    # 2 : Wireframe
    fluxLineDef.SetDisplayType(fluxLineParam[u"displayType"])
    fluxLineDef.SetThickness(u"1.1")
    fluxLineDef.SetColor(u"red")
    fluxLineDef.SetLines(planeParam[u"lines"])
    # drawing type
    # point : Point specification
    # plane : Surface specification
    fluxLineDef.SetFluxLineType(u"plane")

    normalX, normalY, normalZ = planeParam[u"normal"]
    fluxLineDef.SetNormal( normalX, normalY, normalZ )

    originX, originY, originZ = planeParam[u"origin"]
    fluxLineDef.SetOrigin( originX, originY, originZ )

    plane = planeParam[u"plane"]
    useFinitePlane = plane[u"useFinite"]
    fluxLineDef.SetUseFinitePlane(useFinitePlane)
    if useFinitePlane:
        fluxLineDef.SetPlaneWidth(plane[u"width"])
        fluxLineDef.SetPlaneHeight(plane[u"height"])

    seed = planeParam[u"seed"]
    useAllParts = seed[u"allParts"]
    fluxLineDef.SetSeedLineAllParts(useAllParts)
    if not useAllParts:
        # Specify the part ID.
        partIdList = seed[u"partIdList"]
        for partId in partIdList:
            fluxLineDef.AddPart(partId)

model = app.GetCurrentModel()
study = app.GetCurrentStudy()
partSet = model.GetSetList().GetSet(u"Rotor")
fluxLineParam = {
    u"title" : u"MagFluxDens",
    u"resultType" : u"MagneticFluxDensity",
    u"displayType" : 2
}
planeParam = {
    u"lines" : u"22",
    u"normal" : (1, 0, 0),
    u"origin" : (8, 7, 8),
    u"plane" : {
        u"useFinite" : True,
        u"width"     : 15,
        u"height"    : 15,
    },
    u"seed" : {
        u"allParts"   : False,
        u"partIdList" : partSet.GetIDs(),
    },
}

createFluxLineFromPlane(study, fluxLineParam, planeParam)

# Turn on the display of flux lines.
app.View().SetFluxLineView(True)

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