How to stop tcl script after warning message?

Altair Forum User
Altair Forum User
Altair Employee
edited October 2020 in Community Q&A

Hi everybody,

 

how can I stop a tcl script, after a warning message?

I have the following expression:

 

 

if {$outerdiameter > $innerdiameter}  {
} else  {
   tk_messageBox -message 'WARNING - Please check your input! \n
  Outer diameter = $outerdiainput mm \n
  Inner diameter = $innerdiainput mm' -type ok

}

 

outer- and innerdiameter are variables I defined earlier in my script.

 

Now I would like to stop the tcl script from working on, if the message box appears.

Or even better would be if it is possible to add some command that after the message box appears tcl moves back to a specified line in the script. Something like go to line 5.

 

thanks in advance!

Tagged:

Answers

  • tinh
    tinh Altair Community Member
    edited June 2018

    To stop script, use tcl command 'return'

    to jump back a specified line: there is no command to jump but you can do a loop and check condition to break the loop, example

    while {$outerdiameter > $innerdiameter} {

          tk_messageBox -message 'WARNING - Please check your input! \n
      Outer diameter = $outerdiainput mm \n
      Inner diameter = $innerdiainput mm' -type ok

    set       outerdiameter [hm_getint outer]

    set       innerdiameter [hm_getint inner]

    }

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited June 2018

    Hi tinh,

     

    the return command works fine!

    I tried the 'while' command too but nothing happens  :unsure:/emoticons/default_unsure.png' title=':unsure:' />

     

    example:

    set outerdiameter [ hm_getstring 'Outer diameter in mm']            --> My input is 10

    set innerdiameter [ hm_getstring 'Inner diameter in mm']            --> My input is 10.5

     

    while {$outerdiameter > $innerdiameter} {

          tk_messageBox -message 'WARNING - Please check your input! \n
      Outer diameter = $outerdiainput mm \n
      Inner diameter = $innerdiainput mm' -type ok 

    set       outerdiameter [hm_getint outer]

    set       innerdiameter [hm_getint inner]

    }

     

    Now I thought it will bring me back to my input dialog, because innerdiameter is bigger than outerdiameter ??? Am I doing something wrong?

     

    Thnaks in advance

     

     

  • tinh
    tinh Altair Community Member
    edited June 2018

    Hi

    because 10>10.5 is FALL so body script of 'while' will not be evaluated

     

    you have to change 'while {$outerdiameter > $innerdiameter} {'

    to  'while {$outerdiameter < $innerdiameter} {'

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited June 2018

    Hi

    because 10>10.5 is FALL so body script of 'while' will not be evaluated

     

    you have to change 'while {$outerdiameter > $innerdiameter} {'

    to  'while {$outerdiameter < $innerdiameter} {'

     

    Now it works perfectly!!!

    That's what I wanted to have in my tcl-file :D/emoticons/default_biggrin.png' srcset='/emoticons/biggrin@2x.png 2x' title=':D' width='20' />

     

    Thank you very much I really appreciate your support!

     

    Best regards,

    Tomi