DDE
DDE-cmd
The dde command provides Dynamic Data Exchange support with Origin as the client application.
Syntax:
dde [option] argument
Options:
-c; Connect to the specified application with the specified topic
Syntax: dde -c application| topic [varID]
Connect to the specified application with the specified topic.The application|topic string should have the application name and topic connected with a "|" character.If the connection is successful, an ID (>= 0) is assigned to the connection and is stored in the specified variable varID. If varID is not specified, the system variable v1 is used. If the connection is not successful, (-1) is stored in the variable.
-d; Disconnect the specified conversation
Syntax: dde -d varID
Disconnect the specified conversation.
-e; Execute the specified command string string in the server application specified by varID
Syntax: dde -e varID string
Execute the specified command string string in the server application specified by varID.
-i; Find the conversation ID for the specified application with the specified topic
Syntax: dde -i application| topic [varID]
Find the conversation ID for the specified application with the specified topic.The application| topic string must have the application name and topic connected with a "|" character. If the specified conversation is found, its ID is stored in the specified variable varID.If varID is not specified, the system variable v1 is used. If the conversation cannot be found, (-1) is stored in the variable.
-l; List all DDE conversations and display them in the Script window
Syntax: dde -l application
List all DDE conversations and display them in the Script window. If application is specified, only those conversations with the specified application are listed.
-lz; List all DDE conversations and put the result into the %Z string
Syntax: dde -lz application
List all DDE conversations and put the result into the %Z string; result is searchable with substring commands. If application is specified, only those conversations with the specified application are listed.
-p; Poke string to the server application as specified by the varID
Syntax: dde -p varID item string
Poke string to the server application as specified by the varID, under the specified item.
-pc; Poke in column order the data from wksItem to the ServerItem with the specified varID
Syntax: dde -pc varID ServerItem wksItem
Poke in column order the data from wksItem to the ServerItem with the specified varID. The ServerItem should specify a range large enough to hold the data range specified by the wksItem.
-pv; Ignore escape sequences and send untranslated text
Syntax: dde -pv varID item string
Ignore escape sequencesand send untranslated text. When using the DDE -p command to send strings, Origin will translate certain sequences of characters beginning with '\' as escape sequences, resulting in the loss of information. For example, a '\t' sequence would translate to a tab character with the result that: dde -p "My files can be found in C:\temp"; would be received as "My files can be found in C: emp"by the DDE Server Application. The -pv command option will cause Origin to ignore the escape sequence and send untranslated text.
-q; Quiet Origin use of DDE warning message boxes
Syntax: dde -q n
Quiet Origin use of DDE warning message boxes. If n = 1, no warning message boxes are displayed. If n = 0, Origin is reset to its normal state.
-r; Request the item item from the server application specified by varID
Syntax: dde -r varID item
Request the item item from the server application specified by varID. The result is placed in the %Z string if the operation is successful.
-rc; Receive in column order the ServerItem with the specified varID into the specified wksItem
Syntax: dde -rc varID ServerItem wksItem
Receive in column order the ServerItem with the specified varID into the specified wksItem. Column type should match the type of data being received. If the wksItem is the dataset name, then data is appended to the first empty row. If you specify a cell with Dataset!RiCj, then data replaces existing data. Data above the replacement point is retained, data below is removed. If you specify a range with Dataset!RiCj:RkCl, then data replaces the existing block of data without removing data below.
|
Note: When you specify the ServerItem to send the dataset, you need know that, the cell-column notation of ServerItem is different in different localized version of Office, such as, when using R1C1 style in a localized version of Excel, you have to use the localized R1C1 string, in German it is Z1S1, in French it is L1C1 and e.g. in Spanish it is F1C1.
For Example, If you have a Excel file which have some data in its sheet1, the script below will work fine in English OS and with English Excel,
dde -c Excel|[Excel1.xls]Sheet1 idxd;
dde -rc idxd R1C1:R5C2 [Book1]Sheet1!R1C1;
If you want run it in German OS with the German Excel, you should modify the second line to be
dde -c Excel|[Excel1.xls]Sheet1 idxd;
dde -rc idxd Z1S1:Z5S2 [Book1]Sheet1!R1C1;
The ServerItem has been changed from R1C1:R5C2 to Z1S1:Z5S2.
|
-rr; Receive in row order the ServerItem with the specified varID into the specified wksItem
Syntax: dde -rr varID ServerItem wksItem
Receive in row order (transpose rows and columns) the ServerItem with the specified varID into the specified wksItem. See the -rc option for additional information.
Examples:
For the following examples, Excel needs to be running. Either launch Excel manually or use the run -e command.
The following script connects to application Excel and topic Sheet1 and remembers the connection as idExcel.
dde -c excel|sheet1 idExcel;
The next script pokes the slope value (LR.B) of the most recent linear regression to Excel row 1, column 1.
dde -p idExcel R1C1 $(LR.B);
This script requests the cell value of row 2, column 1 in Excel and assigns it to the variable value.
dde -r idExcel R2C1;value=%Z;
Here is a more complex script that launches Excel, opens an Excel file, gets data into Origin, performs a Linear Fit and pushes the calculated slope back to Excel.
// Designate the path to the file of interest,
// note that the path cannot include spaces!:
string fp$ = "D:\Files\FileType\Excel\Dose2.xls";
// Launch Excel, and load desired file:
run -e "C:\Program Files\Microsoft Office\OFFICE11\excel.exe" %(fp$);
// Wait for a good connection
for( ready = 0, attempts = 0 ; ready == 0 && attempts < 10 ; attempts++ )
{
dde -c Excel|System idSys;
sec -p 1;
if(idSys >= 0) ready=1;
}
if(attempts >= 10)
{
type -a Request timed out. Terminating...;
break1;
}
else
{
type -a Connected, retrieving info.;
}
// Request Topics
dde -c Excel|System idSys;
dde -r idSys Topics;
// and display them
type -a List of Topics available.;
for( done = 0, ii = 1 ; done == 0 ; ii++ )
{
%A=%[%Z,#ii];
if(%[%A]>0) type %A; else done = 1;
}
// New connection to another Topic
dde -c Excel|[Dose1.xls]Sheet1 idxd;
// Request data
dde -rc idxd R2C1:R11C2 [Book1]Sheet1!R1C1;
// Do a linear fit
lr col(2);
%A = "Slope is $(lr.b)";
// Push result to Excel
dde -p idxd R1C3:R1C3 %A;
// Terminate connections
dde -d idxd;
dde -d idSys;
|