Author |
Topic |
|
Vainsworth93
USA
8 Posts |
Posted - 09/09/2014 : 11:46:47 AM
|
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 |
|
Vainsworth93
USA
8 Posts |
Posted - 09/09/2014 : 2:45:40 PM
|
Thank You! However, it says that the example you linked is for "multiple layers", will specifying a template allow for multiple single-layered graphs? |
|
|
Vainsworth93
USA
8 Posts |
Posted - 09/09/2014 : 2:59:41 PM
|
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 } } } } |
|
|
greg
USA
1378 Posts |
Posted - 09/10/2014 : 09:33:45 AM
|
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. |
|
|
Vainsworth93
USA
8 Posts |
Posted - 09/10/2014 : 10:21:04 AM
|
Alright! I'll try that, thank you for your help! |
|
|
Vainsworth93
USA
8 Posts |
Posted - 09/11/2014 : 10:36:45 AM
|
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."
|
|
|
greg
USA
1378 Posts |
Posted - 09/11/2014 : 11:56:22 AM
|
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. |
|
|
Vainsworth93
USA
8 Posts |
Posted - 09/11/2014 : 12:16:44 PM
|
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.... |
|
|
greg
USA
1378 Posts |
Posted - 09/12/2014 : 09:25:58 AM
|
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. |
|
|
Vainsworth93
USA
8 Posts |
Posted - 09/16/2014 : 09:39:21 AM
|
Thank you very much, this worked! |
|
|
Vainsworth93
USA
8 Posts |
Posted - 09/30/2014 : 12:26:08 PM
|
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") ? |
|
|
Sophy
China
Posts |
Posted - 10/23/2014 : 03:50:31 AM
|
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. |
|
|
|
Topic |
|