[Gmsh] Assigning to String in Geometry Script

Christophe Geuzaine cgeuzaine at uliege.be
Mon Jul 29 21:02:04 CEST 2019



> On 29 Jul 2019, at 20:03, Keith Prussing <kprussing74 at gmail.com> wrote:
> 
> Greetings,
> 
> I am trying to programmatically build surface labels in my GMSH
> script.  My thought was to store the components I wish to concatenate
> together in variables; however, I keep getting an error while trying
> to use the strings.  Consider the following minimum example
> 
>    $ cat mwe.geo
>    name = "test";
>    Printf("name is", name);
> 
> When I pass this to `gmsh`, I get the following error
> 
>    $ gmsh -0 mwe.geo
>    Info    : Running 'gmsh -2 mwe.geo' [Gmsh 4.3.0, 1 node, max. 1 thread]
>    Info    : Started on Mon Jul 29 13:28:29 2019
>    Info    : Reading 'mwe.geo'...
>    Error   : 'mwe.geo', line 5 : Unknown variable 'name'
>    name is [0]0
>    Info    : Done reading 'mwe.geo'
>    Info    : Writing 'mwe.geo_unrolled'...
>    Info    : Done writing 'mwe.geo_unrolled'
>    Info    : Stopped on Mon Jul 29 13:28:29 2019
> 
> I get the same error from the GUI.  I tried using the
> `name=Str("test");` syntax but that did not help. From what I can
> tell, section 4.2.2 of the manual says this is the correct syntax,

It is. The issue is that the Printf command in the .geo is pretty limited, and can't do string interpolation. So if you need to print the value you could do e.g.

name = "test";
Printf(StrCat("name is ", name));

You can then use it to define labels as follows:

Point(1) = {1,1,1};
Physical Point(Str(name), 1000) = {1};

Christophe



> and
> the thread linked below implies this should work. I also checked
> against a new build of `tag/gmsh_4_4_1` in the repo and the result is
> the same.
> 
> So my question is: What is the correct syntax for storing a string to
> a variable in the geometry scripting language?
> 
> Keith
> 
> [1]: http://onelab.info/pipermail/gmsh/2016/010946.html
> 
> -- 
> Keith Prussing
> 
> _______________________________________________
> gmsh mailing list
> gmsh at onelab.info
> http://onelab.info/mailman/listinfo/gmsh

— 
Prof. Christophe Geuzaine
University of Liege, Electrical Engineering and Computer Science 
http://www.montefiore.ulg.ac.be/~geuzaine






More information about the gmsh mailing list