Share

API example: Customized aspect ratio plot

This example creates a custom contour plot using aspect ratio data from mesh diagnostics. The script uses the DiagnosisManager class for access to mesh diagnostics data, and the PlotManager class to create the custom user plot.

# %RunPerInstance
"""
DESCRIPTION:
Take the Standard Aspect Ratio Plot and convert it into a contour plot

SYNTAX:
python filename.py 
eg. python aspect_ratio_contour.py

PARAMETERS:
none

DEPENDENCIES/LIMITATIONS:
Assumes a study file is open within synergy
"""
from moldflow import Synergy
from moldflow.common import SystemUnits

def main():
    """Main function to create aspect ratio contour plot."""

    synergy = Synergy(units=SystemUnits.METRIC)

    # Create arrays for element IDs and aspect ratio values
    elems = synergy.create_integer_array()
    ar = synergy.create_double_array()

    # Get aspect ratio diagnostics
    diagnosis_manager = synergy.diagnosis_manager

    # Get aspect ratio diagnosis (min=0.0, max=0.0, std_ar=True, visible=False, element_id=elems, value=ar)
    diagnosis_manager.get_aspect_ratio_diagnosis(0.0, 0.0, True, False, elems, ar)

    # Create user plot
    plot_manager = synergy.plot_manager
    ar_plot = plot_manager.create_user_plot()

    # Configure the plot
    ar_plot.set_data_type("ELDT")  # Element data type
    ar_plot.set_name("Aspect ratio by contours")

    # Add the scalar data (time=0.0, element IDs, aspect ratio values)
    ar_plot.add_scalar_data(0.0, elems, ar)

    # Build the plot
    ar_plot.build()   
    print("Script Complete")

if __name__ == "__main__":
    try:
        main()
    except Exception as e:
        print(f"Error: {e}")

Was this information helpful?