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
 Origin Forum
 Accessing worksheet user.variables data from graph
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

LC_

42 Posts

Posted - 04/30/2013 :  08:30:08 AM  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.0 SR1
Operating System: Win 7

Hi

I am writing a script to loop into dataplots in a graph and compares the differences in the page.info.user.variables information from each originating worksheet (information generated automatically during the import). The information then is used to create a graph legend (as in Insert Info Variable) since only a few of the variables will be changing. However, I could not find how to retrieve the variable values from the spreadsheets (highlighted in the code extract below).

Thanks in advance

//count number of dataplots
layer -c;
//initializes tmpVal, variable with 1st user.variables from 1st worksheet
tmpVal = ;
//loop through variables
loop(ii,1,NumVars)
{
//loop through dataplots
loop(jj,1,count)
{
if (tmpVal2 = tmpVal) //tmpVal2 is same variable in next worksheet
//this loop compares the nth variable in the loop across all worksheets
//if they are changing, variable position is recorded for use in legend
}
//updates tmpVal
}
//creates legend out of variables that are changing (format var = value)

LC_

42 Posts

Posted - 05/03/2013 :  07:18:58 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Well, I couldn't find an elegant solution to access all variables so I'm doing it the hard way by activating each workbook and looping through each variable by name. Below is an extract of the code (assuming there is a variable called CONFIG in users.variables). From this point, I have two problems:

1 - the code is not generalizable, since I cannot just access the variables without hard coding their names. So, for each new file I would need to modify the code, which was not the intention.

2 - The code works just fine when there are not too many variables in play, but when I try to increase the number of variables in the last loop (when creating the legend), Code Builder crashes in the following line:

if (StatusLgnd[1]) tmpLgnd$ = tmpLgnd$ + config_.GetAt(ii)$ + " ";

Apparently, Labtalk "doesn't like" longer strings, but the error is not consistently repeatable nor I could find in the documentation what is the allowable length of strings. Any lights?




doc -e DY
{
range -w aa1=%C;
range aa2 = aa1.GetPage()$;
string aa3$ = aa2.name$;
string aa4$ = "["+ aa3$ + "]";
DPNames.Add(%(aa4$));
}

loop(jj,1,NumPlots)
{
string ff$= DPNames.GetAt(jj)$;
win -a %(ff$);
config_.Add(page.info.user.variables.config$);
}

dataset StatusLgnd;

//for(ii=1;ii<=NumVars;ii++)
loop(ii,1,NumVars)
{
StatusLgnd[ii] = 0;
}


//creates legend
Lgnd$ = "";
win -a %(gpname$);

if (NumPlots >=2)
{
////loop through dataplots to check which variables are changed
loop(ii,2,NumPlots)
{
if (Config_.GetAt(ii)$ != Config_.GetAt(ii-1)$) StatusLgnd[1] = 1;
}
loop(ii,1,NumPlots)
{
tmpLgnd$ = "\L($(ii)) ";
if (StatusLgnd[1]) tmpLgnd$ = tmpLgnd$ + config_.GetAt(ii)$ + " ";
Lgnd$ = Lgnd$ + "%(CRLF)";
}

win -a %(gpname$);
legend.text$=Lgnd$;
}
Go to Top of Page

greg

USA
1378 Posts

Posted - 05/03/2013 :  3:47:52 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
There is an internal buffer used for LabTalk string manipulation that is 8K, so given that the last character in the buffer must be NULL your code may be exceeding the 8191 character limit. It shouldn't crash, but I guess your code creates some unusual conditions.

Moving your code to Origin C will allow you to create long strings and assign them to the Legend object as in this fragment:

GraphLayer gl = Project.ActiveLayer();
GraphObject go = gl.GraphObjects("Legend");
string str; // string for legend text
// Code to build your string goes here
go.Text = str; // Assign the string to the Legend object
Go to Top of Page

LC_

42 Posts

Posted - 05/06/2013 :  10:24:52 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Greg

Thanks for your answer. I investigated further and was able to isolate the issue, but what I found is puzzling. The issue was not related to the legend string length. By changing the code I managed to create long strings (over 1000 characters), while my test case had only ~100. Thus I investigated the other parts of the code and, for the modified code (with synthesized inputs in place of the original values read from the workbooks), I could isolate the crash to this section:

if (Config_.GetAt(ii)$ != Config_.GetAt(ii-1)$) StatusLgnd[1] = 1;

This line is repeated for the other 24 variables (25 in total). By commenting or uncommenting the lines, I found out that Code Builder crashes after executing this line for any 16 variables in the list (any of them in any order). Then, I tried to change the test for a string comparison:

if(Config_.GetAt(ii)$.Compare(Config_.GetAt(ii-1)$) StatusLgnd[1] = 1;

To my surprise, with this syntax Code Builder will crash after I execute the line the seventh time for any of the variables, and most times it will show a memory access error like the one below:



It seems to be some internal error with Labtalk. Would you suggest any workaround for this in Labtalk? Following your suggestion of implementing the function in Origin C, is there a way I could access these variables systematically (i.e. not by name)?

Thanks in advance
Go to Top of Page

greg

USA
1378 Posts

Posted - 05/08/2013 :  11:17:27 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
You are only giving us fragments to go on...

Have you checked what size your Config_ StringArray is? Are you sure your NumPlots (original fragment) is correct (and you start at index 2)? Do all strings look 'reasonable'?

loop(ii,1,config_.GetSize())
{
str$ = config_.GetAt(ii)$;
ty str$;
}

Also, please use the LabTalk Forum for these kinds of issues:
http://www.originlab.com/forum/forum.asp?FORUM_ID=10

Edited by - greg on 05/08/2013 11:22:24 AM
Go to Top of Page

LC_

42 Posts

Posted - 06/05/2013 :  02:55:39 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Greg

Sorry for using the wrong forum... The code was the same as I posted just expanded towards the 25 variables I had and Origin always crashes the same way, even if I completely changed the worksheet, variable names and variable contents. I just didn't have time to check if the problem repeated in another computer, but now I have implemented the routine using Origin C and it works flawlessly.
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