Dear University of Vienna team,
the issue you observe relates to how the SET_ICON_CLICK_HDL is intepreted by the platform. You need to modify the statement to add the "raw" command to make it work. Please find below the definition of the command:
Description:
SET_ICON_CLICK_HDL changes the click handler (the function which is executed on a click) of a smart icon. Smart icons can be defined within the library attribute "External coupling" using the "AppInitialized" event.
1CC "Application" [ raw* ] SET_ICON_CLICK_HDL [ component:Component ] name:strValue { AdoScript }
2Component: "acquisition" | "modeling" | "analysis" |"simulation" | "evaluation" | "importexport" | "all"
3--> RESULT ecode:intValue .
The name of a custom smart icon is the name specified at INSERT_ICON. The names of the built-in smart icons are listed in the SET_ICON_VISIBLE documentation.
* The
raw argument at the CC element may be of importance here! Without specifying raw, variables used in the handler are replaced by the current values of these variables. If the handler just calls a global procedure without parameters, raw is not needed. In any other case raw is important to allow the definition of new variables in the script.
As an example, please find attached to this post a sample implementation that shows how to
- Invoke a script within a file (scenario 2) from an icon
- Invoke a script within the library attribute (scenario 3) an icon
- Invoke the same script in an event handler
The sample code is also shown below. To include and test by yourself, please modify/add the following snipplet to the "External coupling" library attribute within the dynamic library.
1ON_EVENT "AppInitialized" {
2
3 # add an icon handler for the file-based execution
4 CC "Application" INSERT_ICON component: "all" name: "GetModelIDFileExecute" bitmap:"db:\\icon1.bmp" text:"Get Model ID (execute file)"
5 # here "raw" is not needed, since the file is handled as an encapsulated procedure
6 CC "Application" SET_ICON_CLICK_HDL name:"GetModelIDFileExecute" {
7 EXECUTE file: ("db:\\HDLAdoScript.asc")
8 }
9
10 # add an icon handler for the file-based execution
11 CC "Application" INSERT_ICON component: "all" name: "GetModelIDAdoScriptExecute" bitmap:"db:\\icon2.bmp" text:"Get Model ID (AdoScript in HDL)"
12 # "raw" is important here, since the code should be interpreted and no variables are set
13 CC "Application" raw SET_ICON_CLICK_HDL name:"GetModelIDAdoScriptExecute" {
14 CC "Modeling" GET_ACT_MODEL
15 SET id_ActModel: ( modelid )
16 CC "AdoScript" INFOBOX ("Return from direct invocation: " + STR id_ActModel + "!")
17 }
18
19}
20
21ON_EVENT "AfterCreateModelWindow" {
22#This event is triggered after a new model window was created in the modelling editor.
23# modelid contains the model ID of the model in question.
24
25 CC "AdoScript" INFOBOX "Execute during event from direct implementation"
26 CC "Modeling" GET_ACT_MODEL
27 SET id_ActModel: ( modelid )
28 CC "AdoScript" INFOBOX ("Return from direct invocation (in event) " + STR ( id_ActModel ) + "!")
29}
30
31
32.