Measuring, how can I get hold of the latest measuring

PDF-XChange Viewer SDK for Developer's
(ActiveX and Simple DLL Versions)

Moderators: TrackerSupp-Daniel, Tracker Support, Vasyl-Tracker Dev Team, Sean - Tracker, Chris - Tracker Supp, Tracker Supp-Stefan, Ivan - Tracker Software

Post Reply
magthenop
User
Posts: 43
Joined: Tue Sep 07, 2010 8:35 am

Measuring, how can I get hold of the latest measuring

Post by magthenop » Wed Sep 15, 2010 7:15 am

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.

User avatar
Vasyl-Tracker Dev Team
Site Admin
Posts: 1923
Joined: Thu Jun 30, 2005 4:11 pm
Location: Canada

Re: Measuring, how can I get hold of the latest measuring

Post by Vasyl-Tracker Dev Team » Wed Sep 15, 2010 9:20 am

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.
Vasyl Yaremyn
Tracker Software Products
Project Developer

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.

magthenop
User
Posts: 43
Joined: Tue Sep 07, 2010 8:35 am

Re: Measuring, how can I get hold of the latest measuring

Post by magthenop » Wed Sep 15, 2010 1:29 pm

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;

User avatar
Vasyl-Tracker Dev Team
Site Admin
Posts: 1923
Joined: Thu Jun 30, 2005 4:11 pm
Location: Canada

Re: Measuring, how can I get hold of the latest measuring

Post by Vasyl-Tracker Dev Team » Wed Sep 15, 2010 4:08 pm

Please update to latest version (2.0.55). It may resolve your problem.
Vasyl Yaremyn
Tracker Software Products
Project Developer

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.

magthenop
User
Posts: 43
Joined: Tue Sep 07, 2010 8:35 am

Re: Measuring, how can I get hold of the latest measuring

Post by magthenop » Thu Sep 16, 2010 5:42 am

Sorry, but after ugrading to 2.0.55 (had 2.0.54) I get the same result as before :(

magthenop
User
Posts: 43
Joined: Tue Sep 07, 2010 8:35 am

Re: Measuring, how can I get hold of the latest measuring

Post by magthenop » Thu Sep 16, 2010 5:56 am

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);

User avatar
Vasyl-Tracker Dev Team
Site Admin
Posts: 1923
Joined: Thu Jun 30, 2005 4:11 pm
Location: Canada

Re: Measuring, how can I get hold of the latest measuring

Post by Vasyl-Tracker Dev Team » Thu Sep 16, 2010 7:39 am

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.
Vasyl Yaremyn
Tracker Software Products
Project Developer

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.

User avatar
Vasyl-Tracker Dev Team
Site Admin
Posts: 1923
Joined: Thu Jun 30, 2005 4:11 pm
Location: Canada

Re: Measuring, how can I get hold of the latest measuring

Post by Vasyl-Tracker Dev Team » Thu Sep 16, 2010 7:51 am

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.
Vasyl Yaremyn
Tracker Software Products
Project Developer

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.

magthenop
User
Posts: 43
Joined: Tue Sep 07, 2010 8:35 am

Re: Measuring, how can I get hold of the latest measuring

Post by magthenop » Thu Sep 16, 2010 7:57 am

When checking the versions I get:

Client version: 2.0.0055.0000
Server version: 2.0.0055.0000

User avatar
Tracker Supp-Stefan
Site Admin
Posts: 13424
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Measuring, how can I get hold of the latest measuring

Post by Tracker Supp-Stefan » Thu Sep 16, 2010 9:23 am

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

magthenop
User
Posts: 43
Joined: Tue Sep 07, 2010 8:35 am

Re: Measuring, how can I get hold of the latest measuring

Post by magthenop » Thu Sep 16, 2010 9:30 am

The latest solution proposed by Viktor, does not work for me. :(
Attachments
PdfView.zip
Here is the source code for my program (Delphi 2006, win32).
(11.15 KiB) Downloaded 74 times

User avatar
Vasyl-Tracker Dev Team
Site Admin
Posts: 1923
Joined: Thu Jun 30, 2005 4:11 pm
Location: Canada

Re: Measuring, how can I get hold of the latest measuring

Post by Vasyl-Tracker Dev Team » Thu Sep 16, 2010 11:56 am

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).
Vasyl Yaremyn
Tracker Software Products
Project Developer

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.

magthenop
User
Posts: 43
Joined: Tue Sep 07, 2010 8:35 am

Re: Measuring, how can I get hold of the latest measuring

Post by magthenop » Thu Sep 16, 2010 12:11 pm

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).

User avatar
Vasyl-Tracker Dev Team
Site Admin
Posts: 1923
Joined: Thu Jun 30, 2005 4:11 pm
Location: Canada

Re: Measuring, how can I get hold of the latest measuring

Post by Vasyl-Tracker Dev Team » Thu Sep 16, 2010 3:12 pm

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.
Vasyl Yaremyn
Tracker Software Products
Project Developer

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.

magthenop
User
Posts: 43
Joined: Tue Sep 07, 2010 8:35 am

Re: Measuring, how can I get hold of the latest measuring

