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

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
}
Best 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
}2
Answers
-
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
0 -
Hello Michael Herve_21439
Thanks for your inputs
Actually, I wanted to create an GUI with Next button and to loop over the components
0 -
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
0 -
no Michael. it is not working
Regards,
Yesvanth
0 -
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
}2 -
0