Can anyone tell me how to increase the Variable j by clicking the Next button in GUI.

Yesvanth
Yesvanth Altair Community Member

set i 0
set j 0

set win .window
catch {destroy $win}
toplevel $win -class TopClass
wm title $win "Master GUI"
wm geometry $win 400x200+900+650
wm resizable $win 0 0
wm deiconify $win

button $win.01 -text "Next" -font {times 15 bold} -command {Script [expr $i + 1]}
place $win.01 -x 230 -y 130 -width 140 -height 36

proc Script {j} {

set i $j

*createmark comp 1 "by assem name" Piston_2D

set Complist [hm_getmark comp 1]

set Complist [lrange $Complist 0 end]

set tot [llength $Complist]

set Isocomp [lindex $Complist $j]

*createmark comp 1 $Isocomp

*isolateonlyentitybymark 1 1 2

hm_viewfit

}

Welcome!

It looks like you're new here. Sign in or register to get started.

Best Answer

  • AndreasAltmann
    AndreasAltmann Altair Community Member
    Answer ✓

    Hello Yesvanth,

    I think you need to declare j as a global variable.
    I would recommend to use a different variable name then j when doing this. Otherwise it will be very likely that you will get conflicts with other scirpts.

    But this should work:

    global j
    set i 0
    set j 0 set win .window
    catch {destroy $win}
    toplevel $win -class TopClass
    wm title $win "Master GUI"
    wm geometry $win 400x200+900+650
    wm resizable $win 0 0
    wm deiconify $win button $win.01 -text "Next" -font {times 15 bold} -command {Script [expr $j + 1]}
    place $win.01 -x 230 -y 130 -width 140 -height 36 proc Script {new_j} {
    global j
    *createmark comp 1 "by assem name" Piston_2D
    set Complist [hm_getmark comp 1]
    set Complist [lrange $Complist 0 end]
    set tot [llength $Complist]
    set Isocomp [lindex $Complist $new_j]

    if {$new_j > $tot} {
    tk_messageBox -message "max reached."
    return
    }

    *createmark comp 1 $Isocomp
    *isolateonlyentitybymark 1 1 2
    hm_viewfit
    incr j
    }

Answers

  • Michael Herve
    Michael Herve
    Altair Employee

    Hello @yeswanth ,

    it seems you are looping on all components belonging to Assembly Pison2D, to isolate and fit (possibly for a screen capture)?

    The recommended way to loop lists in tcl is to use foreach:

    *createmark comp 1 "by assem name" Piston_2D

    set Complist [hm_getmark comp 1]

    foreach Isocomp $CompList {

    *createmark comp 1 $Isocomp

    *isolateonlyentitybymark 1 1 2

    }

    Hope that helps,

    MMichael

  • Yesvanth
    Yesvanth Altair Community Member

    Hello Michael Herve_21439

    Thanks for your inputs

    Actually, I wanted to create an GUI with Next button and to loop over the components

  • Michael Herve
    Michael Herve
    Altair Employee

    Hello Yeshwant,

    sorry I misunderstood your request. What about incrementing j in your proc after the hm_viewfit:

    incr j

    Would that help?

    Best Regards,

    Michael

  • Yesvanth
    Yesvanth Altair Community Member

    no Michael. it is not working

    Regards,

    Yesvanth

  • AndreasAltmann
    AndreasAltmann Altair Community Member
    Answer ✓

    Hello Yesvanth,

    I think you need to declare j as a global variable.
    I would recommend to use a different variable name then j when doing this. Otherwise it will be very likely that you will get conflicts with other scirpts.

    But this should work:

    global j
    set i 0
    set j 0 set win .window
    catch {destroy $win}
    toplevel $win -class TopClass
    wm title $win "Master GUI"
    wm geometry $win 400x200+900+650
    wm resizable $win 0 0
    wm deiconify $win button $win.01 -text "Next" -font {times 15 bold} -command {Script [expr $j + 1]}
    place $win.01 -x 230 -y 130 -width 140 -height 36 proc Script {new_j} {
    global j
    *createmark comp 1 "by assem name" Piston_2D
    set Complist [hm_getmark comp 1]
    set Complist [lrange $Complist 0 end]
    set tot [llength $Complist]
    set Isocomp [lindex $Complist $new_j]

    if {$new_j > $tot} {
    tk_messageBox -message "max reached."
    return
    }

    *createmark comp 1 $Isocomp
    *isolateonlyentitybymark 1 1 2
    hm_viewfit
    incr j
    }
  • Yesvanth
    Yesvanth Altair Community Member

    Hello AndreasAltmann,

    Is working now. Thanks for your inputs.

    Regards,

Welcome!

It looks like you're new here. Sign in or register to get started.

Welcome!

It looks like you're new here. Sign in or register to get started.