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
 Loop over PE folders

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
Clairekun Posted - 04/09/2020 : 10:45:25 AM
Origin Ver. and Service Release (Select Help-->About Origin): 2018b
Operating System: Windows 10

Hello,

I'm trying to plot a series of stacked graphs using parameters in common among datasets. My PE structure is:

Folder1
-- Book 1
---- Sheet a
---- Sheet b
---- Sheet c
-- Book 2
---- Sheet a (same names than in Book 1)
---- Sheet b
---- Sheet c

Folder2
-- Book 1 (same names than in Folder 1)
---- Sheet a
---- Sheet b
---- Sheet c
-- Book 2
---- Sheet a
---- Sheet b
---- Sheet c
(...)

In one particular case, I need to plot those datasets that share folder name and worksheet name. This way, the graphs would hold:

- Graph1: All "Sheet a" from Folder1
- Graph2: All "Sheet b" from Folder1
- Graph3: All "Sheet c" from Folder1
- Graph4: All "Sheet a" from Folder2
(...)

I believe I can manage to write a code that selects and plots all equally named sheets within a folder in a single graph. However, I can't find how to loop through folders. There is, apparently, no doc or loop function that can be targeted to folders, and my labtalk knowledge is too limited to find a solution.

Could you point me in the right direction here?
8   L A T E S T    R E P L I E S    (Newest First)
ds755 Posted - 08/29/2020 : 05:17:21 AM
I should have clarified that my code only works for Long Names. This is why, instead of using "exist", you need to use "exist(%(uid2name(range2uid"...
Clairekun Posted - 08/25/2020 : 04:26:32 AM
quote:
Originally posted by ds755

I think you need to activate the already existing graph in the "else" branch.


Sorry for not replying on this possible solution until now, I did not have the time to work on this again until recently.

That solution did not work. I tried a different approach using if (exist()==0), to no avail.

I found what the problem was, and it was both simple and stupid. One of the string variables had a dot (.) in it so, since short names cannot have those symbols, it automatically deletes it when renaming.

This means that, initially, it will search for names with the dot, and it will obviously not find them, so it will create a new graph instead of appending the data to the existing one. Now, once the graph is created, it tries to rename it (removing the dot in the process) and then finds that the name actually exists, thus showing the error.

I did know about the incompatibility between short names and dots; what I did not notice is that it would not delete the dot automatically before searching for coincidences, which was a silly misconception on my part.

Thanks, everyone.
ds755 Posted - 05/21/2020 : 9:40:20 PM
I think you need to activate the already existing graph in the "else" branch. Here is a code snippet from my scripts:

range rgmlin = [%H]1!col(L);  // data range of gm (Linear) column

....

string graphname$="%(batch$)_%(architecture$)_gm-lin_Vd=%(Vdlin$)V";
if(exist(%(uid2name(range2uid(["%(graphname$)"]))$))==0) // if there is no graph for this type of measurement then create a new graph
{
	// Check if the template exists, otherwise, use a generic one
	string Template$="%(templatepath$)%(architecture$)_%(material$)_Vg=%(VgStart$)V to %(VgStop$)V_single.otpu"; // This is the template path
	if (exist(Template$)!=-1)// if the template exists
		win -t p "%(Template$)"; // create a graph window using template
	else
		win -t p "%(templatepath$)Generic_gm-lin.otpu"; // create a graph window using a generic template
	
	page.longname$ = graphname$; //this renames the active window (long name)
	page.title = 1;  // Let the workbook title shows Long Name only (1 = Long Name, 2 = short name, 3 = both)
};
else
	win -a %(uid2name(range2uid(["%(graphname$)"]))$); // activate the graph window
	
page.active = 1; // activate Layer 1
layer.include(rgmlin);  // plot in the active layer

//layer -a;  // rescale the layer
//layer -g; // Group the datasets in the layer to auto-color increment
//layer -gu; // Ungroup the datasets in the layer
legend; // Update the legend
Clairekun Posted - 04/14/2020 : 9:51:40 PM
Apparently I can't even do what I told you I had the knowledge for. I was trying to plot all equally named sheets within a folder in a single graph, to then try the solution kindly given by user aplotnikov to apply it to all folders.

For better understanding, please remember all books have the same worksheet names. I tried to retrieve those names (partially), use them to name new graphs, and append a plot to an existing graph if its name is already present.

doc -ef W {
	doc -e LW {
		string shtsname$ = %(layer.name$);
		string partsname$ = shtsname.GetToken(1,"_")$;
		string var_t_sTG$ = tTG%@F%(partsname$)z; //var_t_sTG$ =; returns the correct string
		string var_t_lTG$ = var t TG %@F %(partsname$)z;//var_t_lTG$ =; returns the correct string
		//Create a graph with the specified name; if the graph already exists, append the new plot to it
		if (exist(%(var_t_sTG$)) == 3)
		{
			plotxy iy:=[%(page.name$)]"%(layer.name$)"!(2,8) plot:=200  ogl:=[%(var_t_sTG$)]; //Append the plot to the existing graph
		}
		else
		{
			plotxy iy:=[%(page.name$)]"%(layer.name$)"!(2,8) plot:=200  ogl:=[<new>];//Create graph
			%(page.name$) = %(var_t_sTG$); //rename
			page.longname$ = var_t_lTG$;
		}
	}
}


I get individual graphs where those which share the same name (originally, equally named worksheets) ask for a new name.

The main problem, I believe, is that ogl:=[%(var_t_sTG$)] creates a new graph if the name doesn't exist, so the if/else function is useless, and name conflicts appear.

Could you, please, explain what I'm doing wrong, and why?
Clairekun Posted - 04/14/2020 : 10:34:50 AM
Thank you, I'll try this right away.

quote:
Originally posted by aplotnikov
PS. OriginC provides much better functionality for managing the project structure (Folder object, etc.).



I suspected that, but I know nothing about programming and can't find the time to learn (should've done it when I was younger...); I need to stick to a language I'm somewhat familiar with, so that I can understand what I'm doing.
aplotnikov Posted - 04/14/2020 : 05:32:41 AM
You can import the complete project structure as a string:

string strDir$;
pe_cd /;
pe_dir oname:=strDir display:=2 recursive:=1;


Then you can analyze the obtained string using GetToken()-method: tokens ending with a slash ("/") are folder pathnames.

PS. OriginC provides much better functionality for managing the project structure (Folder object, etc.).
Clairekun Posted - 04/13/2020 : 12:33:54 PM
Thank you; I knew about this method, I was wondering if there was a way of doing it without needing to specify folder names, since they could change from project to project.
YimingChen Posted - 04/10/2020 : 09:01:31 AM
Hello,

1. You can use XFunction pe_cd to go to different folders ( Folder1, Folder2 ):
https://www.originlab.com/doc/X-Function/ref/pe_cd

2. Then you can loop all workbooks under current folder using Doc -ef W:
https://www.originlab.com/doc/LabTalk/ref/Document-cmd#-ef.3B_Execute_the_given_script_for_all_objects_in_the_current_folder

James

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