Copy more information from Area Tool
Moderators: TrackerSupp-Daniel, Tracker Support, Paul - Tracker Supp, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Ivan - Tracker Software, Tracker Supp-Stefan
Copy more information from Area Tool
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.
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.
- Vasyl-Tracker Dev Team
- Site Admin
- Posts: 2353
- Joined: Thu Jun 30, 2005 4:11 pm
- Location: Canada
Re: Copy more information from Area Tool
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");
}
}
}
}
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.
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.
Re: Copy more information from Area Tool
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?
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
- Site Admin
- Posts: 6900
- Joined: Wed Mar 25, 2009 10:37 pm
- Location: Chemainus, Canada
- Contact:
Re: Copy more information from Area Tool
Hi kcd2015
if you right click --> complete rather than double clicking to complete you should not get the extra point.
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.
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
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
});
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.
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
Best regards
Paul O'Rorke
Tracker Support North America
http://www.tracker-software.com
Paul O'Rorke
Tracker Support North America
http://www.tracker-software.com
Re: Copy more information from Area Tool
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.
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.
- Tracker Supp-Stefan
- Site Admin
- Posts: 17929
- Joined: Mon Jan 12, 2009 8:07 am
- Location: London
- Contact:
Re: Copy more information from Area Tool
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
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
Okay, good to know. Thank you everyone for your input, it will be a big help to me.
- Tracker Supp-Stefan
- Site Admin
- Posts: 17929
- Joined: Mon Jan 12, 2009 8:07 am
- Location: London
- Contact:
Re: Copy more information from Area Tool
Is there online documentation that shows what objects and their methods/properties are available to me through the javascript?
- Will - Tracker Supp
- Site Admin
- Posts: 6815
- Joined: Mon Oct 15, 2012 9:21 pm
- Location: London, UK
- Contact:
Re: Copy more information from Area Tool
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,
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 (Europe)
Tracker Software Products Ltd.
http://www.tracker-software.com
Thank you.
Best regards
Will Travaglini
Tracker Support (Europe)
Tracker Software Products Ltd.
http://www.tracker-software.com
Re: Copy more information from Area Tool
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.Paul - Tracker Supp wrote: app.addToolButton({
cName: "Calc Segments Length!",
cExec: "doF()",
cTooltext: "Calc Segments Length!",
cEnable: true,
nPos: 0
});[/code]
- Will - Tracker Supp
- Site Admin
- Posts: 6815
- Joined: Mon Oct 15, 2012 9:21 pm
- Location: London, UK
- Contact:
Re: Copy more information from Area Tool
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:
https://www.pdf-xchange.com/PDFXVE6.zip
Cheers,
Are you using the latest release (Version 6 Build 318.1)? If not, please try the latest release and see if that helps:
https://www.pdf-xchange.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 (Europe)
Tracker Software Products Ltd.
http://www.tracker-software.com
Thank you.
Best regards
Will Travaglini
Tracker Support (Europe)
Tracker Software Products Ltd.
http://www.tracker-software.com
Re: Copy more information from Area Tool
I just installed it, rebooted my computer and it still isn't working.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:
https://www.pdf-xchange.com/PDFXVE6.zip
Cheers,
- Tracker Supp-Stefan
- Site Admin
- Posts: 17929
- Joined: Mon Jan 12, 2009 8:07 am
- Location: London
- Contact:
Re: Copy more information from Area Tool
Hello kcd2015,
I still have a few custom buttons on my toolbar and those work perfectly fine.
E.g. this is my first: 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
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);
}
}
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
Here is my js in it's entirety:
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.
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));
}
}
}
}
}
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
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.
- Tracker Supp-Stefan
- Site Admin
- Posts: 17929
- Joined: Mon Jan 12, 2009 8:07 am
- Location: London
- Contact:
Re: Copy more information from Area Tool
Hi kcd2015,
Glad to hear you figured out what was was the trouble!
Let us know if we can assist further!
Cheers,
Stefan
Glad to hear you figured out what was was the trouble!
Let us know if we can assist further!
Cheers,
Stefan