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
 Forum for Origin C
 LT_execute and LabTalk problem in Origin C
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

evanm

Canada
Posts

Posted - 08/18/2004 :  10:15:01 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hello, I am having a problem with LT_execute and/or %() substitution. I have some graph names and I want to loop through them and get the names of the datasets plotted in the graph windows. A simple section of code would look as follows:

//find the dataset name from the first graph:
string graphName = "somegraphname";
LT_set_str("%R", graphName);
LT_execute("%S = %(%R,@D)"); //this sets %S to the dataset name
char charTemp[50];
LT_get_str("%S",charTemp,50);
string dsYName = charTemp;
//now have the first dataset name. The code works fine up to here but doing the same thing again does not work...

//now find the dataset name from the second graph:
graphName = "someothergraphname";
LT_set_str("%R", graphName);
LT_execute("%S = %(%R,@D)");
LT_get_str("%S",charTemp,50);
dsYName = charTemp;

The first section of code works perfectly, however doing the exact thing again fails to work for some reason. Does anyone know what is wrong here?

Thank you, Evan.

easwar

USA
1965 Posts

Posted - 08/18/2004 :  11:16:28 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Evan,

You don't need to use LabTalk to get the data plot names. You can use OC code similar to what is pasted below. This works in v7SR4 - v7.5SR4

Easwar
OriginLab


void get_dataplot_names()
{
// Loop over all graphs in project
foreach( GraphPage gpg in Project.GraphPages )
{
printf( "Graph Page: %s\n", gpg.GetName() );
// Loop over all layers
foreach( GraphLayer gl in gpg.Layers )
{
printf( " Layer %d:\n", gl.GetIndex() + 1 );
// Loop over all data plots
foreach( DataPlot dpl in gl.DataPlots )
{
printf( " %s\n", dpl.GetDatasetName() );
}
}
printf("\n");
}
}



Go to Top of Page

evanm

Canada
Posts

Posted - 08/19/2004 :  05:51:18 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks for the reply. That would work for me except for that I forgot to mention that I am using version 7SR0, and I am unable to upgrade right now. Does anyone know of another way to get the dataset names? Or else why the labtalk code is failing?

Thanks, Evan.

Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 08/19/2004 :  08:47:41 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Evan,

I think the problem lies in your Labtalk method for getting the dataset name. When I use it from the script window I get the following results (Graph1 exists and has a dataplot)...

%R=Graph1;
%S=%(%R, @D);
%S=;
% (%R, @D)

Try something like this instead...

%R=Graph1;
win -o %R {%S=%(1, @D)};
%S=;
Data1_B

If your plot has more than one layer that will get the first dataset in the active layer.

Mike Buess
Origin WebRing Member

Edited by - Mike Buess on 08/19/2004 08:56:13 AM
Go to Top of Page

evanm

Canada
Posts

Posted - 08/19/2004 :  10:37:27 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks Mike,

your method also works, but ONLY for the first graph. When I loop through that section of code using Origin C for some reason only the first iteration of that code segment works.

Suppose wks1 has 3 graph names in its first column. I want to programatically find the names of the first dataset plotted in each graphs active layer.
Using what you suggested, this is my code:

void myfunc()
{
Worksheet wks("wks1");
char temp[50];
string graphName;

for(int i = 0; i < 3; i++) {
wks.GetCell(i,0,graphName);
LT_set_str("%R", graphName);
LT_execute("win -o %R {%S=%(1, @D)}");
LT_get_str("%S", temp, 50);
string dsYName = temp;
printf("dsname %s\n", dsYName);
}
}

When I run this I get output like:
dsname dsYName1 //this one is correct
dsname ### //the other 2 are garbage; I actually get ### out
dsname ###

Any more suggestions would be greatly appreciated. Thanks, Evan.



Edited by - evanm on 08/19/2004 10:38:51 AM
Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 08/19/2004 :  11:33:43 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Evan,

You have row and col indices mixed up in wks.GetCell(). Should be wks.GetCell(0,i,graphName).

...My mistake. I thought your graph names were all in the first row. Your code works perfectly in my Origin 7.0 SR4.

Another reason to update to SR4?

Mike Buess
Origin WebRing Member

Edited by - Mike Buess on 08/19/2004 3:46:58 PM
Go to Top of Page

easwar

USA
1965 Posts

Posted - 08/19/2004 :  11:46:43 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:

That would work for me except for that I forgot to mention that I am using version 7SR0, and I am unable to upgrade right now.



Hi Evan,

The OC code that I posted works in version 7 SR4. So if you want to use the OC code, just get the free SR4 update for your version 7 installation from our website.

Easwar
OriginLab

Go to Top of Page

evanm

Canada
Posts

Posted - 08/19/2004 :  11:56:19 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
easwar,

if I install SR4 and then compile my function can I then run it on other machines that do not have the SR package installed? (ie O7SR0)

Go to Top of Page

cpyang

USA
1406 Posts

Posted - 08/19/2004 :  12:07:23 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
You can not compile in one version of Origin and hope that it (OCB file?) will run on a different version. There are those OP files that you can compile in OriginPro version and then run on regular version of Origin. When you compile some C files, Origin will create OCB files and when you get to run these OCBs, Origin will check that it was produced by which version and if dose not match, Origin will attampt to find the source and compiles it again. Basically, some features were not present in 7SR0, so you will need to patch all the machines to 7SR4.

CP


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