Page 1 of 1
Measuring, how can I get hold of the latest measuring
Posted: Wed Sep 15, 2010 7:15 am
by magthenop
How can I get hold of the measuring that has just been done? (for example: the user selects to measure a distance/area etc. and when he finishes this I want to be able to pick up this event and process the information), and how can I get hold of all measurings that has been done in a pdf,
I want to be able to process this programmaticaly.
Re: Measuring, how can I get hold of the latest measuring
Posted: Wed Sep 15, 2010 9:20 am
by Vasyl-Tracker Dev Team
Hi, magthenop.
This feature is undocumented but you may use next method - you may intercept the next events (in pseudocode):
Code: Select all
OnEvent(type, name,...)
{
if ((type == PXCVA_OnPropertyChanged) AND (FindSubStrIn(name, ".Measure.Simple."))
{
OnNewMeasurement();
}
}
OnNewMeasurement()
{
// read new measurements
ReadNewMeasurement("Distance");
ReadNewMeasurement("Area");
ReadNewMeasurement("Perimeter");
};
ReadNewMeasurement(string annotType)
{
// read current style
int curStyleID;
ax.GetProperty("Tools." + annotType + ".Style", curStyleID);
string prefix = "Commenting." + annotType + ".Styles[#" + curStyleID + "].Measure.Simple.";
// read new scale ratio
double fromValue;
double toValue;
int fromUnit;
int toUnit;
ax.GetProperty(prefix + "FromValue", fromValue);
ax.GetProperty(prefix + "FromUnit", fromUnit);
// to obtain the name of selected measurement unit such as "Point", "Inch", etc. - you may call the:
// string fromUnitStr;
// ax.GetProperty(prefix + "FromUnit", fromUnitStr, PXCVA_GetNamed);
..
ax.GetProperty(prefix + "ToValue", toValue);
ax.GetProperty(prefix + "ToUnit", toUnit);
};
Best
Regards.
Re: Measuring, how can I get hold of the latest measuring
Posted: Wed Sep 15, 2010 1:29 pm
by magthenop
Hi!
This onEvent does not trigger the OnNewMeasurement when I do a new measuring (a distance, area etc).
Something is not right.
Here is my code for the onEvent in Delphi:
Code: Select all
procedure TForm1.PDFRitningEvent(ASender: TObject; Type_: Integer;
const Name: WideString; const DataIn: OleVariant; out DataOut: OleVariant;
Flags: Integer);
begin
if (Type_ = PXCVA_OnPropertyChanged) Then Begin
if (Pos('.Measure.Simple.',Name)>0) Then Begin
OnNewMeasurement;
End;
End;
end;
Re: Measuring, how can I get hold of the latest measuring
Posted: Wed Sep 15, 2010 4:08 pm
by Vasyl-Tracker Dev Team
Please update to latest version (2.0.55). It may resolve your problem.
Re: Measuring, how can I get hold of the latest measuring
Posted: Thu Sep 16, 2010 5:42 am
by magthenop
Sorry, but after ugrading to 2.0.55 (had 2.0.54) I get the same result as before
Re: Measuring, how can I get hold of the latest measuring
Posted: Thu Sep 16, 2010 5:56 am
by magthenop
Another thing that happend after upgrading, I can not set the scale after loading an .pdf file,
if I now try to set this scale I get an
OLE Error 82130001 on the first code line, this worked in 2.0.54.
Code: Select all
PDFRitning.SetProperty('Tools.Distance.Measure.Simple.FromValue', 1.0,0);
PDFRitning.SetProperty('Tools.Distance.Measure.Simple.FromUnit', 'cm',0);
PDFRitning.SetProperty('Tools.Distance.Measure.Simple.ToValue', 1.0,0);
PDFRitning.SetProperty('Tools.Distance.Measure.Simple.ToUnit', 'm',0);
Re: Measuring, how can I get hold of the latest measuring
Posted: Thu Sep 16, 2010 7:39 am
by Vasyl-Tracker Dev Team
Hi, magthenop.
The 'Tools.Distance' does not contain the 'Measure' node. So the next code is wrong:
Code: Select all
PDFRitning.SetProperty('Tools.Distance.Measure.Simple.FromValue', 1.0,0);
Replace your code by:
Code: Select all
PDFRitning.SetProperty('Commenting.Distance.Styles[0].Measure.Simple.FromValue', 1.0,0);
Note: the name fragment 'Styles[0]' can be changed to 'Styles[#<CurrentDistanceStyleID>]', example:
'Commenting.Distance.Styles[#6463].Measure.Simple.FromValue' - represents scale ratio part of current style of Distance Tool.
The <CurrentDistanceStyleID> you can obtain by (in Delphi):
Code: Select all
var:
iCurrentStyleIDofDist: integer;
dataOut: OLEVariant;
...
PDFRitning.GetProperty('Tools.Distance.Style', dataOut, 0);
iCurrentStyleIDofDist := dataOut;
- Look again to
ReadNewMeasurement in my previous post.
Best
Regards.
Re: Measuring, how can I get hold of the latest measuring
Posted: Thu Sep 16, 2010 7:51 am
by Vasyl-Tracker Dev Team
Sorry, but after ugrading to 2.0.55 (had 2.0.54) I get the same result as before
Strange...
I checked it again - it working properly: I can intercept events about measurement changing..
Please check version of installed components by
GetVersionInfo routine. Probably you haven't updated all components.
Re: Measuring, how can I get hold of the latest measuring
Posted: Thu Sep 16, 2010 7:57 am
by magthenop
When checking the versions I get:
Client version: 2.0.0055.0000
Server version: 2.0.0055.0000
Re: Measuring, how can I get hold of the latest measuring
Posted: Thu Sep 16, 2010 9:23 am
by Tracker Supp-Stefan
Thanks for double checking the version magthenop,
So is the latest solution proposed by Viktor still not working for you as your comment where you said there is no change is before Viktor's latest snippets?
Best,
Stefan
Re: Measuring, how can I get hold of the latest measuring
Posted: Thu Sep 16, 2010 9:30 am
by magthenop
The latest solution proposed by Viktor, does not work for me.
Re: Measuring, how can I get hold of the latest measuring
Posted: Thu Sep 16, 2010 11:56 am
by Vasyl-Tracker Dev Team
Hi, magthenop.
Your example working properly, BUT, may be, here exists one misunderstanding. You said at the beginning:
How can I get hold of the measuring that has just been done? (for example: the user selects to measure a distance/area etc. and when he finishes this I want to be able to pick up this event and process the information), and how can I get hold of all measurings that has been done in a pdf,
I have understood it as: "how do I know the scale-ratio of measurement that has just changed by the end-user in the 'Properties' toolbar?"
But, if you need to know the current distance/area/perimeter value of the corresponding annotation while the end-user modifies it - it is impossible now, you will be able do it in the new version only (V3).
Re: Measuring, how can I get hold of the latest measuring
Posted: Thu Sep 16, 2010 12:11 pm
by magthenop
Oh, thats to bad.
When will this version be available? I must have some sort of working solution for this shortly after mid october (promised demo to many customers),
after that Beta testing and in the beginning of next year rollout of a new version to all customers.
Can I solve this some other way? for example by looking at the latest annotation and se if this has changed and is of a current date/time (then it is new).
Re: Measuring, how can I get hold of the latest measuring
Posted: Thu Sep 16, 2010 3:12 pm
by Vasyl-Tracker Dev Team
You could use the following method for your case:
Code: Select all
PDFRitning.SetProperty('Notifications.Selection.Filter', 'Annotations', 0);
...
procedure TForm1.PDFRitningEvent(ASender: TObject; Type_: Integer; const Name: WideString; const DataIn: OleVariant; out DataOut: OleVariant; Flags: Integer);
begin
if (Type_ = PXCVA_OnNamedNotify) Then
Begin
if ((CompareText(Name, 'Global::OperationsHistoryChanged') = 0) or (CompareText(Name, 'Notifications.Selection') = 0)) Then
Begin
ReadDimOfSelAnnot();
End;
End;
end;
function ReadDimOfSelAnnot()
var
script:widestring;
result:widestring;
begin
try
script := 'a = this.selectedAnnots; if (a.length) { a[0].intent; };';
result := '';
PDFRitning.RunJavaScript(script, result, 0, 0);
if ((CompareText(result, 'LineDimension') = 0) or (CompareText(result, 'PolyLineDimension') = 0) or (CompareText(result, 'PolygonDimension') = 0)) Then
begin
try
script := 'a = this.selectedAnnots; if (a.length) { a[0].contents; };';
result := '';
PDFRitning.RunJavaScript(script, result, 0, 0);
// after this the 'result' should contain the measure string, like to: '1 200 m'
except
on ex : EOleException do
;
end;
end
...
except
on ex : EOleException do
;
end;
end;
Please excuse me if there are any small syntax errors, I'm not a Delphi-programmer
.
Best
Regards.
Re: Measuring, how can I get hold of the latest measuring
Posted: Fri Sep 17, 2010 7:21 am
by magthenop
Nice, work totaly fine for me
Thanks a million.
Re: Measuring, how can I get hold of the latest measuring
Posted: Fri Sep 17, 2010 9:19 am
by magthenop
One more thing
When measuring an Area i can se inte PDFViewer the length of the perimeter, but when finished I can only se the area.
When "reading" the selected annotation for a area measurement can I somehow even get the perimeter length at the same time (or can I translate the selected annotation from a PolygonDimension to a PolyLineDimension so I can get the perimeter length) ?
Re: Measuring, how can I get hold of the latest measuring
Posted: Fri Sep 17, 2010 9:51 am
by Vasyl-Tracker Dev Team
I'm afraid that there is no simple way for this..
Re: Measuring, how can I get hold of the latest measuring
Posted: Fri Sep 17, 2010 11:15 am
by magthenop
Ok, thats a settback
Can I somehow convert the values in the rect propery of the annotation to a length by any simple means?
Re: Measuring, how can I get hold of the latest measuring
Posted: Fri Sep 17, 2010 11:28 am
by magthenop
Sorry, rect is wrong propery, but somewhere the "points" must be saved.
Re: Measuring, how can I get hold of the latest measuring
Posted: Fri Sep 17, 2010 12:56 pm
by Vasyl-Tracker Dev Team
To obtain the points you may use the next JS-script:
Code: Select all
a = this.selectedAnnots;
if (a.length) { a[0].vertices; };
If successful then it returns the array of points in format:
x1, y1, x2, y2, x3, y3...
For more details:
http://www.adobe.com/devnet/acrobat/pdf ... erence.pdf
Re: Measuring, how can I get hold of the latest measuring
Posted: Mon Sep 20, 2010 7:33 am
by magthenop
Do you have a link that works? I'm getting: Sorry, this page is not available
Re: Measuring, how can I get hold of the latest measuring
Posted: Mon Sep 20, 2010 9:09 am
by Vasyl-Tracker Dev Team
Hi, magthenop.
The Adobe changed it in the last Friday.
I found it in the new place:
http://www.adobe.com/content/dam/Adobe/ ... erence.pdf
Re: Measuring, how can I get hold of the latest measuring
Posted: Fri Sep 24, 2010 7:35 am
by magthenop
Hi!
I can not find any function where I can send in the vertices from a[0].vertices and get back the perimeter length or create a new Polyline measurement on the same location as the Polygon measurement with the polygon measure as a blueprint.
Can someone help me with this?
Or how to catch the event when a new point is created/edited/deleted on a plygon measurement and then also be able to pick up the perimeter length that is displayed on the screen for this measurement.
Or how to add some functionallity for the "create/change" event when a polygon measurement is created/changed so I also can save the perimeter length in another propery of this object.
Re: Measuring, how can I get hold of the latest measuring
Posted: Fri Sep 24, 2010 10:09 am
by Vasyl-Tracker Dev Team
Hi, magthenop.
You may use next method:
Method A
1. prepare string obtained from a[0].vertices (how obtain - see above):
the obtained:
x0,y0,x1,y1,x2,y2
to new:
[[x0,y0],[x1,y1],[x2,y2]]
example:
from:
0,0,200,200,300,100,0,0
to:
[[0,0],[200,200],[300,100],[0,0]]
2. Build and launch special script for adding the corresponding polyline annotation (example pseudocode):
Code: Select all
int page; // zero based
string preparedVertices; // can contain for example the string "[[0,0],[200,200],[300,100],[0,0]]" (without quote marks)
scriptToAddPolyLine = "var a = this.addAnnot({page:" + page +", type: "PolyLine", vertices: " + preparedVertices + "});";
Method B
1. extract actual points from a[0].vertices
2. calc perimeter by:
Code: Select all
val = 0;
points; // zero bazed
pointsNum; // count of points
for (size_t i = 1; i < pointsNum; i++)
{
double dx = (points[i].x - points[i - 1].x);
double dy = (points[i].y - points[i - 1].y);
val = val + sqrt(dx * dx + dy * dy);
};
3. Transform calculated value by current scale ratio (yow obtain actual scale ratio - see above) and save it to 'subject' property of existsing polygon annotation by:
Code: Select all
string val; // contain perimeter string
scriptToModifySubjOfAnnot = 'a = this.selectedAnnots; if (a.length) { a.subject = "' + val + '"; };';
To intercept "create/change" event:
Code: Select all
procedure TForm1.PDFRitningEvent(ASender: TObject; Type_: Integer; const Name: WideString; const DataIn: OleVariant; out DataOut: OleVariant; Flags: Integer);
begin
if (Type_ = PXCVA_OnNamedNotify) Then
Begin
if (CompareText(Name, 'Global::OperationsHistoryChanged') = 0) Then
Begin
OnAnyAnnotChangedAddedOrDeleted();
End;
End;
end;
HTH.
Re: Measuring, how can I get hold of the latest measuring
Posted: Mon Sep 27, 2010 8:39 am
by magthenop
When I measure an arean (in this case a triangle)
I get this points from the vertices of the area measure:
[437.95407360805285,1462.71714922049],
[588.6882667505505,1466.467706013363],
[503.19723183391005,1363.7024498886415]
Before I finishes the measurement I know that the circumfence length should be 10,03 meters,
I also know that the scale I have set is 1 cm equals 1 meter ( 1:100), it also says this for the area measurement.
After running this function (descibed in code below) I get the result: 403,03469552
Code: Select all
Omkr:=0; // Set the measured length to 0
for Rkn:=0 To AntalVert-1 Do Begin //AntalVert is the number of points
NyRkn:=Rkn-1; // Set NyRkn to the previous point
If NyRkn=-1 Then NyRkn:=AntalVert-1; // If NyRkn is less than 0 set it to the last point
dx := VertX[NyRkn] - VertX[Rkn];
dy := VertY[NyRkn] - VertY[Rkn];
Omkr := Omkr + sqrt((dx * dx) + (dy * dy));
End;
I can not get the value of 403,03469552 to be equal to 10,03 meters if my scale is set to 1:100.
I assume that I am thinking wrong somewhere but how and why?
Re: Measuring, how can I get hold of the latest measuring
Posted: Mon Sep 27, 2010 9:59 am
by Vasyl-Tracker Dev Team
After running this function (descibed in code below) I get the result: 403,03469552
I can not get the value of 403,03469552 to be equal to 10,03 meters if my scale is set to 1:100.
Because you obtained the value in points (1 pt = 1/72 inch), it is standard measurement unit in PDF.
You should transform this value by corresponding scale ratio. The current scale ratio you can read by:
Code: Select all
PDFRitning.GetProperty('Commenting.Distance.Styles[0].Measure.Simple.FromValue', @valFrom,0);
PDFRitning.GetProperty('Commenting.Distance.Styles[0].Measure.Simple.FromUnit', @unitFrom,PXCVA_GetNamed);
PDFRitning.GetProperty('Commenting.Distance.Styles[0].Measure.Simple.ToValue', @valTo, 0);
PDFRitning.GetProperty('Commenting.Distance.Styles[0].Measure.Simple.ToValue', @unitTo, PXCVA_GetNamed);
And next:
Code: Select all
valPerim; // contains the perimeter in points, and scale ration is 1cm=1m
If unitFrom='Centimeter' Then Begin
valPerim := (valPerim / 72.0) * 2.54; // pt to cm, 403,03469552 pt = 14,22 cm, note: your 10,3 is some incorrect
End;
valPerim := valPerim * (valTo / valFrom); // 14,22 cm * (1/1), because 1cm=1m
// after this you have valPerim in unitTo (Meter)
Re: Measuring, how can I get hold of the latest measuring
Posted: Mon Sep 27, 2010 12:30 pm
by magthenop
It works so nice now! Thanks a million.
Re: Measuring, how can I get hold of the latest measuring
Posted: Mon Sep 27, 2010 1:35 pm
by Tracker Supp-Stefan
All the kudos to Vasyl
Cheers,
Stefan
Re: Measuring, how can I get hold of the latest measuring
Posted: Mon Sep 27, 2010 4:21 pm
by magthenop
I could not agree more, all kudos to vasil
Re: Measuring, how can I get hold of the latest measuring
Posted: Wed Sep 29, 2010 4:05 pm
by Paul - Tracker Supp
"All praise to the Great One..."