Remove error

Jouher_20929
Jouher_20929 Altair Community Member
edited October 2020 in Community Q&A

@tinh @Pandurang

I have option for selection of node (*createmarkpanel) followed by set of operations. If, i am not selecting any node, while execution of command, I want to exit from command instead of throwing errors. please help me to sort this out.

Tagged:

Answers

  • Imoto
    Imoto
    Altair Employee
    edited June 2018

    Hi Jouher,

     

    *createmarkpanel nodes 1 'Please select nodes';
    if {[hm_marklength nodes 1] > 0} {
     *nodemarkaddtempmark 1;
    } else {
     tk_messageBox -message '0 nodes selected' -icon error;
    }

     

    Or You can use 'catch' command.

    https://www.tcl.tk/man/tcl8.4/TclCmd/catch.htm

     

    Thanks,

    Imoto

  • Jouher_20929
    Jouher_20929 Altair Community Member
    edited June 2018

    Thanks @Imoto ,

    But, If i select any node, then press esc it wont work. similarly for string too, if I type name and instead of proceed, if i press esc key, it will proceed further.

    Please help me to solve this too.

  • tinh
    tinh Altair Community Member
    edited June 2018

    Hi Jouher,

    so you want : press ESC => will NOT proceed, don't you?

    I had the code

  • Jouher_20929
    Jouher_20929 Altair Community Member
    edited June 2018

    Hi Jouher,

    so you want : press ESC => will NOT proceed, don't you?

    I had the code

    Yes, @tinh

  • Imoto
    Imoto
    Altair Employee
    edited June 2018

    Hi Jouher,

     

    You can add the bind for Escape key.

     

    proc ESCkeyClearAll {args} {
     hm_markclearall 1;
     hm_markclearall 2;
    }
    bind . <Escape> ESCkeyClearAll


    *createmarkpanel nodes 1 'Please select nodes';
    if {[hm_marklength nodes 1] > 0} {
     *nodemarkaddtempmark 1;
    } else {
     tk_messageBox -message '0 node selected' -icon error;
    }

     

    Thanks,
    Imoto

  • Jouher_20929
    Jouher_20929 Altair Community Member
    edited June 2018

    Hi Jouher,

     

    You can add the bind for Escape key.

     

    proc ESCkeyClearAll {args} {
     hm_markclearall 1;
     hm_markclearall 2;
    }
    bind . <Escape> ESCkeyClearAll


    *createmarkpanel nodes 1 'Please select nodes';
    if {[hm_marklength nodes 1] > 0} {
     *nodemarkaddtempmark 1;
    } else {
     tk_messageBox -message '0 node selected' -icon error;
    }

     

    Thanks,
    Imoto

    Its not working

  • tinh
    tinh Altair Community Member
    edited June 2018

    Hi

    we should not bind a script to '.' toplevel, because it will trigger every widgets

    the main widget receives ESC key to exit panel is .hmContainer

  • Imoto
    Imoto
    Altair Employee
    edited June 2018

    Thanks Tinh,

     

    bind .hmContainer <Escape> {hm_markclearall 1; hm_markclearall 2; hm_notifykeydown %N %k;}
    

  • tinh
    tinh Altair Community Member
    edited June 2018

    I wrote a proc like this:

     

    proc p_SelectMark {EntityType MarkId args} {

            #this binding code can be set once at level #0, but i embed here, so this proc is working everytime

             if {![string match '*set ::v_PressEsc 1*' [bind .hmContainer <Key-Escape>]]} {

                    bind .hmContainer <Key-Escape> {+set ::v_PressEsc 1}

             }

             if {![hm_info functionlock]} {

                    set ::v_PressEsc 0

                   *createmarkpanel $EntityType $MarkId $args

                    if {$::v_PressEsc} {

                        *clearmark $EntityType $MarkId

                    }

                    hm_getmark $EntityType $MarkId

             }

    }