Share

API example: The first lines of a script

The following template is a suggested starting point for using the Moldflow Python API.

To call a specific version of Synergy, the first line must be:

# %RunPerInstance

These lines are the entry point to start scripting in Synergy (the Autodesk Moldflow user interface). Other initial settings are set in this class such as units and logging.

from moldflow import Synergy
from moldflow.common import SystemUnits

synergy = Synergy(units=SystemUnits.METRIC)

You are able to set units separately for better clarity. Units that can be used are "English" (US units) and "Metric". For more clarity during coding you can use the enums from Moldflow.

from moldflow import Synergy
from moldflow.common import SystemUnits

synergy = Synergy()
synergy.units = SystemUnits.ENGLISH

It is good practice to put explanatory comments at the top of your scripts. Here is an example of a python script using Moldflow api.

# %RunPerInstance
"""
DESCRIPTION:
Basic template script for Moldflow Synergy API

SYNTAX:
python filename.py
eg. python template_script.py

PARAMETERS:
none

DEPENDENCIES/LIMITATIONS:
Requires Moldflow Synergy
"""
from moldflow import Synergy

def main():
    """Main function - template for Moldflow API scripts."""

    synergy = Synergy()

    #
    # Put remainder of code here.
    #

    print("Script Complete")

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

Was this information helpful?