FeResPost Web Site                     FeResPost Online User Manual

VII.1.1.1 Using component with python

The file “COM/EX99_LANGS/testClaCom.py” contains the Python code for automating CLA calculations. Some explanation of how the program works is given below.

First, some standard Python packages must be imported to enable OLE automation in the program. The following statements are therefore added at the beginning of the program:

         import sys
         import gc

         from win32com.client import Dispatch, constants
      

The program then defines several methods that are used in the main program:

No “main” function is defined in the program; instead, the last lines of the file contain the instructions that perform the main analysis.

First, the component must be accessed and a ClaDb object created and initialized, as follows:

         frpApp = Dispatch("FeResPost_3_4_0.Application")
         db=frpApp.newObject("ClaDb")
         db.readNeutral("test.ndf")
      

Note that accessing the application requires its full name, which includes the version identifier. This means that the name must be changed if a different version of the component is used. Initializing the ClaDb object involves reading the “test.ndf” neutral data file.

The results are written to a disk file:

         os=file("testClaCom_py.txt","w")
      

Note that iterators are easy to use in Python. Readers familiar with Python should have no trouble understanding the following lines:

         for lamId in db.iter_laminateId:
            printLamProperties(db,os,lamId)
            for loadId in db.iter_loadId:
               printLoadResponse(db,os,lamId,loadId,0.0,criteria)
      

The outer loop iterates over the laminates and prints their properties. Inside this loop, an inner loop iterates over the loads stored in the database, calculating and printing the laminate load response for each one. The criteria calculated are: “TsaiHill”, “Ilss” and “YamadaSun”.

When the program is run, the FeResPost component application window displays the number of referenced component objects and the number of references to each. You can stop the program at various points to check this information, for example by adding Windows message boxes.