From the lower entry, can invoke Tcl code writing -np- followed some space and then some tcl code an press <Return>
Note: -np- mean ‘No-Process’ and the next command is expected to be Tcl code. It is used as a fast way to run a simple procedure or re-define code.
Use copy/paste code after -np-
In particular there are some predefined Tcl procs that run python code, like GiD_Python_Exec (other possibilities are GiD_Python_Eval, GiD_Python_Call, …)that expects the python code to be evaluated
Example: matplotlib graph of a line
This is a simple example of call from Tcl a Python code that uses the matplotlib to show a graph (in new Tk window opened by tkinter)
Code Block |
---|
GiD_Python_Exec {
import matplotlib.pyplot as plt
plt.plot([1, 2, 3, 4])
plt.ylabel('some numbers')
plt.show()
} |
GiD_Python_Exec
do an implicit package require tohil
and then tohil::exec
Can invoke this Tcl code for example pasting it after -np-
in the command line (with one or more spaces separating the code pasted), and press <return>
...
then will appear a window like this
...
-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.
Example: matplotlib graph of two curves
The file <GiD>/scripts/tohil/doc/demo_matplotlib.py contain a code like the one of the image
...
and can source this file writing this (<GiD> must be replaced by the true path)
-np- GiD_Python_Source {<GiD>/scripts/tohil/doc/demo_matplotlib.py}
then this window will appear:
...