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
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum
 Origin Forum
 automatic refresh of worksheet with data from file
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

Maersch

Germany
Posts

Posted - 09/01/2005 :  07:04:58 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
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!

easwar

USA
1965 Posts

Posted - 09/01/2005 :  12:22:29 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
Go to Top of Page

Maersch

Germany
Posts

Posted - 09/09/2005 :  07:50:03 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
It works. Thank you!!!
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000