Post by magthenop » Fri Sep 17, 2010 7:21 am

Nice, work totaly fine for me :D
Thanks a million.

magthenop
User
Posts: 43
Joined: Tue Sep 07, 2010 8:35 am

Re: Measuring, how can I get hold of the latest measuring

Post by magthenop » Fri Sep 17, 2010 9:19 am

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) ?

User avatar
Vasyl-Tracker Dev Team
Site Admin
Posts: 1923
Joined: Thu Jun 30, 2005 4:11 pm
Location: Canada

Re: Measuring, how can I get hold of the latest measuring

Post by Vasyl-Tracker Dev Team » Fri Sep 17, 2010 9:51 am

I'm afraid that there is no simple way for this.. :(
Vasyl Yaremyn
Tracker Software Products
Project Developer

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.

magthenop
User
Posts: 43
Joined: Tue Sep 07, 2010 8:35 am

Re: Measuring, how can I get hold of the latest measuring

Post by magthenop » Fri Sep 17, 2010 11:15 am

Ok, thats a settback :-(

Can I somehow convert the values in the rect propery of the annotation to a length by any simple means?

magthenop
User
Posts: 43
Joined: Tue Sep 07, 2010 8:35 am

Re: Measuring, how can I get hold of the latest measuring

Post by magthenop » Fri Sep 17, 2010 11:28 am

Sorry, rect is wrong propery, but somewhere the "points" must be saved.

User avatar
Vasyl-Tracker Dev Team
Site Admin
Posts: 1923
Joined: Thu Jun 30, 2005 4:11 pm
Location: Canada

Re: Measuring, how can I get hold of the latest measuring

Post by Vasyl-Tracker Dev Team » Fri Sep 17, 2010 12:56 pm

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
Vasyl Yaremyn
Tracker Software Products
Project Developer

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.

magthenop
User
Posts: 43
Joined: Tue Sep 07, 2010 8:35 am

Re: Measuring, how can I get hold of the latest measuring

Post by magthenop » Mon Sep 20, 2010 7:33 am

Do you have a link that works? I'm getting: Sorry, this page is not available

User avatar
Vasyl-Tracker Dev Team
Site Admin
Posts: 1923
Joined: Thu Jun 30, 2005 4:11 pm
Location: Canada

Re: Measuring, how can I get hold of the latest measuring

Post by Vasyl-Tracker Dev Team » Mon Sep 20, 2010 9:09 am

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
Vasyl Yaremyn
Tracker Software Products
Project Developer

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.

magthenop
User
Posts: 43
Joined: Tue Sep 07, 2010 8:35 am

Re: Measuring, how can I get hold of the latest measuring

Post by magthenop » Fri Sep 24, 2010 7:35 am

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.

User avatar
Vasyl-Tracker Dev Team
Site Admin
Posts: 1923
Joined: Thu Jun 30, 2005 4:11 pm
Location: Canada

Re: Measuring, how can I get hold of the latest measuring

Post by Vasyl-Tracker Dev Team » Fri Sep 24, 2010 10:09 am

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.
Vasyl Yaremyn
Tracker Software Products
Project Developer

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.

magthenop
User
Posts: 43
Joined: Tue Sep 07, 2010 8:35 am

Re: Measuring, how can I get hold of the latest measuring

Post by magthenop » Mon Sep 27, 2010 8:39 am

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?

User avatar
Vasyl-Tracker Dev Team
Site Admin
Posts: 1923
Joined: Thu Jun 30, 2005 4:11 pm
Location: Canada

Re: Measuring, how can I get hold of the latest measuring

Post by Vasyl-Tracker Dev Team » Mon Sep 27, 2010 9:59 am

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)
Vasyl Yaremyn
Tracker Software Products
Project Developer

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.

magthenop
User
Posts: 43
Joined: Tue Sep 07, 2010 8:35 am

Re: Measuring, how can I get hold of the latest measuring

Post by magthenop » Mon Sep 27, 2010 12:30 pm

:D It works so nice now! Thanks a million. :mrgreen:

User avatar
Tracker Supp-Stefan
Site Admin
Posts: 13424
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Measuring, how can I get hold of the latest measuring

Post by Tracker Supp-Stefan » Mon Sep 27, 2010 1:35 pm

All the kudos to Vasyl :)

Cheers,
Stefan

magthenop
User
Posts: 43
Joined: Tue Sep 07, 2010 8:35 am

Re: Measuring, how can I get hold of the latest measuring

Post by magthenop » Mon Sep 27, 2010 4:21 pm

I could not agree more, all kudos to vasil :mrgreen:

User avatar
Paul - Tracker Supp
Site Admin
Posts: 4924
Joined: Wed Mar 25, 2009 10:37 pm
Location: Chemainus, Canada
Contact:

Re: Measuring, how can I get hold of the latest measuring

Post by Paul - Tracker Supp » Wed Sep 29, 2010 4:05 pm

"All praise to the Great One..." ;-)
_________________
If posting files to this forum - you must archive the files to a ZIP, RAR or 7z file or they will not be uploaded - thank you.

Best regards

Paul O'Rorke
Tracker Support North America
http://www.tracker-software.com

Post Reply