Query in Calling TCL script from another TCL script

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

Hi,

I have created a UI with OK and CANCEL button. (Please refer UI.tcl)

Inside OK Command, I am calling another tcl file Sample.tcl.

Both the tcl files are in the same location

 

source command work fine If I provide the absolute path of the Sample.tcl.

 

source C:/Sample.tcl

 

 

But I am getting 'File not found error' for the following code

 

 variable macro_directory [file dirname [info script]];

 set tclFileName $macro_directory/Sample.tcl; 

 source $tclFileName;

 

Please help.

 

Please find the codes below:

 

UI.tcl


package require hwt;
package require hwat;
#######################################################
#######################################################
###GUI CREATION
#######################################################
#######################################################
namespace eval ::MyNameSpace::UI {
variable m_base
variable m_master_frame
}
#########################################################
proc ::MyNameSpace::UI::CreateActionFrame { } {

#Action Frame
set action_frame [frame $::MyNameSpace::UI::m_master_frame.action_frame -height 100 -width 100];
pack $action_frame -side top -anchor nw;

button $action_frame.ok_btn -text 'OK' -borderwidth 3 -width 10 -command '::MyNameSpace::UI::OnOk'
pack $action_frame.ok_btn -side left -padx [list 337 0] -pady 10 -in $action_frame

button $action_frame.cancel_btn -text 'CANCEL' -borderwidth 3 -width 10 -command '::MyNameSpace::UI::OnCancel'
pack $action_frame.cancel_btn -side left -padx [list 20 0] -pady 10 -in $action_frame

}
#########################################################
proc ::MyNameSpace::UI::DestroyDialog { } {

#Delete m_base
if {[info exists ::MyNameSpace::UI::m_base]} {
destroy $::MyNameSpace::UI::m_base

}

}
#########################################################
proc ::MyNameSpace::UI::OnOk { } {

variable macro_directory [file dirname [info script]];
set tclFileName $macro_directory/Sample.tcl;
source $tclFileName;



}
#########################################################
proc ::MyNameSpace::UI::OnCancel { } {

::MyNameSpace::UI::DestroyDialog

}
#########################################################
proc ::MyNameSpace::UI::Main { } {

#Delete if m_base exist
if {[info exists ::MyNameSpace::UI::m_base]} {
destroy $::MyNameSpace::UI::m_base
}

#Set value for m_base
set ::MyNameSpace::UI::m_base .bjaDialog
toplevel $::MyNameSpace::UI::m_base

#Dialog title
wm title $::MyNameSpace::UI::m_base 'My Script'
wm resizable $::MyNameSpace::UI::m_base 0 0

#Create Master Frame in Base
set ::MyNameSpace::UI::m_master_frame [frame $::MyNameSpace::UI::m_base.m_master_frame];
pack $::MyNameSpace::UI::m_master_frame -side top -anchor nw -padx 7 -pady 7 -expand 1 -fill both;

#Create Action Frame and add to Master Frame
::MyNameSpace::UI::CreateActionFrame

}
#########################################################
#Call Main
::MyNameSpace::UI::Main;

Sample.tcl


package require hwt;
package require hwat;
namespace eval ::MyNameSpace::MyScript {

}
proc ::MyNameSpace::MyScript::Main { } {

tk_messageBox -message 'Hello World!';

}

::MyNameSpace::MyScript::Main;
Tagged:

Answers

  • tinh
    tinh Altair Community Member
    edited February 2015

    Hi,

    In your case you should put info script command in body of namespace eval

    (do not put it inside body of a proc)

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited February 2015

    Modified as per you reply and it is working. Thank you very much.

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.