Author |
Topic  |
|
Clairekun
Germany
175 Posts |
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? |
Edited by - Clairekun on 04/09/2020 10:46:18 AM |
|
YimingChen
1667 Posts |
|
Clairekun
Germany
175 Posts |
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. |
 |
|
aplotnikov
Germany
169 Posts |
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.). |
Edited by - aplotnikov on 04/14/2020 05:44:48 AM |
 |
|
Clairekun
Germany
175 Posts |
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. |
 |
|
Clairekun
Germany
175 Posts |
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? |
 |
|
ds755
57 Posts |
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
Germany
175 Posts |
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
57 Posts |
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"... |
 |
|
|
Topic  |
|
|
|