6. Consideration on the use of macros in Python#

6.1. Definition of an out-of-catalog macro#

The standard way to add a macro definition in Python for Code_Aster execution is to add it to the code reference catalog.

However, in some cases:

  • personal macro,

  • test during development,

It may be useful to add the macro definition outside of the catalog. To do this, simply create a Python module containing the definition of the macro by adding the import of the variables from the catalog at the top of the module.

Simplified example:

from code_aster.cata.Syntax import...

from code_aster.cata.DataStructure import...

def my_macro_prod (self, ... ):

def my_macro_ops (self, … ):

MA_MACRO = MACRO (name=” MA_MACRO “,…)

Then, upon use, all you have to do is import the macro previously defined in the command file.

Example of a command file:

# macro MA_MACRO is defined in the ma_macro.py module

From ma_macro import MA_MACRO

a= MA_MACRO (...)

It is also possible to use the INCLUDE feature:

# macro MA_MACRO is defined in file INCLUDE 45

INCLUDE (UNITE =45)

a= MA_MACRO (...)