[S0034] Get the settings of measurement variables

 

Measurement variables are a function that obtains the length, angle, area, and other properties of geometries.
The measured value can be used to verify the geometry and as constraints during optimization.
The parameters that need to be specified and the types of entities that can be measured vary depending on the measurement type.
This script retrieves and displays the measurement type and setting parameters for the specified measurement variable.

Preconditions

  • One or more study has been created.
    This script runs on the active study in the project tree.
  • The measurement variables have been created and their names are known.

Script Function

  • Retrieve the measurement variable with the specified name.
    If not found, display a message and exits.
  • Retrieve and display the name and measurement type.
  • Display the center vertex ID and specified point position if the specified measurement type of variable needs to hold them.
  • Display the type and ID of the entity being measured.
# 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/

import tkinter as tk
from tkinter import messagebox

def getMeasurementVariableSetting(designTable, measurementVariableName):
    """Show the parameters of measurement variable with the specified name."""
    numMv = designTable.NumMeasurementVariables()
    flagValid = False
    for IdxMv in range(numMv):
        measurementVariable = designTable.GetMeasurementVariable(IdxMv)
        if measurementVariable.GetName() == measurementVariableName:
            flagValid = True
            break
    if not flagValid:
        messagebox.showerror("Error", f"The measurement variable '{measurementVariableName}' does not exist.")
        return
    # It's also possible to get by name
    # measurementVariable = designTable.GetMeasurementVariable(measurementVariableName)
    
    # Types those have specified point
    # EntityAndPointShortest : Entity and Point (Shortest Distance)
    # EntityAndPointPerpendicular : Entity and Point (Perpendicular Distance)
    # TwoPointsAndCenterAngle : Two Points and Centre Angle
    HAS_SPECIFIED_POINT_TYPES = ["EntityAndPointShortest", "EntityAndPointPerpendicular", "TwoPointsAndCenterAngle"]
    # Types those have center
    # ThreePointAngle : Three Point Angle
    HAS_CENTERD_POINT_TYPES = ["ThreePointAngle"]
    
    measurementVariableNameRetrieved = measurementVariable.GetName()
    measurementVariableType = measurementVariable.GetType()
    print(f"Name: {measurementVariableNameRetrieved}")
    print(f"Type: {measurementVariableType}")

    if measurementVariableType in HAS_SPECIFIED_POINT_TYPES:
        point = measurementVariable.GetPoint()
        print(f"\tX: {point.GetX()}")
        print(f"\tY: {point.GetY()}")
        print(f"\tZ: {point.GetZ()}")
    elif measurementVariableType in HAS_CENTERD_POINT_TYPES:
        selectedCenter = measurementVariable.GetCenter()
        if selectedCenter.NumVertices() == 1:
            print(f"Center point vertex ID: {selectedCenter.VertexID(0)}")
        else:
            print(f"Center point vertex: None")

    if measurementVariable.NumParts() <= 0:
        print("Selected entities: None")
    else:
        print("Selected entities ID:")

    selection = measurementVariable.GetSelection()
    NumVtc = selection.NumVertices()
    NumEdg = selection.NumEdges()
    NumFc = selection.NumFaces()
    NumPrt = selection.NumParts()
    
    for IdxVtc in range(NumVtc):
        Id = selection.VertexID(IdxVtc)
        print(f"\tVertex: {Id}")
    for IdxEdg in range(NumEdg):
        Id = selection.EdgeID(IdxEdg)
        print(f"\tEdge: {Id}")
    for IdxFc in range(NumFc):
        Id = selection.FaceID(IdxFc)
        print(f"\tFace: {Id}")
    for IdxPrt in range(NumPrt):
        Id = selection.PartID(IdxPrt)
        print(f"\tPart: {Id}")
    print("")


mvName = u"PointArc"
app = designer.GetApplication()
study = app.GetCurrentStudy()
dt = study.GetDesignTable()
getMeasurementVariableSetting(dt, mvName)

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