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 for Programming
 LabTalk Forum
 code to change "Graph1" to the workbook name

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
EigenGoofy Posted - 05/14/2011 : 5:25:51 PM
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!!!
2   L A T E S T    R E P L I E S    (Newest First)
EigenGoofy Posted - 05/16/2011 : 4:19:31 PM
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~
larry_lan Posted - 05/16/2011 : 02:33:21 AM
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

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