Using the Data Selector tool with a scriptWhen you use the Data Selector tool, it sets internal variables:
mks1 and mks2
which can then be used in script.
When programmatically accessing the Data Selector it is convenient to re-program the POINTPROC macro to automatically execute a script after a user double-clicks or presses Enter to set the markers.
Here is a basic script that simply reports the row index, X and Y values for each marker.
dotool 4;
def pointproc {
py=%C[mks1];
%A=xof(%C);
px=%A[mks1];
type -a Left marker is at index $(mks1), X is $(px),Y is $(py);
py=%C[mks2];
%A=xof(%C);
px=%A[mks2];
type -a Right marker is at index $(mks2), X is $(px),Y is $(py);
dotool 0;
};
You could use this as the basis for your script, but there are still details you would have difficulty with - specifically, your use of the sum function.
1.The sum function is implemented as a method of the sum object and does not return values; it simply sets the properties of the sum object. Your M=sum(... should therefore simply be sum(....
2.The only allowable argument to the sum function is a dataset name. Your range notation which you got from other LabTalk commands is not allowed in the sum() method. Instead, you can use options of the set command to temporarily set a dataset range:
set Data1_B -bs mks1;
set Data1_B -es mks2;
sum(Data1_B);
3.The Data Selector tool is only available to graph windows. Your argument to the sum() method - col(..) - does not apply since there are no columns in a graph window. You need to use a notation that supplies a full dataset name such as Data1_B.
Here is an example that does something like what you want for the active dataset of the active layer:
dotool 4;
def pointproc {
set %C -bs mks1;
set %C -es mks2;
sum(%C);
Type -a From index $(mks1) to $(mks2), the mean is $(sum.mean);
dotool 0;
};
My use of %C (which contains the active dataset of the active layer) may require modification to work in your circumstances.