Run TCL script using button

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

Hello all
How I can run .tcl script using a button?
I searched a lot of information, but can't found

I have a procedure:

 proc add_button {title command} {   global frame count   button $frame.$count -text $title -command $command -font 'arial 10'   pack   $frame.$count -side top -pady 1 -padx 1 -fill x   incr count }

Then I call it:
 

 add_frame  'TCL' add_button 'test open file'     {*readfile 'C:/temp/11.tcl'} add_button 'test open file 2'       {*readfile 'C:/temp/clip.hm'}

But opening a .hm file works good, but .tcl does not work and I have an error:
 

 0 0     while executing '*readfile 'C:/temp/11.tcl''     invoked from within '.buttons.frame15.18 invoke'     ('uplevel' body line 1)     invoked from within 'uplevel #0 [list $w invoke]'     (procedure 'tk::ButtonUp' line 24)     invoked from within 'tk::ButtonUp .buttons.frame15.18'     (command bound to event)


Can everyone explain me how correct this error or how can I run a .tcl file using buttons?

Answers

  • Q.Nguyen-Dai
    Q.Nguyen-Dai Altair Community Member
    edited March 2019

    Maybe try 'userpage.mac' ? Here's from my userpage.mac

     *createbutton(5,'NASTRAN',   5, 0, 5, GREEN,'Export to Nastran',EvalTcl,'HM2Nastran.tcl') *createbutton(5,'SAMCEF',    5, 5, 5, GREEN,'Export to Samcef ',EvalTcl,'HM2Samcef.tcl')

    All my scripts found in the directory defined in environment variable 'TCL_INCLUDE'