13.6.4. Writing the Script

Engineering Knowledge Manager

Administration Guide | Chapter 13: EKM Client API | 13.6. Writing and Running a Python Script Using IronPython |

13.6.3. Directory Structure for an IronPython Script without Workbench |  | 13.7. Building and Executing C# Sample
Prev |  | Next

### 13.6.4. Writing the Script

The first thing that the script must do is import the Common Language Runtime object and load the C# libraries. This is shown below:

    import clr
    clr.AddReferenceToFileAndPath("bin//CookComputing.XmlRpcV2.dll")
    clr.AddReferenceToFile("bin//EkmClientApi.dll")
    clr.AddReferenceToFile("bin//log4net.dll")

Next, the script needs to import any classes needed. For example, this script only needs specific access to the `ConnectionFactory` class:

    from com.ansys.ingress.client.api import ConnectionFactory

Finally, the script can open the connection and perform some task. The full script contained in OpenCloseConnection.py is provided below:

    # Load EKM assemblies
    import client_init

    from com.ansys.ingress.client.api import ConnectionFactory

    if __name__ == "__main__":
        conn = None
        try:
            # Change the username and password below as needed
            conn = ConnectionFactory.Open(
                "http://localhost:8080", # host
                "ekmadmin",              # username
                "Adminuser123!")         # password
            print ">>>>> Connection " + conn.GetName() + " opened"
        finally:
            if conn:
                conn.Close()
                print ">>>>> Connection " + conn.GetName() + " closed"

The following is the sample output of this script:

    F:\scripts>ipy OpenCloseConnection.py
    >>>>> Connection Default@lebmmoales2 opened
    >>>>> Connection Default@lebmmoales2 closed

Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

Prev | Up / Contents | Next

Release 18.2 - © ANSYS, Inc. All rights reserved.