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
 Name Plots in Project Explorer

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
CMRR2D Posted - 03/03/2015 : 12:03:31 AM
Origin Ver. and Service Release (Select Help-->About Origin): 9.0.0
Operating System: Windows XP

Hi,

I'm using an automatic plotting program to do line plots. To make things easier, when my plot is outputted, I'd like to be able to name the plot in the project explorer and also maybe in the legend of the plot itself. How can I implement this? Here is the code I'm using.

foreach(WorksheetPage wp in Project.WorksheetPages)
	{
		if(wp.IsValid())
		{
			for(int iWks=0; iWks<wp.Layers.Count(); iWks++)  // all worksheets in worksheet page
			{
				Worksheet wks = wp.Layers(iWks);  // get worksheet
				if(wks.IsValid())
				{
					GraphPage gp;
					gp.Create("Line");  // create graph page
					gp.SetName(wks.GetName());  // set graph page name
					GraphLayer gl = gp.Layers(0);  // get graph layer in graph page

					Curve crv(wks,0,1);
					int nPlot = gl.AddPlot(crv, IDM_PLOT_LINE);
					gl.GroupPlots(0);  // group all plots in the graph layer
					gl.Rescale();  // rescale graph layer
					printf("\tPlotted: %s\n", wks.GetName());  // name of graph page

				}
			}
		}
	}


Thank you,

James
11   L A T E S T    R E P L I E S    (Newest First)
yuki_wu Posted - 01/04/2018 : 01:04:23 AM
Hi Claire,

Try to modify your script as below:

doc -e LW 
{
string gwname$ = layer.name$ + "-" + wcol(1)[C]$;
range r1 = 2; 
range r2 = 3; 
plotxy iy:=r1 plot:=200 ogl:=[<new template:=V3_Phase name:=%(gwname$)>]; 
plotxy iy:=r2 ogl:=2 plot:=200; 
}


More examples can be found on this page:
https://www.originlab.com/doc/X-Function/ref/plotxy

Hope it helps.

