How to close Gmsh GUI using API for Python
Hello everyone,
My first need was to save an image using the API for Python without using Gmsh GUI.
First, I tried to save the image using only the command gmsh.write
:
import gmsh
def main():
# Initializing API
gmsh.initialize()
# Geometry
s = gmsh.model.occ.add_rectangle(0, 0, 0, 1, 1)
gmsh.model.occ.synchronize()
# Mesh
gmsh.model.mesh.generate()
# Save image
gmsh.write(f"image_{s}.png")
# Other actions...
if __name__ == "__main__":
main()
I got the error with that code: "Creating 'image_1.png' requires a graphical interface context".
Ok. I thought and is at least reasonable to use the graphical interface context to generate the image
So, I used the command gmsh.fltk.initialize()
as follows, but it opens a Gmsh window, and I need to perform other actions with the Gmsh windows closed.
import gmsh
def main():
# Initializing API
gmsh.initialize()
# Geometry
s = gmsh.model.occ.add_rectangle(0, 0, 0, 1, 1)
gmsh.model.occ.synchronize()
# Mesh
gmsh.model.mesh.generate()
# Save image
gmsh.fltk.initialize()
gmsh.write(f"image_{s}.png")
# Other actions...
# How to close the gmsh window?
if __name__ == "__main__":
main()
I tried gmsh.finalize
after the command gmsh.write
. It closes the windows but also deletes the model.
Is there a way to close the Gmsh window without deleting the model using the API for Python?