Scripting Menu

FEFLOW Python scripting capabilities are activated via Global Settings options from the Tools menu. The option Enable Scripting is part of the section Tool Properties. Once this scripting option has been activated, FEFLOW will remember the user-defined setting and provide access to the Scripting menu.

The operation in the Scripting menu differs slightly to an external Python interpreter or Python Shell outside FEFLOW. The import of the ifm module is not required. The document variable, typically referred as doc, is automatically initialized and referred to the current document instance (either FEM file or DAC file) loaded in the FEFLOW Graphical Interface.

Table below shows an example about the operation differences between an external Python interpreter and the Scripting menu. The simple example just print the total number of nodes in the finite-element mesh.

 

External Python Interpreter / Python Shell FEFLOW Scripting menu

# Import FEFLOW ifm module

import sys

sys.path.append(r'C:\Program Files\DHI\2024\FEFLOW 8.1\bin64\')

import ifm

 

# Load document

doc = ifm.loadDocument('myFile.fem')

 

# Carry out an action

print 'Number of nodes: ' + str(doc.getNumberOfNodes())

 

# Carry out an action

print 'Number of nodes: ' + str(doc.getNumberOfNodes())

 

The variable doc is reserved for referring to the current document in the graphical interface. Another variable to point the FEFLOW document is not supported, e.g. d.getNumberOfNodes() will return an error message.

Edit FEFLOW Python Script

FEFLOW Python scripts can be loaded from an external file (*.py) via the Edit Script option in the Scripting menu. The Edit FEFLOW  Python Script dialog provides access for simple editing of the loaded script as well as to export the modification in a Python document (*.py). Script available on the FEFLOW  Python Script dialog becomes part of the client-section of the FEFLOW document (*.fem) after the document is saved.

Execute Python Command

The Execute Python Command dialog allows simple capabilities of a Python console. For example, the user can test parts of the scripts, e.g. functions defined already in the Edit FEFLOW  Python Script dialog. The command dialog provides exclusive access the GUI-module (feflow) methods, which shutdown, getKernelVersion, openDocument, etc. An example of the operation of the Execute Python Commands dialog is shown below.

 

# Display available methods

print dir(feflow)

 

# Load a document

FEM = "..\\femdata\\MyFile.fem"

feflow.openDocument(FEM)

 

# Close FEFLOW Graphical Interface

feflow.shutdown()

Script Handling

FEFLOW provides four options for handling stored scripts in FEM documents. These options are reachable via the menu Tools - Global Settings.

  • Disable scripting: Scripts will not be executed and it is not possible to edit/execute any script/command but scripts in the documents are preserved (during load/save)

  • Ask me every time a document is loaded: For any document - which is loaded and contains scripting data -  the user is queried if the script should be executed. If yes, the script is executed, e.g., procedures are available. If not, the script is never executed (thus no procedures available), unless the user executes the script manually in the Python Script Dialog.

  • Ask me only once per session: Same behaviour as Ask me every time a document is loaded, except that the user is queried only once a document with scripting data is loaded and the answer is applied to all subsequent documents until FEFLOW is closed.

  • Always execute scripts: Scripts are always executed without any query

Table of Contents

Index

Glossary

-Search-

Back