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 for Programming
 Forum for Origin C
 Creating Multiple Graphs from Multiple Worksheets
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

Vainsworth93

USA
8 Posts

Posted - 09/09/2014 :  11:46:47 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): 9.1
Operating System: XP

Hi! I'm an undergrad working on a research project that is to create some code to automate the processing of large amounts of data. I've been able to figure out the multiple import, so there's no problem there, but I can't seem to figure out how to get the information I import to graph, or to have it create a multiple graphs.
Obviously I'm not looking for someone to hand me the answer, but suggestions/advice/a bit of help would be greatly appreciated!

Edited by - Vainsworth93 on 09/09/2014 1:52:33 PM

greg

USA
1378 Posts

Posted - 09/09/2014 :  2:18:38 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Here's a start:
http://ocwiki.originlab.com/index.php?title=Category:Graphing

Where that example says:
gp.Create("Origin");

you can specify any of our built-in graph templates or one of your own custom templates.
Go to Top of Page

Vainsworth93

USA
8 Posts

Posted - 09/09/2014 :  2:45:40 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank You! However, it says that the example you linked is for "multiple layers", will specifying a template allow for multiple single-layered graphs?
Go to Top of Page

Vainsworth93

USA
8 Posts

Posted - 09/09/2014 :  2:59:41 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
At the moment I'm using a code I found in one of the examples within the Origin website. It will only allow me to graph either the very first worksheet or the very last, I've been trying to get it to graph all work sheets into the separate graphs.


void Graph()
{
// Construct the Curve object specifying the x and y datasets to be used for
// the dataplot
Worksheet wks = Project.WorksheetPages(-1).Layers(-1);
if(wks)
{
Curve cc(wks, 0, 1);

// the graph layer needs to be initialized:
GraphPage gp;
gp.Create("Origin");
GraphLayer lay = gp.Layers(0);
if(lay)
{
// Add the dataplot to the graph:
int nIndex = lay.AddPlot(cc, IDM_PLOT_LINE);
lay.Rescale();
// Display the index of the data plot just added:
out_int("Dataplot index = ", nIndex);
}
}
}

void Graph(Folder& fdr, GraphLayer& gl, bool bRecursive = false)
{
if ( !fdr || !gl )
return;

//loop all pages and plot data on worksheets
foreach(PageBase pg in fdr.Pages)
{
if ( pg.GetType() == EXIST_WKS ) //check whether is WorksheetPage
{
WorksheetPage wksPage(pg);
foreach(Layer wkslyr in wksPage.Layers)
{
Worksheet wks(wkslyr);
gl.AddPlot(wks, IDM_PLOT_LINE); //plot all curves from wks to gl, as line
}
}
}
}
Go to Top of Page

greg

USA
1378 Posts

Posted - 09/10/2014 :  09:33:45 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Try removing IDM_PLOT_LINE leaving just

gl.AddPlot(wks); // Use default of IDM_PLOT_UNKNOWN

It's possible there is no matching Line plot style holder in your template in which case the plot will not be added. The AddPlot method returns a -1 ( indicating a problem ) in such cases.
Go to Top of Page

Vainsworth93

USA
8 Posts

Posted - 09/10/2014 :  10:21:04 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Alright! I'll try that, thank you for your help!
Go to Top of Page

Vainsworth93

USA
8 Posts

Posted - 09/11/2014 :  10:36:45 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Okay, so that didn't work, it didn't really change what the program was doing at all, really. Is there a way I could enter a range of (0,-1) [meaning the first to the last worksheet] to be graphed? I've tried to put in that range for this line
Worksheet wks = Project.WorksheetPages(-1).Layers(-1);

but it tells me that "Member function Project::WorksheetPages not defined or does not have matching prototype."
Go to Top of Page

greg

USA
1378 Posts

Posted - 09/11/2014 :  11:56:22 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I tested your code [ the second version without the non-sensical Worksheet wks = Project.WorksheetPages(-1).Layers(-1) ] with the IDM_PLOT_LINE removed and it worked in every release of Origin 9.1.

Using foreach with the Pages collection is the correct approach.
Go to Top of Page

Vainsworth93

USA
8 Posts

Posted - 09/11/2014 :  12:16:44 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I don't understand how you were able to remove the Worksheet wks = Project.WorksheetPages(-1).Layers(-1) line because when I remove it from my code, my output box tells me that the variable 'wks' is no longer defined....
Go to Top of Page

greg

USA
1378 Posts

Posted - 09/12/2014 :  09:25:58 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
As I said .. the SECOND version. Your version of the function with no arguments won't work since
Worksheet wks = Project.WorksheetPages(-1).Layers(-1)
is meaningless.

///// SECOND version /////
void Graph(Folder& fdr, GraphLayer& gl, bool bRecursive = false)
{
if ( !fdr || !gl )
return;

//loop all pages and plot data on worksheets
foreach(PageBase pg in fdr.Pages)
{
if ( pg.GetType() == EXIST_WKS ) //check whether is WorksheetPage
{
WorksheetPage wksPage(pg);
foreach(Layer wkslyr in wksPage.Layers)
{
Worksheet wks(wkslyr);
gl.AddPlot(wks); //plot all curves from wks to gl, as line
}
}
}
}
///// END SECOND version /////

Here is how your first version could be re-written to handle looping over all worksheets in the the project:
void Graph()
{
// Construct the Curve object specifying the x and y datasets to
// be used for the dataplot
foreach(PageBase pg in Project.Pages)
{
if ( pg.GetType() == EXIST_WKS ) //check whether is WorksheetPage
{
WorksheetPage wksPage(pg);
foreach(Layer wkslyr in wksPage.Layers)
{
Worksheet wks(wkslyr);
Curve cc(wks, 0, 1);
// the graph layer needs to be initialized:
GraphPage gp;
gp.Create("Origin");
GraphLayer lay = gp.Layers(0);
if(lay)
{
// Add the dataplot to the graph:
int nIndex = lay.AddPlot(cc, IDM_PLOT_LINE);
lay.Rescale();
// Display the index of the data plot just added:
out_int("Dataplot index = ", nIndex);
}
}
}
}
}

This version creates multiple graphs with one plot rather than one graph with multiple plots. Re-write if you want something else.
Go to Top of Page

Vainsworth93

USA
8 Posts

Posted - 09/16/2014 :  09:39:21 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank you very much, this worked!
Go to Top of Page

Vainsworth93

USA
8 Posts

Posted - 09/30/2014 :  12:26:08 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hey again!
I'm Curious, if I were to want Origin to select files to graph based on their file name, (say, there are two files that both contain '0T' in their file name), so that there would be two layers per graph, where in this code would I edit that in?
Also in what format would I put that? Would I have something similar to gp.getname( "the beginning of the filename \\0T") ?
Go to Top of Page

Sophy

China
Posts

Posted - 10/23/2014 :  03:50:31 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by Vainsworth93

Hey again!
I'm Curious, if I were to want Origin to select files to graph based on their file name, (say, there are two files that both contain '0T' in their file name), so that there would be two layers per graph, where in this code would I edit that in?
Also in what format would I put that? Would I have something similar to gp.getname( "the beginning of the filename \\0T") ?



Hi, I'm not sure what you want(select files to graph base on their file name? what is the file? does it have anything to do with the graph you are creating?). If you want to plot data on a graph of two layers, better create your own template, then when you create a graph with your template, it will already have two layers on it(or you can create with gp.Create("Origin.otp"), and then use gp.AddLayer() to add another layer on it.
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