using python to control GiD
Moderator: GiD Team
using python to control GiD
Hello,
I know it is possible to use RamDebug and TCL to automate creation of GiD models ...etc. This is very useful however I would like to see if I can take it a step further. The step is using Python. Question:
Is there anyway to control GiD using python? I am not saying it is necessary to avoid TCL altogther, maybe we can still use TCL but from a Python IDE such as Spyder or Pycharm to control GiD. Any thoughts? This would be extremely useful if possible.
Thanks
I know it is possible to use RamDebug and TCL to automate creation of GiD models ...etc. This is very useful however I would like to see if I can take it a step further. The step is using Python. Question:
Is there anyway to control GiD using python? I am not saying it is necessary to avoid TCL altogther, maybe we can still use TCL but from a Python IDE such as Spyder or Pycharm to control GiD. Any thoughts? This would be extremely useful if possible.
Thanks
Re: using python to control GiD
No, GiD cannot evaluate Python scripting language.
Re: using python to control GiD
Will this be incorporated in the future? I think it would be extremely useful to have a GiD-specific python library...something like
import GiD_process
code
import GiD_process
code
Re: using python to control GiD
Also, maybe there is an indirect way to control GiD with Python? Since python can communicate with TCL/TK and GiD is built on TCL/TK?
Re: using python to control GiD
Probably some tricky indirect way is possible, but I don't know anything simple and robust
I imagine that it is possible to use sockets to send from python commands to a remote GiD that evaluate them as GiD-Tcl commands and return values to Python.
other possibility that maybe is interesting for you is to run gid in batch mode (with the process commands on a batch file).
You can write the batch file from python an run an auxiliary gid.exe -b <batchfile> do to some task and finish
In any case; what could be done with Python that doesn't has some equivalent in Tcl?
I imagine that it is possible to use sockets to send from python commands to a remote GiD that evaluate them as GiD-Tcl commands and return values to Python.
other possibility that maybe is interesting for you is to run gid in batch mode (with the process commands on a batch file).
You can write the batch file from python an run an auxiliary gid.exe -b <batchfile> do to some task and finish
In any case; what could be done with Python that doesn't has some equivalent in Tcl?
Re: using python to control GiD
I like to use python
1) As a central tool to control external applications (os, subprocess, Matlab engine, Python wrappers for FE software for example Abaqus)
2) As an analytical tool using numerical+visualization libraries (Matplotlib, numpy, vtk) to plot and interpret results
GiD is also important for me because I need to generate meshes, conditions etc to input into the FE software.
Currently my workflow is 85% in python spyder and 15% in GiD. I do a lot of work in python but have to constantly switch over to the much slower and less developed RamDebugger just to develop and generate geometries, etc then switch back to python. It would be extremely beneficial to be able to also control GiD via python or maybe control TCL through python and GiD through TCL.
1) As a central tool to control external applications (os, subprocess, Matlab engine, Python wrappers for FE software for example Abaqus)
2) As an analytical tool using numerical+visualization libraries (Matplotlib, numpy, vtk) to plot and interpret results
GiD is also important for me because I need to generate meshes, conditions etc to input into the FE software.
Currently my workflow is 85% in python spyder and 15% in GiD. I do a lot of work in python but have to constantly switch over to the much slower and less developed RamDebugger just to develop and generate geometries, etc then switch back to python. It would be extremely beneficial to be able to also control GiD via python or maybe control TCL through python and GiD through TCL.
Re: using python to control GiD
How to start a remove session of GiD? using only TCL... no python?
Re: using python to control GiD
Also what does gid.exe -b <batchfile> do?
Re: using python to control GiD
gid -b <batchfile>
start GiD and read the 'gid keyword commands' of the batch file and do them, instead to do it interactively.
e.g. create some shape, generate a mesh, export it to some file and exit
then you can control it to do a task from a external program, like an optimizator, or a python script, or others...
it is useful in batch mode to use also a -n flag, to not open any window avoiding use its resources (and to not show unwanted ugly windows).
start GiD and read the 'gid keyword commands' of the batch file and do them, instead to do it interactively.
e.g. create some shape, generate a mesh, export it to some file and exit
then you can control it to do a task from a external program, like an optimizator, or a python script, or others...
it is useful in batch mode to use also a -n flag, to not open any window avoiding use its resources (and to not show unwanted ugly windows).
Re: using python to control GiD
About use GiD 'remote' I mean that you start GiD somewhere, and in this GiD, with Tcl you can use the command 'socket' to open some port, and use the protocol you want (standard, or your own protocol) to communicate with him from other process that use the same protocol (e.g from python using its sockets and the same protocol).
You can send/receive messages between GiD and other program, located on the same machine or in other place, and evaluate in GiD as Tcl the appropriated messages.
This is moreless difficult because require implementation of the protocol at both sides: Tcl of GiD and your python interpreter, but possible.
There are packages for Tcl and for python for some standard protocols, like http, soap, websocket, etc. to facilitate part of the implementation.
You can send/receive messages between GiD and other program, located on the same machine or in other place, and evaluate in GiD as Tcl the appropriated messages.
This is moreless difficult because require implementation of the protocol at both sides: Tcl of GiD and your python interpreter, but possible.
There are packages for Tcl and for python for some standard protocols, like http, soap, websocket, etc. to facilitate part of the implementation.