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
 Automatically execute Adjacent Averaging
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

soltyr

3 Posts

Posted - 07/16/2015 :  09:28:01 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): 7.5 SR4
Operating System: Windows 7 (64 bit)

Hi there,

I am new to Origin. We use it in our company but now there is someone who wants something special and I really need your help.

We create txt files with time and value automatically in C#. After that we take those txt files and open it as a worksheet and say column 1 is time and column 2 is value. We also have a lot of graph template files. An ogs files maps my values from the worksheet to my graph template. At the end we have really nice graph files. This is pretty much straight forward, not really complicated and a lot of copy & paste work.

Now there is that guy who wants to have an Adjacent Averaging Smoothing on one graph. Okay, he showed me how he does it.
He clicks on the data in the graph then Analysis -> Smoothing -> Adjacent Averaging.

My question, how can I execute everything (Analysis -> Smoothing -> Adjacent Averaging) automatically after the project was opened? Is it possible to record a macro, as in Excel?

I also have to confess that I am not familiar with Labtalk or Origin C.

Another solution for me would be to implement the Adjacent Averaging Algorithm in C# and create a worksheet and do the mapping. But I think there should / could be an easier way in Origin itself.

Thanks in advance

Soltyr

cdrozdowski111

USA
247 Posts

Posted - 07/16/2015 :  12:21:03 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Soltyr,

Origin has very nice features called Analysis Templates and Batch Processing that let you automate your data transformation and analysis routines and apply them to as many data files/sources as you need. You should definitely check them out.

http://www.originlab.com/index.aspx?go=Products/Origin/DataAnalysis/AnalysisTemplates

http://www.originlab.com/doc/X-Function/ref/batchProcess

Thanks,
Chris
Go to Top of Page

snowli

USA
1386 Posts

Posted - 07/16/2015 :  10:03:33 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hello,

This is doable without the need of much programming skill.

Here is how to do it:

1. Generate the code that does smoothing:
In one of your graph, choose Analysis: Signal Processing: Smooth...
Set all controls as you like. E.g. method as Adjacent Averaging, Recalculation Mode to Auto, etc.

Now, click the > button next to Dialog Theme, and choose Generate Script
E.g.
smooth -r 1 method:=aav;
is dumped in Script window.

This is the code to run smoothing with adjacent averaging method. Also the recalculation mode is Auto.

2. Code to loop through all graph windows:
If you google "labtalk loop graph windows", you will find the following page to loop though all kinds of Origin objects, e.g. graph windows, worksheets, etc.
http://www.originlab.com/doc/LabTalk/guide/Looping-Over-objs#Looping_Over_Graph_Windows

doc -e LP is for looping through all graph windows
So I can change the code as

//start
doc -e LP
{
// Skip over any embedded graphs or Layout windows
if(page.IsEmbedded==0&&exist(%H)!=11)
{
smooth -r 1 method:=aav; }
}

In any opj, if you choose WIndow: Script Window menu to open Script window.
copy and paste the above code there. Highlight all and press Enter. It will loop through all graph windows and do smoothing.


3. To run the code automatically after opening an opj
Each opj has its corresponding ProjectEvents.ogs to execute script after open, before save and before closing, etc.

So open your opj (without smoothing done yet), choose View: Code Builder.. to open Code Builder.
In Code Bulder, in left workspace, expand Project node and double click ProjectEvents.ogs

Enter the above code at the end of [AfterOpenDoc] section.
Click the Save button in Code Builder to save the ogs file.
Close Code Builder.
Go back to Origin and save the opj again.

Now whenever you load this opj file, the smoothing will loop through all graph windows automatically.

Thanks, Snow Li
OriginLab Corp.

Edited by - snowli on 07/17/2015 01:59:27 AM
Go to Top of Page

soltyr

3 Posts

Posted - 07/20/2015 :  09:38:41 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi there,
so first I really want to thank you for your help and support. You helped me a great deal.
But I got two more question.

1. I had to change the Origin.ini File so it would execute the AfterOpenDoc Event. Is this a project setting or installation setting?

2. In Origin 9.1 it works with following code.

[AfterOpenDoc]
window -a Graph13;
layer -s 1;
smooth -r 1 method:=aav npts:=50;
window -a Graph13;
layer -s 3;
smooth -r 1 method:=aav npts:=50;


But it won't work in Origin 7.5. Within the Script Window I always receive the error

SMOOTH-R1METHOD:
#Command Error!


Is this because the smooth command is not implemented in Origin 7.5?

Again I really appreciate your help.

Thanks in advance.

Soltyr
Go to Top of Page

snowli

USA
1386 Posts

Posted - 07/20/2015 :  10:45:29 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hello,

Since 8.0, we used xfunction for many tools, such as smoothing, etc.

So before 8.0, e.g. 7.5, smooth command I said would not work.

BTW, there is no need to change Origin.ini to execute ProjectEvents.ogs which is saved with its opj file.

But in 7.5, there is no ProjectEvents.ogs file. That's why you used ini but that's not associated with a single opj.


Thanks, Snow
Go to Top of Page

soltyr

3 Posts

Posted - 07/22/2015 :  08:37:59 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi there,
I know I am really annoying.
On Monday the script in the ProjectEvents.ogs file worked really great. I have to confess I created my own file and added it in the CodeBuilder Project section.

But now I made some changes and somehow when I start my project the AfterOpenDoc event is not executing anymore.

How can I check why my AfterOpenDoc Event is not working anymore?

Again many thanks
Soltyr
Go to Top of Page

snowli

USA
1386 Posts

Posted - 07/22/2015 :  09:44:16 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I am not sure if why you need to manually create projectevents.ogs.

If possible, could you send the opj to tech@originlab.com so that we could take a look.

Attn: Snow.

Thanks, Snow
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