HyperWorks Tools

Tcl

Tcl

Previous topic Next topic Expand/collapse all hidden text  

Tcl

Previous topic Next topic JavaScript is required for expanding text JavaScript is required for the print function  

While writing Tcl scripts, it is important to keep in mind that the same script works interactively (with the GUI) and in Replay mode.

hmtoggle_plus1greyThe Namespace

Scripts that are hooked up to the tasks in the process must be name spaced. The Process Manager engine creates the namespace and the modules must be in that namespace.

::hw::pmgr::${::hw::pmgr::namespace}::DisplayWnd {} 

For example, Process Manager expects the functions shown above to exist in the namespace shown.

hmtoggle_plus1greyMain Functions Expected in the Tcl Script

There are four main procedures expected in the Tcl script, which are expected to do the following tasks:

DisplayWnd

Create the UI components.
Associate a namespace/member variable for each UI component.
GetDataFromDataModel to initialize the member variables (and the UI from a previous session).

proc ::hw::pmgr::${::hw::pmgr::namespace}::DisplayWnd {}

variable mainWnd;

variable id;

variable m_strFileName;  

set mynamespace ::hw::pmgr::${::hw::pmgr::namespace};

 

if {[WndExists] == 0}

CreateWnd "HWPM -- Load Template" "Import"

 

# Create all the UI components

set txtFileName [entry $mainWnd.txtFileName -font [hwt::AppFont] \

-textvariable ${mynamespace}::m_strFileName -width 60]

 

.

.

.

 

#Get the data from the DataModel and update the UI

GetDataFromDataModel;  

}

return 0;

}

 

SetDataInDataModel

 

·        Checks to see if any of the member variable values have changed from what is currently in the DataModel.

Set the changed values in the DataModel.
If nothing has changed, "RestoreOriginalState."

proc ::hw::pmgr::${::hw::pmgr::namespace}::SetDataInDataModel {}

variable mainWnd;

variable id;

variable m_strFileName;

 

set nDataChanged 0;

 

# Set all the data from the UI into the data model.

# As we set, check if the data has changed

 

#Set the HM filename in the data model

if {$m_strFileName != \

[::hw::pmgr::PmgrGetData $id ${id}::HM_FILENAME]}

::hw::pmgr::PmgrSetData $id ${id}::HM_FILENAME $m_strFileName;

set nDataChanged 1;

}

 

if {$nDataChanged == 0}

RestoreOriginalState;

};

}

GetDataFromDataModel

·        Get data from the DataModel and initialize the member variables.

·        If the value of the data from the DataModel is "", initialize the member variable with default value.

proc ::hw::pmgr::${::hw::pmgr::namespace}::GetDataFromDataModel {}

variable mainWnd;

variable id;

variable m_strFileName;

 

#Get the HM filename in the data model

set m_strFileName [::hw::pmgr::PmgrGetData $id ${id}::HM_FILENAME];

if {$m_strFileName == ""}

set m_ strFileName "D:/altair/demos/hm/bumper.hm"

}

}

Exec

·        This is the heart of the module and will do whatever needs to be done by the module.

Relies exclusively on member variables for data.
Does not get data from the UI components.
hmtoggle_plus1greyVariables and Methods Created in the Module's Namespace

CreateWnd

·        This method will create a window with the Apply, Next, Prev, Cancel buttons.

This window will be embedded in the panel region of HyperWorks (or the float, if it cannot be embedded).
Takes the name of the window and text to appear on the Apply button as arguments.

WndExists

·        Will be implemented in the future.

Will not be recreating the window if it has already been created.
This function will return 0 if the window has never been created.
This function will return 1 and display the window if the window has already been created.
Currently, this function always returns 0.

RestoreOriginalState

·        This method will restore the (completion) state of the task to what it was prior to you visiting/revisiting the task.

Will be called by the module if you leave the task without executing it or changing any of its data.

variable id

·        This variable is set as the name of the task.

Will be useful in prefixing/namespacing data that will be stored in the DataModel.
This will be a key argument for all of the Tcl APIs provided by the Process Manager framework.

Variable mainWnd

·        The CreateWnd method sets this variable.

It is the window handle.
The module will add more UI components to this window based on the requirements of the module.

 

#######################################################################

#  Create the UI components in the window

#######################################################################

proc ::hw::pmgr::${::hw::pmgr::namespace}::DisplayWnd {}

variable mainWnd;

variable id;

 

if {[WndExists] == 0}

CreateWnd "HWPM -- Load Template" "Apply"

 

 

# Add other components to the UI

set lblTpl [label $mainWnd.lblwip -text "Madymo template:" \

-font [hwt::AppFont] -anchor w];

set txtfldMadFileName [entry $mainWnd.madymofile \

-font [hwt::AppFont] -width 60]

set btnMadFBrowser [button $mainWnd.fb -text " Browse... " \

-command  "::hw::pmgr::${::hw::pmgr::namespace}::OnBrowseMadymoFile" \

-font [hwt::AppFont]];

pack $ lblTpl $txtfldMadFileName $btnMadFBrowser \

-side left -padx 5 -pady 5

 

#Get the data from the DataModel and update the UI

GetDataFromDataModel

}

return 0;

}