[Tool] Scale/Align annotations by two reference lines  SOLVED

Forum for the PDF-XChange Editor - Free and Licensed Versions

Moderators: PDF-XChange Support, Daniel - PDF-XChange, Chris - PDF-XChange, Sean - PDF-XChange, Paul - PDF-XChange, Vasyl - PDF-XChange, Ivan - Tracker Software, Stefan - PDF-XChange

Mathew
User
Posts: 581
Joined: Thu Jun 19, 2014 7:30 pm

[Tool] Scale/Align annotations by two reference lines  SOLVED

Post by Mathew »

This tool will scale and/or rotate selected annotations by drawing two reference lines.

I frequently need to scale stamps to overlay on drawings (usually stamps of sections of other drawings to compare differences). I made this tool to help scaling to fit.

To install, extract the zip file and save the contents to the Javascripts folder either in %APPDATA%\Tracker Software\PDFXEditor\3.0\ or in %PROGRAMFILES%\Tracker Software\PDF Editor
scaleAnnotsByRef v1.1.zip

It adds a toolbar button to the add-ins toolbar. It also adds a menu item to the Ribbon UI at Home > Selection (and in the Edit menu for the classic UI):
image.png

To use it, select the markup(s) you want to scale, and click the button. It should open a dialog:
image(1).png
Choose the options that you want to change on the selection, and press 'OK'

It should activate the arrow tool.
Draw the first arrow starting from a base point in the selected annotation, to a reference length on the annotation.
image(2).png
Draw the second arrow from the new base point to the length you want the annotations scaled to.
image(3).png
It should immediately scale the selected annotations.
If you chose to move it to the second origin it will also move it to the second start point.
If you chose to rotate it, it will rotate from the angle of the first line to the angle of the second line.
image(4).png
It works by scaling the .rect property of the annotations, changing the .rotation property, and (for lines and callouts) moving the points. Let me know if you see problems.

Limitations
  • It scales equally in the x and y direction, using the relative lengths of the two lines drawn (not of their relative x and y differences).
  • I don't know an easy way to cancel the tool once it's started. If you pick the tool again, it will cancel. Also if you pick the rectangle tool, or some non-line tool and draw with that, it will usually catch it. I've tried to fail gracefully, but let me know if it does something bad.

TL;DR
Getting the two lengths is difficult because javascript in PDFXChange doesn't have a way to interactively get points in the drawing, or pick areas, etc. I've worked around by setting up a timeout that waits until a new annotation is drawn, then grabbing that annotation and starting a new function.
You do not have the required permissions to view the files attached to this post.
Last edited by Mathew on Tue Dec 17, 2024 4:39 pm, edited 6 times in total.
User avatar
Stefan - PDF-XChange
Site Admin
Posts: 19868
Joined: Mon Jan 12, 2009 8:07 am

Re: Tool: Scale annotations by two reference lengths

Post by Stefan - PDF-XChange »

Hello Mathew,

Once again a lovely tool! Thanks for sharing it with everyone here in the forums - that is greatly appreciated!

Kind regards,
Stefan
Mathew
User
Posts: 581
Joined: Thu Jun 19, 2014 7:30 pm

Re: Tool: Scale annotations by two reference lengths

Post by Mathew »

I totally re-wrote this tool to make it work a bit more smoothly; it uses some of the xutil utilities I wrote for other tools, particularly xutil.getNewAnn(). I've also updated the first post above with instructions.

But the most useful change is that it will rotate as well as scale to the reference lines, so it's more of an 'align' tool now. I've made it translatable, also, if someone has the interest: See my other post about 1ang.js viewtopic.php?t=43253

scaleAnnotsByRef v1.0.zip

If you already had the previous tool installed, I changed the file name, so you'll need to manually delete 'Scale by reference lengths.js'.

Changes
  • Add custom dialog for options,
  • add rotate to align,
  • add to ribbon UI, 40x40 icon,
  • filename changed from "Scale by reference lengths.js" --> "scaleAnnotsByRef.js",
  • rewrite to use xutil
You do not have the required permissions to view the files attached to this post.
KD952
User
Posts: 109
Joined: Mon Feb 13, 2023 6:13 am

Re: [Tool] Scale/Align annotations by two reference lines

Post by KD952 »

I don't know what to say.
It is all I ever wanted and more.
Thank you kindly Mathew .

Sincerely,
Daniel
User avatar
Stefan - PDF-XChange
Site Admin
Posts: 19868
Joined: Mon Jan 12, 2009 8:07 am

[Tool] Scale/Align annotations by two reference lines

Post by Stefan - PDF-XChange »

:)
Mathew
User
Posts: 581
Joined: Thu Jun 19, 2014 7:30 pm

Re: [Tool] Scale/Align annotations by two reference lines

Post by Mathew »

KD952 wrote: Fri Oct 25, 2024 6:28 am I don't know what to say.
It is all I ever wanted and more.
:D
User avatar
Paul - PDF-XChange
Site Admin
Posts: 7361
Joined: Wed Mar 25, 2009 10:37 pm

Re: [Tool] Scale/Align annotations by two reference lines

Post by Paul - PDF-XChange »

Hi, Mathew

such great contribution Mathew!

As always, very much appreciated.

YOU ROCK!
Best regards

Paul O'Rorke
PDF-XChange Support
http://www.pdf-xchange.com
Mathew
User
Posts: 581
Joined: Thu Jun 19, 2014 7:30 pm

Re: [Tool] Scale/Align annotations by two reference lines

Post by Mathew »

Thanks all. I'm glad it's useful and if you see bugs please post about it.

I made a very small change that only affects the Classic UI: I moved it to the Edit menu after Transform... If you don't use the classic UI this revision will make no difference.
scaleAnnotsByRef v1.0.1.zip
You do not have the required permissions to view the files attached to this post.
User avatar
Dimitar - PDF-XChange
Site Admin
Posts: 2208
Joined: Mon Jan 15, 2018 9:01 am

Re: [Tool] Scale/Align annotations by two reference lines

Post by Dimitar - PDF-XChange »

Thanks, Mathew.

We appreciate your effort.

Regards.
Mathew
User
Posts: 581
Joined: Thu Jun 19, 2014 7:30 pm

Re: [Tool] Scale/Align annotations by two reference lines

Post by Mathew »

Slight update to fix some bugs and make a bit less fragile. Now it highlights the tool icon in the menu and toolbar while the tool is running - can select the tool again to cancel it:
image.png
scaleAnnotsByRef v1.1.zip
Changes v1.1
  • Fix bug if called when already running
  • mark menu item when running
  • fix bug cancelling timeout (update to xutil v0.5)
  • remove text label in add-on toolbar to make it fit tighter
You do not have the required permissions to view the files attached to this post.
User avatar
Daniel - PDF-XChange
Site Admin
Posts: 11043
Joined: Wed Jan 03, 2018 6:52 pm

[Tool] Scale/Align annotations by two reference lines

Post by Daniel - PDF-XChange »

:)
Dan McIntyre - Support Technician
PDF-XChange Co. LTD

+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com