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
 wrong coordinates
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

phildes

Austria
Posts

Posted - 12/17/2007 :  7:17:29 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Version 7.5 SR6:
Operating System: Win Vista
and
Origin Version 7.0 SR4:
Operating System: Win XP

I have a problem with the Labtalk getpoint selection tool. When I create a graph with origin C and rescale and maximize the graph window, the internal coordinates of getpoint dotool 2 will be almost everytime false. It's quite funny that clicking manually on the refresh button helps while executing the same script automatically doesn't change anything.
Only the refresh doc -uw in the PointProc macro helps, but thats not a solution.
I have the workaround to ask the user after the point was selected if the point was ok and let him refresh the graph manually.

Here is the sourcecode, the programm needs a wks with data in col 2 and 3.

  
void hyst()
{
Worksheet wks=Project.ActiveLayer();
if(!wks.IsValid())
{
out_str("Please select a Worksheet");
return;
}

GraphPage grph(wks.GetPage().GetName()+"g");


BOOL bOK=true;

if(!grph.IsValid()) // If graph does not exists, create new one
{

bOK = grph.Create("", CREATE_VISIBLE);

if (!bOK) // break on error
return;

}
// maximize Graph
LT_execute("win -a "+wks.GetPage().GetName()+"g"+";win -z");

// Get the first layer:

GraphLayer grlay = grph.Layers(0);

ASSERT(grlay.IsValid()); //check if ok

// Get the curve object from wks data set "moment"

wks.Columns(2).SetType(OKDATAOBJ_DESIGNATION_X);

Curve cv(wks,2,3); //make curve from wks with X= col2 , Y= col3

ASSERT(cv.IsValid());

// Add one data plot to the graph layer:

bOK = 0 <= grlay.AddPlot(cv);

if (!bOK)
return;

grlay.Rescale(); // Rescale layer

grph.Rename(wks.GetPage().GetName()+"g");

// rescale the dataplot to new range
string str;
str.Format("layer.x.from=%d;layer.x.to=%d;", 0, 20000);
LT_execute(str);

str.Format("layer.y.from=%s;layer.y.to=%d;", "-200", 0);
LT_execute(str);

LT_set_str("%K",wks.GetPage().GetName());

grph.SetShow(PAGE_NORMAL);
grph.Refresh(TRUE); // refresh graph

// grph.SetShow(PAGE_MAXIMIZED); //maximize
grph.Refresh(TRUE); // refresh graph


// execute LT to get points
LT_execute("run.section(%Yrelax\script\hyst.c, getpoint)");

}

#ifdef LABTALK // can be anything not defined

[getpoint]

def EndToolBox
{
nextf(); // start next function
};

def PointProc
{
t=-1;
doc -uw;
type -y "Was the selected point ok?";
if (t==1)
{
{EndToolbox};
doTool 0;
}
else
{
doTool -next;
}
};
// win -a;
plot -c;
label -xb "Magnetic Field (Oe)";
label -yl "Magnetic Moment (emu/g)";
//label -p 50 0 -j 1 "Hysteresis loop";

doc -uw; //window refresh
window -z; // maximize the window
doc -uw; clr; //window refresh

dotool 2;
//getpts -a 1;
clr; doc -uw;
x=11000;
y=-0.5;
//time -p 1;
clr; doc -uw;
//run.section(STANDARD,Refresh);

#endif

void nextf(){return;}

I've already worked more than several days on that problem. There must be something wrong in my code or this is a quite annoying bug.

regards Philipp

Mike Buess

USA
3037 Posts

Posted - 12/18/2007 :  5:04:04 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Philipp,

You might already have noticed that the script works fine if you don't maximize the graph window. The solution is to pause (sec -p) after maximizing. In the code below I've removed all OC and LT refreshes and moved most of the stuff in the LT section to the OC function.
void hyst()
{
Worksheet wks = Project.ActiveLayer();
if(!wks.IsValid())
{
out_str("Please select a Worksheet");
return;
}
string sWks = wks.GetPage().GetName(); // wks name
GraphPage grph(sWks + "g");

BOOL bOK;

if(!grph.IsValid()) // If graph does not exists, create new one
{
bOK = grph.Create("Origin.otp", CREATE_VISIBLE);
if (!bOK) // break on error
return;
grph.Rename(sWks + "g"); // rename graph
}

// Get the first layer:
GraphLayer grlay = grph.Layers(0);
ASSERT(grlay.IsValid()); //check if ok
wks.Columns(2).SetType(OKDATAOBJ_DESIGNATION_X);

// Get the curve object from wks data set "moment"
Curve cv(wks,2,3); //make curve from wks with X= col2 , Y= col3
ASSERT(cv.IsValid());

// Add one data plot to the graph layer:
//bOK = 0 <= grlay.AddPlot(cv); // ???
if( grlay.AddPlot(cv)==-1 )
return;

// rescale the layer to new range
//grlay.Rescale(); // auto rescale to show all data
grlay.X.From = 0; // manual rescale
grlay.X.To = 20000;
grlay.Y.From = -200;
grlay.Y.To = 0;

LT_set_str("%K",sWks);

GraphObject Xlabel = grlay.GraphObjects("xb"); // x axis label
if( Xlabel )
Xlabel.Text = "Magnetic Field (Oe)";
GraphObject Ylabel = grlay.GraphObjects("yl"); // y axis label
if( Ylabel )
Ylabel.Text = "Magnetic Moment (emu/g)";

// maximize graph window, then pause 0.1s
grph.SetShow(PAGE_MAXIMIZED);
LT_execute("sec -p 0.1");



// execute LT to get points
// __FILE__ contains the path\name of this OC file
LT_execute("run.section(" + __FILE__ + ", getpoint)");
}


#ifdef LABTALK // can be anything not defined

[getpoint]

def EndToolBox
{
nextf(); // start next function
};

def PointProc
{
t=-1;
type -y "Was the selected point ok?";
if (t==1)
{
{EndToolbox};
doTool 0;
}
else
{
doTool -next;
}
};

dotool 2;
//getpts -a 1;

x = 11000;
y = -0.5;

#endif

void nextf(){return;}


Mike Buess
Origin WebRing Member

Edited by - Mike Buess on 12/18/2007 5:09:05 PM
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