PDF-XChange - Tracker PDF Viewer - TIFF-XChange - Image-XChange - XMF-XChange - Raster-XChange - Support

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

 
kcd2015
User
Topic Author
Posts: 10
Joined: Tue Oct 11, 2016 6:55 pm

Copy more information from Area Tool

Tue Oct 11, 2016 7:01 pm

How difficult will it be to write a plugin, or javascript, that will report the lengths of each side of a polygon drawn with the 'Area Tool'?

What would be perfect for me is if I could right click on the "Area Info" box and have an option to copy this data to clipboard.
 
User avatar
Vasyl-Tracker Dev Team
Site Admin
Posts: 1855
Joined: Thu Jun 30, 2005 4:11 pm
Location: Canada

Re: Copy more information from Area Tool

Tue Oct 11, 2016 9:53 pm

You may try to use the following script:

var sa = this.selectedAnnots;
if (sa.length != 0)
{
    var a = sa[0];
    if (a.type == "PolyLine" || a.type == "Polygon")
    {
        var v = a.vertices;
        if (v.length > 1)
        {
            for (i=0;i<v.length-1;i++)      
            {
                var p0 = v[i];
                var p1 = v[i + 1];
                var dx = p0[0] - p1[0];
                var dy = p0[1] - p1[1];
                var len = Math.sqrt(dx * dx + dy * dy);
                console.println("segment #" + i + " length: " + util.printf("%,0.3f", len/72.0) + " in");
            }
        }
   }
}
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.
 
kcd2015
User
Topic Author
Posts: 10
Joined: Tue Oct 11, 2016 6:55 pm

Re: Copy more information from Area Tool

Wed Oct 12, 2016 3:12 pm

Thank you, that works great! Now I can start hacking. Now I have two questions:

1) What is the variable/how do I access the scale of the selectedAnnot?
2) When I trace out a polygon/area I double-click my last corner to finish the area. I've discovered from this script that that method has a side effect of creating to vertices at the point of the double click. So the script prints out a very tiny length for the last side. Is there a different way to end/close an area? (I know I can work around this by tweaking the script to skip the very last vertice and use first point and second to last point for the final side length.)
[edit]
3) Is there a way to save this script for easy access later? Maybe assign it to a hot key?
4) Do you have a link to some docs for the object names and their properties/methods?
 
Paul - Tracker Supp
User
Posts: 4713
Joined: Wed Mar 25, 2009 10:37 pm
Location: Chemainus, Canada
Contact:

Re: Copy more information from Area Tool

Wed Oct 12, 2016 8:18 pm

Hi kcd2015

if you right click --> complete rather than double clicking to complete you should not get the extra point.
function doF()
{
    console.show();
    console.println(">>>>");
    var sa = this.selectedAnnots;
    if (sa.length != 0) {
        var a = sa[0];
        if (a.type == "PolyLine" || a.type == "Polygon") {
            var v = a.vertices;
            if (v.length > 1) {
                for (i = 0; i < v.length - 1; i++) {
                    var p0 = v[i];
                    var p1 = v[i + 1];
                    var dx = p0[0] - p1[0];
                    var dy = p0[1] - p1[1];
                    var len = Math.sqrt(dx * dx + dy * dy);
                    console.println("segment #" + i + " length: " + util.printf("%,0.3f", len / 72.0) + " in");
                }
            }
        }
    }
    console.println("<<<<");
}

app.addToolButton({
    cName: "Calc Segments Length!",
    cExec: "doF()",
    cTooltext: "Calc Segments Length!",
    cEnable: true,
    nPos: 0
});


Put the JavaScript file in the folder: C:\Program Files\Tracker Software\PDF Editor\JavaScripts Create it if it doesn't already exist.
The second function will add a button to the Editor that will when clicked display the JS console and your results. It works with both the Area and Perimeter Tools.

Image

In this example we divided the result by 72 to get from points to inches. You could also divide by 28.346456693 for cm. With these you can then calculate your own coefficient to use when converting to other units.

I found this helpful for that: http://www.unitconversion.org/typography/centimeters-to-points-computer-conversion.html

hth
_________________
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
 
kcd2015
User
Topic Author
Posts: 10
Joined: Tue Oct 11, 2016 6:55 pm

Re: Copy more information from Area Tool

Wed Oct 12, 2016 9:39 pm

That's great again! Thank you.

Regarding the scaling. I'm using the area tool to take off dimensions from construction blue prints. When I use the Area, Distance, or Perimeter tool I already set scale in the tool bar. It would be nice if I could access this user defined scale from the javascript, is that possible?

I know I can calculate that by hand if I have to when I copy my lengths to my spreadsheet, only that's another opportunity for me to make an expensive mistake.

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

Re: Copy more information from Area Tool

Thu Oct 13, 2016 9:43 am

Hello kcd2015,

The JS code that executes has access to the file, and can read the objects in it and give you the results, but it can't access what the current scale is, so you will e.g. need to manipulate the code yourself to make it work in different scales.
Paul recommended how you can make it a button, but if you need scale other than the default - you can copy and paste that JS code directly in the console, change the coefficient to set the desired scale, and then execute it from there - obtaining your results directly calculated as needed.

Regards,
Stefan
 
kcd2015
User
Topic Author
Posts: 10
Joined: Tue Oct 11, 2016 6:55 pm

Re: Copy more information from Area Tool

Thu Oct 13, 2016 1:40 pm

Okay, good to know. Thank you everyone for your input, it will be a big help to me.
 
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 12027
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Copy more information from Area Tool

Thu Oct 13, 2016 1:48 pm

:)
 
