As an additional case, to show how DLLs and EXE files can be called from within ADOxx, please find below the script part that shows in a simplifed environment how
a) DLL calls can be used to construct a complex UI dialog
b) EXE calls to the R (http://www.r-project.org/) as an example are available to performed based on model information
c) the model is updated with the results of the calculation and also visually highlights elements (based on a comparison)
Please find attached the AdoScript that is triggered from a menu element, the R implementation to calculate the averages and the necessary parts to update the model. Attached to this post you find the generic implementation as ABL for import, an example model as well as the integrated scripts for R and ADOxx.
1# This script demonstrates how external functionality can be integrated #
2# in ADOxx, using DLL on on hand to provide a custom, complex dialog box, #
3# in a modal format and in a second step to call functionality in an external #
4# tool for calculation purposes. #
5# IMPORTANT: this script does not include any
6
7
8# 0. Initialize variables as default values
9IF (type (c_sActiveFolder) = "undefined") {
10 SETG c_sActiveFolder: "C:\\temp\\"
11}
12IF (type (c_sExtAppPath) = "undefined") {
13 SETG c_sExtAppPath: "C:\\Programme\\R\\R-3.0.2\\bin\\rscript.exe"
14}
15SETG sDataFile: ("ConsumptionInfo.txt")
16SETG sAvgFile: ("AverageInfo.txt")
17
18# 1. Construct a complex dialoag using external DLL calls
19# the necessary DLL is part of the ADOxx installation, the path is relative expressed below
20SET str_DLLPath: ("tools\\misc\\")
21# init the structutur of the dialog, 1 column, 5 rows
22CALL dll: (str_DLLPath + "mDlg.dll")
23 function:"long initMDialog(char* cols, char* rows, char** dummy)"
24 cols: ("1")
25 rows: ("5")
26 dummy:0
27# define width of column
28CALL dll: (str_DLLPath + "mDlg.dll")
29 function:"long setColWidth(char* col, long width, char** dummy)"
30 col: ("1")
31 width:150
32 dummy:0
33# add editbox with defaultvalue
34CALL dll: (str_DLLPath + "mDlg.dll")
35 function:"long setEditBox (char* sColRow, char* sValue, char** dummy)"
36 sColRow: ("1:1")
37 sValue: (c_sExtAppPath)
38 dummy:0
39# add the name of the box
40CALL dll: (str_DLLPath + "mDlg.dll")
41 function:"long setEditBoxCaption (char* sColRow, char* sValue, char** dummy)"
42 sColRow: ("1:1")
43 sValue:"External application path: "
44 dummy:0
45# add a file name identifier
46CALL dll: (str_DLLPath + "mDlg.dll")
47 function:"long setEditBox (char* sColRow, char* sValue, char** dummy)"
48 sColRow: ("1:2")
49 sValue: (c_sActiveFolder)
50 dummy:0
51# add the name of the box
52CALL dll: (str_DLLPath + "mDlg.dll")
53 function:"long setEditBoxCaption (char* sColRow, char* sValue, char** dummy)"
54 sColRow: ("1:2")
55 sValue:"Existing folder to save data: "
56 dummy:0
57# show constructed dialog box
58CALL dll: (str_DLLPath + "mDlg.dll")
59 function:"long showMDlg(char* caption, long hwnd, char** dummy)"
60 caption: ("Example Dialog")
61 hwnd:0
62 dummy:0
63
64# get return values and set accordingly for further processing
65CALL dll: (str_DLLPath + "mDlg.dll")
66 function:"long getEditBoxResult (char* sColRow, char** sResult)"
67 sColRow: ("1:1")
68SETG c_sExtAppPath: (sResult)
69
70CALL dll: (str_DLLPath + "mDlg.dll")
71 function:"long getEditBoxResult (char* sColRow, char** sResult)"
72 sColRow: ("1:2")
73SETG c_sActiveFolder: (sResult)
74
75
76# 2. Export model information for processing, this could also be through a standard interface in ADOxx,
77# in this example we create an own stream.
78
79# get the current model ID
80CC "Modeling" GET_ACT_MODEL
81 # --> RESULT modelid: intValue
82SETL n_ModelID: (modelid)
83CC "Core" GET_ALL_OBJS_OF_CLASSNAME modelid: (n_ModelID) classname:"Car"
84SETL l_CarObjIDs: (objids)
85# export data for each car
86SET sExportString: ""
87FOR s_CarObjID in: ( l_CarObjIDs ) {
88 SET n_CarObjID: ( VAL s_CarObjID)
89 # read the consumption value
90 CC "Core" GET_ATTR_VAL objid: (n_CarObjID) attrname: "Consumption"
91 # --> RESULT ecode: intValue val: anyValue
92 SET sExportString: ( tokunion ( sExportString , STR val , " " ) )
93}
94# write the information to a text file
95SET sConsumptionDataFile: (c_sActiveFolder + sDataFile)
96# add a \n at end for R to understand the input as a table
97CC "AdoScript" FWRITE file: (sConsumptionDataFile) text: (sExportString + "\n") append: 0 binary: 0 base64: 0
98
99
100# 3. Run external functionality to calculate the average of consumption
101# copy R script to the active folder
102CC "AdoScript" COPY_FILES "db:\\calcPowerAvg.r" to: (c_sActiveFolder + "calcPowerAvg.r") overwrite-existing
103
104# call external functionality of R using the script and input from the model
105SET c_sScriptName: (c_sActiveFolder + "calcPowerAvg.r")
106SET c_sAvgDataFile: (c_sActiveFolder + sAvgFile)
107SET sExtCall: (c_sExtAppPath + " " + c_sScriptName + " " + sConsumptionDataFile + " " + c_sAvgDataFile)
108SYSTEM ( sExtCall ) with-console-window
109
110#read return results
111CC "AdoScript" FREAD file: (c_sAvgDataFile)
112 # --> RESULT ecode: intValue text: strValue .
113SET nAvgPwrValue: ( VAL text )
114
115# 4. Read return and update objects, the values are set, and the graphical appearance is changed through a DYE approach
116FOR s_CarObjID in: ( l_CarObjIDs ) {
117 SET n_CarObjID: ( VAL s_CarObjID)
118 # read the consumption value
119 CC "Core" SET_ATTR_VAL objid: (n_CarObjID) attrname: "Average consumption" val: (nAvgPwrValue)
120 CC "Core" GET_ATTR_VAL objid: (n_CarObjID) attrname: "Consumption"
121 # highlight elements in model
122 IF (val > nAvgPwrValue) {
123 CC "Modeling" DYE (n_CarObjID) error-mark
124 }
125}
126CC "AdoScript" INFOBOX "External call to R completed and updated model!"