Example POSTFEKO API Script
The easiest way to understand and get started with scripting is by analysing a working example. As part of the example, a number of important aspects are highlighted. The example can be copied into the script editor and executed as part of the demonstration.
Open a Model
app = pf.GetApplication() app:NewProject() FEKO_HOME = os.getenv("FEKO_HOME") print("Feko is installed in " .. FEKO_HOME) app:OpenFile(FEKO_HOME..[[/shared/Resources/Automation/startup.fek]]) printlist(app.Models:Items())
The code extract starts by accessing and storing the application object, using the GetApplication static function that is available under the pf namespace . All functions, objects, constants and enumerations are available in the pf namespace, although a subset of these are also globally available. These were added in a namespace so that they will not be replaced when loading external libraries. The namespace also makes it easier to use the auto completion feature in the editor (type pf. in the editor to see the auto completion menu). The application objects are stored in a variable app to make it easier to access further down in the script.
:) and to access the static
                    function use a full stop(.).The FEKO_HOME environment variable is stored in a new variable by utilising the os (operating system) module’s getenv method. The os module is included as part of the Feko installation. The value of the variable is then printed to the screen for validation.
The OpenFile method of the Application object
                is then used to load the startup
                model (a demonstration model that is part of all Feko
                installations). Finally the models that have been loaded are printed to screen as
                confirmation that the model has indeed loaded correctly.
If the script is executed, POSTFEKO should have the
                    startup model loaded. The rest
                of the example will illustrate basic tasks that can be performed using the startup model.
Access the Model Configuration
c1 = app.Models["startup"].Configurations[1] print(c1.EndFrequency) print(c1.StartFrequency)
A variable, c1, is used to store a
                link to the first configuration of the model. The model that has been loaded is
                accessed using the Models property of the
                    Application object. Properties, like static functions, are
                accessed using a full stop as indicated in the example. The
                    Models property returns a collection. There are many
                collections in the POSTFEKO API, but the collections
                work the same and have the same methods and operators associated with them. An item
                in the collection is accessed by name or by index using the square bracket indexing
                    ([]).
The example uses both indexing methods since it indexes the model by name and the configuration by number. The same result is achieved by accessing both the model and the configuration by name or by number.
c1, but it makes it
                    easier and shorter to access the configuration further down in the
                    script.Create and Customise a Cartesian Graph
cg = app.CartesianGraphs:Add() cg.BackColour = pf.Enums.ColourEnum.Transparent cg.Grid.BackColour = pf.Enums.ColourEnum.LightGrey cg.Grid.Minor.Visible = true cg.Grid.Minor.HorizontalLine.Style = pf.Enums.LineStyleEnum.SolidLine cg.Grid.Minor.VerticalLine.Style = pf.Enums.LineStyleEnum.DashDotDotLine cg.Grid.Major.HorizontalLine.Colour = pf.Enums.ColourEnum.Black cg.Grid.Major.VerticalLine.Colour = pf.Enums.ColourEnum.BlackThe only new concept that is introduced in this script extract is the use of enumerations to access predefined colours and line styles. Enumerations are accessed using the pf.Enums namespace.
Add a Trace to a Graph
cg.Traces:Add(c1.NearFields[1]) cg.Legend.Frame.BackColour = pf.Enums.ColourEnum.Transparent cg.HorizontalAxis.Title.Frame.Line.Colour = pf.Enums.ColourEnum.Blue cg.VerticalAxis.Title.Frame.Line.Colour = pf.Enums.ColourEnum.Blue
Generate a PDF Report
report = app:CreateQuickReport([[Example_report]], pf.Enums.ReportDocumentTypeEnum.PDF) report.DocumentHeading = "Example report" report:Generate()This example only illustrates a small subset of what can be done using the POSTFEKO application programming interface. Use this script as a starting point to explore other features that are available in the API.