kcd2015
User
Topic Author
Posts: 10
Joined: Tue Oct 11, 2016 6:55 pm

Re: Copy more information from Area Tool

Sat Oct 15, 2016 7:53 pm

Is there online documentation that shows what objects and their methods/properties are available to me through the javascript?
 
User avatar
Will - Tracker Supp
Site Admin
Posts: 5881
Joined: Mon Oct 15, 2012 9:21 pm
Location: Chemainus, BC
Contact:

Re: Copy more information from Area Tool

Mon Oct 17, 2016 7:53 am

Hi kcd2015,

Thanks for the post - We support most of the features and commands available here:
http://www.adobe.com/content/dam/Adobe/ ... erence.pdf

Cheers,
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

Will Travaglini
Tracker Support
http://www.tracker-software.com
 
kcd2015
User
Topic Author
Posts: 10
Joined: Tue Oct 11, 2016 6:55 pm

Re: Copy more information from Area Tool

Mon Nov 14, 2016 3:27 pm

Paul - Tracker Supp wrote:
app.addToolButton({
cName: "Calc Segments Length!",
cExec: "doF()",
cTooltext: "Calc Segments Length!",
cEnable: true,
nPos: 0
});[/code]


I don't know what's changed but this code doesn't seem to be working anymore. When I load PDF-XChange this button is no longer available to me. It worked before just fine.
 
User avatar
Will - Tracker Supp
Site Admin
Posts: 5881
Joined: Mon Oct 15, 2012 9:21 pm
Location: Chemainus, BC
Contact:

Re: Copy more information from Area Tool

Tue Nov 15, 2016 10:18 am

Hi kcd2015,

Are you using the latest release (Version 6 Build 318.1)? If not, please try the latest release and see if that helps:
http://www.tracker-software.com/PDFXVE6.zip

Cheers,
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

Will Travaglini
Tracker Support
http://www.tracker-software.com
 
kcd2015
User
Topic Author
Posts: 10
Joined: Tue Oct 11, 2016 6:55 pm

Re: Copy more information from Area Tool

Wed Nov 23, 2016 2:38 pm

Will - Tracker Supp wrote:
Hi kcd2015,

Are you using the latest release (Version 6 Build 318.1)? If not, please try the latest release and see if that helps:
http://www.tracker-software.com/PDFXVE6.zip

Cheers,


I just installed it, rebooted my computer and it still isn't working.
 
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 12027
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Copy more information from Area Tool

Wed Nov 23, 2016 3:52 pm

Hello kcd2015,

I still have a few custom buttons on my toolbar and those work perfectly fine.
E.g. this is my first:
app.addToolButton({   
 cName: "PrintAll",   
// oIcon: oIcon,   
 cExec: "printAllOpenedDocs();",   
 cTooltext: "Print All Documents",   
 nPos: 0 
});


function printAllOpenedDocs(){
  var ad = app.activeDocs;
  for (var i = 0; i < ad.length; i++)
  {
    var pp = ad[i].getPrintParams();
    // uncomment the next line to print without dialog for each document
    // pp.interactive = pp.constants.interactionLevel.silent;
    ad[i].print(pp);
  }
}
that prints all opened docs for me.

Make sure that nPos is unique - as if you try to add more than one button with the same nPos - only one of them will be shown.

Regards,
Stefan
 
kcd2015
User
Topic Author
Posts: 10
Joined: Tue Oct 11, 2016 6:55 pm

Re: Copy more information from Area Tool

Wed Nov 23, 2016 4:12 pm

Here is my js in it's entirety:
app.addToolButton({
    cName: "CalcLnLengths",
    cExec: "calcLineLengths();",
    cTooltext: "Calc Segment Length!",
    cEnable: true,
    nPos: 0
});

function calcLineLengths()
{
    console.show();
    console.clear();
    var sa = this.selectedAnnots;
    if (sa.length != 0) {
        var a = sa[0];
        if (a.type == "PolyLine" || a.type == "Polygon") {
            var v = a.vertices;
            if (v.length > 1) {
                for (i = 0; i < v.length - 1; i++) {
                    var p0 = v[i];
                    var p1 = v[i + 1];
                    var dx = p0[0] - p1[0];
                    var dy = p0[1] - p1[1];
                    var len = Math.sqrt(dx * dx + dy * dy);
                    console.println( (i+1) + ", " + util.printf("%,0.13f", len));
                }
                if (a.type == "Polygon") {
                  var p0 = v[0];
                  var p1 = v[v.length - 1]
                  var dx = p0[0] - p1[0];
                  var dy = p0[1] - p1[1];
                  var len = Math.sqrt(dx * dx + dy * dy);
                  console.println( (i+1) + ", " + util.printf("%,0.13f", len));
                }
            }
        }
    }
}


This was working just fine then one day the button just dissappeared without any changes that I'm aware of. As far as I can tell all tool bars are enabled.

When run my calcLineLengths() function from the js console that works so we know the js file is being read when PDF editor loads.
 
kcd2015
User
Topic Author
Posts: 10
Joined: Tue Oct 11, 2016 6:55 pm

Re: Copy more information from Area Tool

Wed Nov 23, 2016 4:18 pm

I'm sorry, I'm an idiot... the toolbar was 'minimized', all is well... This toolbar UI is ever so slightly different than standard so it threw me off.
 
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 12027
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Copy more information from Area Tool

Wed Nov 23, 2016 4:40 pm

Hi kcd2015,

Glad to hear you figured out what was was the trouble!
Let us know if we can assist further!

Cheers,
Stefan

Who is online

Users browsing this forum: No registered users and 1 guest