Hi, Oliver.
I see there are two problems. First, it will cause dead loop; Second, it failed to add labels to y axis.
Therefore, I modified your code like this:
void plotting_with_err_bar()
{
// Create a Project object
Project proj;
PageBase pg;
// Loop over all pages in the project and display their names:
foreach (pg in proj.Pages)
{
string name = pg.GetName();
// Declare worksheet, data curve and error dataset and check validity
Worksheet wks(name);
if (!wks) continue; //Added to avode dead loop
Curve crvData(wks, 0, 1);
Dataset dsErr(wks, 2);
// Create a new graph and plot the data as a scatter plot
GraphPage gpg;
gpg.Create( "Origin.OTP" );
GraphLayer gly = gpg.Layers( 0 );
gly.AddPlot( crvData, IDM_PLOT_SCATTER );
// Add the error dataset as error bar to this plot
int nPlotIndex = gly.AddErrBar( crvData, dsErr );
// Rescale layer
gly.Rescale();
//set X and Y titles
LT_execute("lab -xb (classes);");
//Deleted
//LT_set_str("%P", name);
//LT_execute("label -yl %P;");
//Added
string str = "label -yl ";
str+=name;
str+=";";
LT_execute(str);
}
}
I hope this will help ^_^.
Deanna
OriginLab GZ Office