Regards,
Yuki
OriginLab
CZA Posted - 12/18/2017 : 11:49:52 AM
Hello
I have tried to retrieve the script here above (http://www.originlab.com/forum/topic.asp?whichpage=1&TOPIC_ID=20405#29887) and to transform it so that I can trace double Y instead of scatter (my doubley template is named V3_Phase.otp), but I still want get the plots renamed with the sheet name appended (concatened ?) with the comment (3rd row) of the first column of each sheet.
So I modified the script like this :
doc -e LW
{
// layer.name$ is current worksheet name
// wcol(1)[C]$ is Comments in first column
string gwname$ = layer.name$ + "-" + wcol(1)[C]$;
// define ranges
range r1 = 2; // Column 2
range r2 = 3; // Column 3
win -t plot V3_Phase; // Load double Y personal template
plotxy iy:=r1 ogl:=1 plot:=200; // Plot column 2 into layer1 (Line)
plotxy iy:=r2 ogl:=2 plot:=200; // and col 3 into layer2 (line)

}

It works fine, traces all my plots in one shot, with the style I am expecting, except that it does not rename the graphs (and I get graph1, graph2...)

Then I tried to re-run the initial script (that use to run nicely some time ago as far as I recall…):

doc -e LW
{
// layer.name$ is current worksheet name
// wcol(1)[C]$ is Comments in first column
string gwname$ = layer.name$ + "-" + wcol(1)[C]$;
// Replace Scatter with your graph template name
plotxy (1,2) ogl:=[<new template:=Scatter name:=%(gwname$)>];
};

It gives me the following error message
“Error: value mT is missing a variable name” (44 times for 11 graphs !)
Note that my comments in the 1rst column are in the shape xx mT where xx is a number and mT is a character string that stands for units (millitesla).
Could you please tell me what’s wrong with the renaming procedure?
Thanks
Claire
CZA Posted - 03/11/2015 : 06:12:56 AM
Many thanks, you are my savior !

CZA
SeanMao Posted - 03/11/2015 : 02:34:07 AM
Hi,

In your case, you only need few lines of LabTalk scripts.


doc -e LW 
{
//	layer.name$ is current worksheet name
//      wcol(1)[C]$ is Comments in first column
string gwname$ = layer.name$ + "-" + wcol(1)[C]$;
//	Replace Scatter with your graph template name
plotxy (1,2) ogl:=[<new template:=Scatter name:=%(gwname$)>]; 																					
}																					


The code will loop through all worksheets in current workbook and make a plot with data from column A (index 1) as X and column B (index 2) as Y using graph template "Scatter" and append worksheet name plus comments in first column as current graph window name.

To run the script for your own settings, you need to make sure you firstly replace "Scatter" to be the template name you are using.

After that with the workbook stored data active, open Script Window from menu Window:Script Window and input above codes in Script Window, highlight all code lines and hit Enter key.

It shall "batch plot" using worksheet name plus comments in first column as graph window name.

Any problems, please feel free to post back!

Best regards!

Sean

OriginLab Tech. Service

CZA Posted - 03/09/2015 : 1:46:26 PM
Hello
I have a similar problem. Except that I am not much of a programmer, so the program hereafter looks a litlle bit like chinese to me.
I use ASCII data that I import with the proper filter so that they distribute in different worksheets in the same book, than I draw one plot and use "duplicate (batch plotting" to get all the other graphs on the same model. It work nicely except that I can't rename the graphs and they automatically get named "Duplicate with [Book blablabla.."
How can I get them automatically renamed?
Better than this, how could I get them automatically renamed with the sheet name appended (concatened ?) with the comment (3rd row) of the first column of each sheet ?
If a similar as below program is needed, please make it “for dummies”: when have I to apply it, where should I put it, how should I name it, recall it…
PS I use 9.1 version
Thanks in advance (note that I am also a dummy for the use of forum too, I hope I made it rigth)
Claire

quote:
Originally posted by CMRR2D

Origin Ver. and Service Release (Select Help-->About Origin): 9.0.0
Operating System: Windows XP

Hi,

I'm using an automatic plotting program to do line plots. To make things easier, when my plot is outputted, I'd like to be able to name the plot in the project explorer and also maybe in the legend of the plot itself. How can I implement this? Here is the code I'm using.

foreach(WorksheetPage wp in Project.WorksheetPages)
	{
		if(wp.IsValid())
		{
			for(int iWks=0; iWks<wp.Layers.Count(); iWks++)  // all worksheets in worksheet page
			{
				Worksheet wks = wp.Layers(iWks);  // get worksheet
				if(wks.IsValid())
				{
					GraphPage gp;
					gp.Create("Line");  // create graph page
					gp.SetName(wks.GetName());  // set graph page name
					GraphLayer gl = gp.Layers(0);  // get graph layer in graph page

					Curve crv(wks,0,1);
					int nPlot = gl.AddPlot(crv, IDM_PLOT_LINE);
					gl.GroupPlots(0);  // group all plots in the graph layer
					gl.Rescale();  // rescale graph layer
					printf("\tPlotted: %s\n", wks.GetName());  // name of graph page

				}
			}
		}
	}


Thank you,

James



CZA
SeanMao Posted - 03/04/2015 : 8:48:31 PM
Hi,

I am not sure when you mean "Data Tile". Is it the column Long Name of the dataset?

The code you wrote will assign worksheet name as the Legend for every data plot you made. If the worksheet names are the same, the legend name should be the same.

The following code will use column Long Name as Legend instead, see if this is what you want:


	foreach(PageBase pg in Project.ActiveFolder().Pages)
	{
		WorksheetPage wp(pg);	// Narrow criteria to only worksheet pages
		if(wp.IsValid())
		{
			for(int iWks=0; iWks<wp.Layers.Count(); iWks++)  // all worksheets in worksheet page
			{
				Worksheet wks = wp.Layers(iWks);  // get worksheet
				if(wks.IsValid())
				{
				
					GraphPage gp;
					string legendname;
					gp.Create("Line");  // create graph page
					gp.SetName(wks.GetName());  // set graph page name
					GraphLayer gl = gp.Layers(0);  // get graph layer in graph page

					Curve crv(wks,0,1);
					int nPlot = gl.AddPlot(crv, IDM_PLOT_LINE);
					legend_append_plot(gl, nPlot, "@L"); //Use Column Long Name (Data Tile) as Legend
					
					
					gl.GroupPlots(0);  // group all plots in the graph layer
					gl.Rescale();  // rescale graph layer
					//legendname = wks.GetName();
					//gl.LT_execute("legend");
					//GraphObject golegend = gl.GraphObjects("legend");
					//golegend.Text = legendname;
					
					printf("\tPlotted: %s\n", wks.GetName());  // name of graph page
				}
			}
		}
	}


where I simply use "@L" to replace "@WS" to serve the purpose.

Any questions, please proceed to ask or send your opj file to tech@originlab.com and detailed requirements along in the email.

Regards!

Sean
CMRR2D Posted - 03/04/2015 : 04:33:17 AM
Update: even when taking out the code I added there seems to be a strange problem. The legend title no longer updates - it only takes the long name of the first data set it plots, and assigns every other data plot after that the first legend name. Not Sure why this is happening.
CMRR2D Posted - 03/04/2015 : 04:19:58 AM
Another Question-

I add these lines to the code so that I can get an graph legend to be the same as the data title

foreach(PageBase pg in Project.ActiveFolder().Pages)
	{
		WorksheetPage wp(pg);	// Narrow criteria to only worksheet pages
		if(wp.IsValid())
		{
			for(int iWks=0; iWks<wp.Layers.Count(); iWks++)  // all worksheets in worksheet page
			{
				Worksheet wks = wp.Layers(iWks);  // get worksheet
				if(wks.IsValid())
				{
				
					GraphPage gp;
					string legendname;
					gp.Create("Line");  // create graph page
					gp.SetName(wks.GetName());  // set graph page name
					GraphLayer gl = gp.Layers(0);  // get graph layer in graph page

					Curve crv(wks,0,1);
					int nPlot = gl.AddPlot(crv, IDM_PLOT_LINE);
					legend_append_plot(gl, nPlot, "@WS"); //Use Sheet Name as Legend
					
					
					gl.GroupPlots(0);  // group all plots in the graph layer
					gl.Rescale();  // rescale graph layer
					legendname = wks.GetName();
					gl.LT_execute("legend");
					GraphObject golegend = gl.GraphObjects("legend");
					golegend.Text = legendname;
					
					printf("\tPlotted: %s\n", wks.GetName());  // name of graph page

				}
			}
		}
	}


And the append_legend_plot does not seem to be working anymore. The output for all plots legend titles are the same when they shouldn't be. Any thoughts?
SeanMao Posted - 03/03/2015 : 8:58:53 PM
Hi,

The code is as following:


	foreach(PageBase pg in Project.ActiveFolder().Pages) // Get all pages in active folder
	{
		WorksheetPage wp(pg);	// Narrow criteria to only worksheet pages
		
		if(wp.IsValid())
		{
			for(int iWks=0; iWks<wp.Layers.Count(); iWks++)  // all worksheets in worksheet page
			{
				Worksheet wks = wp.Layers(iWks);  // get worksheet
				if(wks.IsValid())
				{
					GraphPage gp;
					gp.Create("Line");  // create graph page 
					gp.SetName(wks.GetName());  // set graph page name
					GraphLayer gl = gp.Layers(0);  // get graph layer in graph page
					
					Curve crv(wks,0,1);
					int nPlot = gl.AddPlot(crv, IDM_PLOT_LINE);
					legend_append_plot(gl, nPlot, "@WS"); //Use Sheet Name as Legend
					gl.GroupPlots(0);  // group all plots in the graph layer
					gl.Rescale();  // rescale graph layer
					printf("\tPlotted: %s\n", wks.GetName());  // name of graph page

				}
			}
		}
	}


Regards!

Sean
CMRR2D Posted - 03/03/2015 : 4:46:47 PM
Sean,

Thank you so much for your quick reply! I have one more additional question. This program plots all worksheets in the entire project- is there a way to have the program plot only the worksheets in the active folder?

Thanks again,

James
SeanMao Posted - 03/03/2015 : 04:30:22 AM
Hi,

I added one more line as shown below:


foreach( WorksheetPage wp in Project.WorksheetPages )
	{
		if(wp.IsValid())
		{
			for(int iWks=0; iWks<wp.Layers.Count(); iWks++)  // all worksheets in worksheet page
			{
				Worksheet wks = wp.Layers(iWks);  // get worksheet
				if(wks.IsValid())
				{
					GraphPage gp;
					gp.Create("Line");  // create graph page 
					gp.SetName(wks.GetName());  // set graph page name
					GraphLayer gl = gp.Layers(0);  // get graph layer in graph page
					
					Curve crv(wks,0,1);
					int nPlot = gl.AddPlot(crv, IDM_PLOT_LINE);
					legend_append_plot(gl, nPlot, "@WS"); //Use Sheet Name as Legend
					gl.GroupPlots(0);  // group all plots in the graph layer
					gl.Rescale();  // rescale graph layer
					printf("\tPlotted: %s\n", wks.GetName());  // name of graph page

				}
			}
		}
	}


The command line you are using "gp.SetName(wks.GetName());" actually set the Short Name of current graph page and it will be shown as the window name accordingly in Project Explorer.

I added a command line "legend_append_plot(gl, nPlot, "@WS");" to allow you define the legend of current data plot.

The legend substitution notation can be found on this link below:

http://www.originlab.com/doc/LabTalk/ref/Legend-Substitution-Notation

Examples about the function legend_append_plot() is in this page:
http://www.originlab.com/doc/OriginC/ref/legend_append_plot

Regards!

Sean

OriginLab Technical Service


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