# using python to control GiD

**URL:** <https://forum.gidsimulation.com/t/using-python-to-control-gid/2246>\
**Category:** Customization\
**Created:** [May 26, 2017, 3:38pm UTC](https://forum.gidsimulation.com/t/using-python-to-control-gid/2246 "2017-05-26T15:38:46Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![awa5114](https://forum.gidsimulation.com/letter_avatar_proxy/v4/letter/a/d07c76/32.png) [@awa5114](https://forum.gidsimulation.com/u/awa5114)\
**Post date:** [May 26, 2017, 3:38pm UTC](https://forum.gidsimulation.com/t/using-python-to-control-gid/2246/1 "2017-05-26T15:38:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![escolano](https://forum.gidsimulation.com/user_avatar/forum.gidsimulation.com/escolano/32/6_2.png) [@escolano](https://forum.gidsimulation.com/u/escolano)\
**Post date:** [May 26, 2017, 5:30pm UTC](https://forum.gidsimulation.com/t/using-python-to-control-gid/2246/2 "2017-05-26T17:30:28Z")

</div>

No, GiD cannot evaluate Python scripting language.

---

<div class="post-metadata">

**Author:** ![awa5114](https://forum.gidsimulation.com/letter_avatar_proxy/v4/letter/a/d07c76/32.png) [@awa5114](https://forum.gidsimulation.com/u/awa5114)\
**Post date:** [May 27, 2017, 6:39am UTC](https://forum.gidsimulation.com/t/using-python-to-control-gid/2246/3 "2017-05-27T06:39:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![awa5114](https://forum.gidsimulation.com/letter_avatar_proxy/v4/letter/a/d07c76/32.png) [@awa5114](https://forum.gidsimulation.com/u/awa5114)\
**Post date:** [May 28, 2017, 7:24am UTC](https://forum.gidsimulation.com/t/using-python-to-control-gid/2246/4 "2017-05-28T07:24:02Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![escolano](https://forum.gidsimulation.com/user_avatar/forum.gidsimulation.com/escolano/32/6_2.png) [@escolano](https://forum.gidsimulation.com/u/escolano)\
**Post date:** [May 29, 2017, 6:18pm UTC](https://forum.gidsimulation.com/t/using-python-to-control-gid/2246/5 "2017-05-29T18:18:38Z")

</div>

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 do to some task and finish

In any case; what could be done with Python that doesn’t has some equivalent in Tcl?

---

<div class="post-metadata">

**Author:** ![awa5114](https://forum.gidsimulation.com/letter_avatar_proxy/v4/letter/a/d07c76/32.png) [@awa5114](https://forum.gidsimulation.com/u/awa5114)\
**Post date:** [June 18, 2017, 5:45am UTC](https://forum.gidsimulation.com/t/using-python-to-control-gid/2246/6 "2017-06-18T05:45:55Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![awa5114](https://forum.gidsimulation.com/letter_avatar_proxy/v4/letter/a/d07c76/32.png) [@awa5114](https://forum.gidsimulation.com/u/awa5114)\
**Post date:** [June 19, 2017, 9:06am UTC](https://forum.gidsimulation.com/t/using-python-to-control-gid/2246/7 "2017-06-19T09:06:43Z")

</div>

How to start a remove session of GiD? using only TCL… no python?

---

<div class="post-metadata">

**Author:** ![awa5114](https://forum.gidsimulation.com/letter_avatar_proxy/v4/letter/a/d07c76/32.png) [@awa5114](https://forum.gidsimulation.com/u/awa5114)\
**Post date:** [June 19, 2017, 9:16am UTC](https://forum.gidsimulation.com/t/using-python-to-control-gid/2246/8 "2017-06-19T09:16:34Z")

</div>

Also what does gid.exe -b do?

---

<div class="post-metadata">

**Author:** ![escolano](https://forum.gidsimulation.com/user_avatar/forum.gidsimulation.com/escolano/32/6_2.png) [@escolano](https://forum.gidsimulation.com/u/escolano)\
**Post date:** [June 19, 2017, 5:01pm UTC](https://forum.gidsimulation.com/t/using-python-to-control-gid/2246/9 "2017-06-19T17:01:51Z")

</div>

gid -b   
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).

---

<div class="post-metadata">

**Author:** ![escolano](https://forum.gidsimulation.com/user_avatar/forum.gidsimulation.com/escolano/32/6_2.png) [@escolano](https://forum.gidsimulation.com/u/escolano)\
**Post date:** [June 19, 2017, 5:13pm UTC](https://forum.gidsimulation.com/t/using-python-to-control-gid/2246/10 "2017-06-19T17:13:08Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![fjgarate](https://forum.gidsimulation.com/user_avatar/forum.gidsimulation.com/fjgarate/32/13_2.png) [@fjgarate](https://forum.gidsimulation.com/u/fjgarate)\
**Post date:** [June 23, 2024, 8:55pm UTC](https://forum.gidsimulation.com/t/using-python-to-control-gid/2246/11 "2024-06-23T20:55:10Z")

</div>

Hey,

you can use python to control GiD!  
Please check the documentation: [https://gidsimulation.atlassian.net/wiki/spaces/GCS/pages/2809692161/Using+Python+in+GiD](https://gidsimulation.atlassian.net/wiki/spaces/GCS/pages/2809692161/Using+Python+in+GiD)

Javi G

---

<div class="post-metadata">

**Author:** ![escolano](https://forum.gidsimulation.com/user_avatar/forum.gidsimulation.com/escolano/32/6_2.png) [@escolano](https://forum.gidsimulation.com/u/escolano)\
**Post date:** [December 18, 2024, 5:56pm UTC](https://forum.gidsimulation.com/t/using-python-to-control-gid/2246/12 "2024-12-18T17:56:08Z")

</div>

Since the version 17 GiD can evaluate Python code in its own embedded interpreter.

Read in this course chapter how to use Python in GiD:

> **[Using Python in GiD - GiD courses - Confluence](https://gidsimulation.atlassian.net/wiki/spaces/GCS/pages/2809692161/Using+Python+in+GiD)**
