Menu

Defining constants

Help
2005-09-16
2013-04-22
  • Nobody/Anonymous

    I would like to define constants and use those constants in the definition of my model. For example: a=3 b=4 c=5 and then use those to define my model.

    in   sph3.s    sph    a    2*b    2.3*a    3*c/b

    What command do I use to define a constant?

     
    • Sean Morrison

      Sean Morrison - 2005-09-23

      You can use the fact that you're working in a Tcl interpreter to do this by saving the values as Tcl variables.  By default, the MGED command line behaves in a globbing mode like a usual command line, so you'll probably want to turn that off first:

      set glob_compat_mode 0

      That is also achievable through the menus via File->Preferences->Special Characters->Tcl Evaluation.  Once that's set, you can:

      set a 3
      set b 4
      set c 5
      in sph2 sph $a [expr 2*$b] [expr 2.3*$a] [expr 3*$c/$b]

      You can actually do all that without setting glob compat mode, but you'd have to escape all the []'s and *'s:

      in sph2 sph $a \[expr 2 \* $b\] \[expr 2.3 \* $a\] \[expr 3 \* $c / $b\]

      Not very pretty, but it should work.  Again, it's a full Tcl interpreter so you can pretty much do anything that is allowed in Tcl (or incrTcl for that matter since it's loaded too if you want object-oriented semantics).  Those constants and expressions are not stored in the model, they are computed then and there and set on the object.  Parametric expresssions are on the to-do list for the next revision of the geometry format.

      Cheers!
      Sean

       

Log in to post a comment.