The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
 All Forums
 Origin Forum
 Origin Forum
 automatic refresh of worksheet with data from file

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
Maersch Posted - 09/01/2005 : 07:04:58 AM
Origin Version: 7.5
Operating System: Windows 2000

Hi,
I want to call origin from another programm.
I want to open origin with a specified *.OPJ-File, for example my_origin.opj (my_origin.opj has a worksheet called Data1 and a Graph called Graph1).

I have imported the data into the my_origin.opj with the import wizard from a file my_data.txt which is in the same folder as the my_origin.opj.

I am using this command to call origin from the command line:
C:\Programme\OriginLab\Origin75>origin75 my_origin.opj

It works fine, Origin is started and the my_origin.opj is loaded.

Now my problem:
The data in the file my_data.txt changes every day.
I do not know how to "refresh" the data in my worksheet automatically
with the new data from the file.

Thank you!
2   L A T E S T    R E P L I E S    (Newest First)
Maersch Posted - 09/09/2005 : 07:50:03 AM
It works. Thank you!!!
easwar Posted - 09/01/2005 : 12:22:29 PM
Hi Maersch,

This can be done with a combination of LabTalk script programming and Origin C code.

Try the following steps and please report back if this does not work.

Easwar
OriginLab

1> Create a new OC file in Code Builder and copy-paste the code pasted below, and save this file in the following location:
<your user files folder>\OriginC\OriginLab\WksImportUsingFilter.c
It is important to name it this way and save in this location to have the rest of the steps work.

Here is the OC code. Make sure you get the #include statements:


#include <Origin.h>
#include <..\OriginLab\fileimport.h>
#include <..\OriginLab\Filter_Utils.h>
////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////
// This function imports specified data file using specified import filter into
// the currently active worksheet.
// It is assumed that the Code Builder workspace already has the necessary files
// needed to call import functions related to the import wizard prior to compiling
// this function.
// In order to set up the workspace one can issue the following command from script:
// %a = system.path.program$;
// iret = run.loadoc(%aOriginC\OriginLab\ImportWiz.ocw);
// if( 0 != iret )
// {
// type -b "Failed to load workspace for importing";
// return;
// }
//
// Parameters:
// strFileName: Name of data file to be imported
// strFilterName: Name of filter file to use for importing.
// If blank, then the function looks for a filter that
// is saved in the worksheet
// Return:
// 0: Success
// -1: Active layer is not a worksheet
// -2: Filter name was blank, and could not find a filter in worksheet
// other: Error values returned by the import function
//
int wks_import_using_filter(string strFileName, string strFilterName = "")
{
Worksheet wks = Project.ActiveLayer();
if( !wks ) return -1;
WorksheetPage wpg = wks.GetPage();

// If filter file name is null...
Tree trFilter;
if( 0 == strFilterName.GetLength() )
{
// Check if there is a filter stored in wks
if( !fuLoadFilterFromPage(trFilter, wpg, FILTER_TYPE_ASCII) )
return -2;
// Import file using filter stored in wks
return ImportFile(wpg, trFilter, strFileName);
}
// If filter file name is not null, import using specified file name
else
return ImportFile(wpg, strFilterName, strFileName);
}




2> Go to your OPJ and import one of your files into the worksheet using the Import Wizard, and in the process save the import settings to a filter file. You can either save the filter right into the worksheet, or if you save to disk, then make sure to save it to your user files folder area.

3> In the worksheet add a new text label. You can give it any text string, such as "oncreate". Then right-click on the text label to bring up Label Control dialog using the context menu

4> In the label control dialog, change the "Script, Run After:" drop-down to "Window Create"

5> In the edit box below the drop-down, enter the following script code:


// First load and compile workspace for Import Wizard
%a = system.path.program$;
iret = run.loadoc(%aOriginC\OriginLab\ImportWiz.ocw);
if( 0 != iret )
{
type -b "Failed to load workspace for importing";
return;
}

// Now load and compile OC file with function to import
iret = run.loadoc(%YOriginC\OriginLab\WksImportUsingFilter.c);
if( 0 != iret )
{
type -b "Failed to load and compile OC file"
return;
}
// Now call OC function to import specific file
iret = wks_import_using_filter("C:\my_data.txt", %YFilters\myfilter.oif);
if( 0 != iret )
{
type -b "Failed to import file";
return;
}




6> In the above script, change the path/name of the data file and filter file as applicable to you, in the line:
iret = wks_import_using_filter("C:\my_data.txt", %YFilters\myfilter.oif);

If you are using a filter saved in the worksheet, then you can leave out the second argument.

7> Clear the data in your wks and save the OPJ

Now when you open the OPJ (manually or programmatically), the worksheet is "created" each time, and at the time of creation the script under step 5 will be executed. This script will load all necessary files into the Code Builder workspace and then will call the custom function in the new OC file to do the import and fill the wks with the new data from your text file.





Edited by - easwar on 09/01/2005 12:24:15 PM

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000