Page 1 of 1

Copy more information from Area Tool

Posted: Tue Oct 11, 2016 7:01 pm
by kcd2015
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.

Re: Copy more information from Area Tool

Posted: Tue Oct 11, 2016 9:53 pm
by Vasyl-Tracker Dev Team
You may try to use the following script:

Code: Select all

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

Re: Copy more information from Area Tool

Posted: Wed Oct 12, 2016 3:12 pm
by kcd2015
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?

Re: Copy more information from Area Tool

Posted: Wed Oct 12, 2016 8:18 pm
by Paul - Tracker Supp
Hi kcd2015

if you right click --> complete rather than double clicking to complete you should not get the extra point.

Code: Select all

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/typograph ... rsion.html

hth

Re: Copy more information from Area Tool

Posted: Wed Oct 12, 2016 9:39 pm
by kcd2015
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

Re: Copy more information from Area Tool

Posted: Thu Oct 13, 2016 9:43 am
by Tracker Supp-Stefan
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

Re: Copy more information from Area Tool

Posted: Thu Oct 13, 2016 1:40 pm
by kcd2015
Okay, good to know. Thank you everyone for your input, it will be a big help to me.

Re: Copy more information from Area Tool

Posted: Thu Oct 13, 2016 1:48 pm
by Tracker Supp-Stefan
:)

Re: Copy more information from Area Tool

Posted: Sat Oct 15, 2016 7:53 pm
by kcd2015
Is there online documentation that shows what objects and their methods/properties are available to me through the javascript?

Re: Copy more information from Area Tool

Posted: Mon Oct 17, 2016 7:53 am
by Will - Tracker Supp
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,

Re: Copy more information from Area Tool

Posted: Mon Nov 14, 2016 3:27 pm
by kcd2015
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.

Re: Copy more information from Area Tool

Posted: Tue Nov 15, 2016 10:18 am
by Will - Tracker Supp
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,

Re: Copy more information from Area Tool

Posted: Wed Nov 23, 2016 2:38 pm
by kcd2015
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.

Re: Copy more information from Area Tool

Posted: Wed Nov 23, 2016 3:52 pm
by Tracker Supp-Stefan
Hello kcd2015,

I still have a few custom buttons on my toolbar and those work perfectly fine.
E.g. this is my first:

Code: Select all

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

Re: Copy more information from Area Tool

Posted: Wed Nov 23, 2016 4:12 pm
by kcd2015
Here is my js in it's entirety:

Code: Select all

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.

Re: Copy more information from Area Tool

Posted: Wed Nov 23, 2016 4:18 pm
by kcd2015
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.

Re: Copy more information from Area Tool

Posted: Wed Nov 23, 2016 4:40 pm
by Tracker Supp-Stefan
Hi kcd2015,

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

Cheers,
Stefan