Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

In particular there are some predefined Tcl procs that run python code, like GiD_Python_Exec that expects the python code to be evaluated

...

then will appear a window like this

...

There are other procs similar to GiD_Python_Exec ,like GiD_Python_Eval (for a single instruction and value is returned) or GiD_Python_Call (to invoke a function that must be previously defined)

Source a file with the code

-np- GiD_Python_Source $your_filename_py

The normal way to write long Python code is write it in a .py file.

Note: Visual Studio Code is our recommended editor, installing the MS Python extension for this language.

GiD_Python_Source is a Tcl proc that expects the name of a python file with the code to be sourced

...

then this window will appear:

...

Python force reload a file

Other Tcl procs related to source Python code are GiD_Python_Import_File and GiD_Python_Import

Using our Tcl command GiD_Python_Import_File (that do tohil::import) will import a module in Python.

And GiD_Python_Import is similar to GiD_Python_Import_File but instead of a full path expects the module name (without .py extension), and must be found based on the path environment variable

but if we are developing and modify the .py file doing a new import don’t refresh the code in the interpreter.

A trick to do it it to use the Tcl command GiD_Python_Source,then the new code of the file is used without need to restart GiD.

In fact it seems that this is similar to use in Python the function reload of the importlib module

Code Block
import importlib
importlib.reload(module)