From ba08ae0f58a21a6e6114ac78dce19310d87f7e19 Mon Sep 17 00:00:00 2001 From: Christophe Geuzaine <cgeuzaine@ulg.ac.be> Date: Wed, 15 Nov 2017 18:20:27 +0100 Subject: [PATCH] nicely handle argc/argv (gmshInitialize) in python --- Common/gmsh.i | 9 ++++++++- demos/api/t1.py | 1 - demos/api/t2.py | 8 ++++++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Common/gmsh.i b/Common/gmsh.i index bad364b285..d6a320814f 100644 --- a/Common/gmsh.i +++ b/Common/gmsh.i @@ -1,7 +1,14 @@ %module gmsh + +// "int &outTag" in function arguments is replaced by an append of outTag to the +// value returned by the function %include typemaps.i -// reference to int is appended to the returned values of the function %apply int &OUTPUT { int &outTag }; + +// handle gracefully the arguments of gmshInitialize +%include argcargv.i +%apply (int ARGC, char **ARGV) { (int argc, char **argv) } + %{ #include "gmsh.h" %} diff --git a/demos/api/t1.py b/demos/api/t1.py index c2493c71ce..4fc14e9ae9 100644 --- a/demos/api/t1.py +++ b/demos/api/t1.py @@ -50,7 +50,6 @@ gmshModelGeoAddLine(2, 3, 2); gmshModelGeoAddLine(3, 3, 4); gmshModelGeoAddLine(4, 4, 1); - # The philosophy to construct line loops and surfaces is similar: the second # arguments are now vectors of integers. gmshModelGeoAddLineLoop(1, [4, 1, -2, 3]); diff --git a/demos/api/t2.py b/demos/api/t2.py index 5a4181126f..5360c9cfac 100644 --- a/demos/api/t2.py +++ b/demos/api/t2.py @@ -4,13 +4,17 @@ # API functions used, compared to the ones introduced in t1.py. from gmsh import * +import sys + +# If sys.argv is passed, Gmsh will parse the commandline in the same way as the +# standalone Gmsh code. +gmshInitialize(sys.argv); -gmshInitialize(); gmshOptionSetNumber("General.Terminal", 1); gmshModelCreate("t2"); -# Copied from t1.cpp... +# Copied from t1.py... lc = 1e-2; gmshModelGeoAddPoint(1, 0, 0, 0, lc); gmshModelGeoAddPoint(2, .1, 0, 0, lc); -- GitLab