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
 LabTalk Forum
 code to change "Graph1" to the workbook name
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

EigenGoofy

64 Posts

Posted - 05/14/2011 :  5:25:51 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): 8.5


Suppose that the long name of a workbook is "r23ektrun7.xvg". Then by using a template, a line-plotted graph associated with two columns from the workbook is generated with title "Graph1". Now, I need to change the title of the graph "r23A" instead of "Graph1".

If archiving this manually, then I open the Properties window, and type "r23A" for the long name and "r23A" for the short name. It is too tedious to type these names for 800 times, so I need to write labtalk code to do the same thing.

Note that the difference of the name between the workbook and the graph - one is "r23ektrun7", and the other one is "r23A". So if the name of the workbook is "r52ektrun7", then the corresponding name of the graph is "r52A".

Currently I know that:
aaa$=wks.name$; //get the name of worksheet
aaa.Replace("ekt",'%(TAB)'); //replace the string "ekt" as an delimiter "Tab"
%A=aaa.GetToken(1,tab)$; // get the string "r23"
%D=%AA

so %D is "r23A".

Then Questions:
1, there are hundreds of workbooks on my user interface, but this graph is associated with only one workbook, so how can I write a code segment which can find the appropiate workbook and get its name?

2, Since %D is "r23A", then how can I write a code segment which can change the long name and short name of the graph? (ie. how to apply %D to the graph title)

Thanks!!!

larry_lan

China
Posts

Posted - 05/16/2011 :  02:33:21 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Supposed there is only one curve in each graph page, you can try this script:

// Loop over all graph windows
// Please read LabTalk help for detail info about doc command
doc -e P {
	// Supposed there is only one plot in a graph
	// Get the active plot dataset name
	string scn = %c;
	string sbn = scn.GetToken(1, "_")$;
	string sbLN;
	string sbSN;
	// Get the book short name and long name
	win -o %(sbn$) {
		sbLN$ = page.longname$;
		sbSN$ = page.name$;
	}
	// Change the current graph window longname
	page.longname$ = sbLN$;
	// Place the longname on the graph
	// Please look into "Label" command to see how to fine ture
	// label positions.
	label -p 50 50 -s %(sbLN$)
}


Please modify the script as you need. For more information about the commands, please read the detail in LabTalk Help document.

Thanks
Larry
Go to Top of Page

EigenGoofy

64 Posts

Posted - 05/16/2011 :  4:19:31 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Oh, your reply is precious!

I learned something from another expert "greg" and "Amanda" here and modified your codes:

string strFile$ = page.info.system.import.filename$;

strFilepri$ = strFile$;
strFileprime$=strFilepri.GetToken(1,".")$;

strFilegraph$ = strFileprime$;
strFilegraph.Replace("ekt",'%(TAB)');
%A=strFilegraph.GetToken(1,tab)$;
%B=strFilegraph.GetToken(2,tab)$;
%J=%AA;
%K=%AA-%B;

string scn = %J;
string sbn = scn.GetToken(1, "_")$;
string sbLN = sbn$;
string sbSN = sbn$;

win -o %(sbn$) {
sbLN$ = page.longname$;
sbSN$ = page.name$;
};

page.longname$ = sbLN$;

string wn$ = page.name$;
win -r %(wn$) %(sbSN$);

string mylegend = %K;
label -p 70 20 -s %(mylegend$);

label -r legend;


This code works for me. Thank you so much~
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