Often for markup I need to show hatch patterns, and it's laborious to mark them up with individual lines. Also, sometimes the default solid fills are sometimes not optimal to highlight areas in pdfs. This tool uses the same format as the hatch patterns that come with AutoCAD, so any of the thousands of hatch patterns for that program can be used.
The tool adds a Pencil annotation to the drawing with the hatch pattern, and subject is "Hatch " followed by the name of the pattern. The attached pdf file has a listing of all the included hatch patterns.
To install:
- Extract the attached javascript and hatch patterns file from the zip file and save both in the Javascripts folder either in the application folder, or in C:\Users\[USERNAME]\AppData\Roaming\Tracker Software\PDFXEditor\3.0\Javascripts )
- Restart PDF-XChange and it should create a Hatch button in the add-on toolbar, and a "Hatch" option in the Comments menu (in the classic UI)
First select annotation(s) to draw the hatch patterns around, then click the hatch button. (It won't do anything if you haven't selected an annotation).
You'll get a dialog:
Hatch Parameters
These are properties of the hatch that need to be re-drawn to change (ie you can't adjust them after the hatch is drawn, you'll just need to delete the hatch and draw it again).
Hatch Pattern: Select the hatch pattern to use.
Rotation: You can rotate the angle that the hatch is drawn.
Scale: This is a scale factor on the defined hatch. Watch out: If the scale is too small, the hatch will be so dense that it may appear solid. It also will be many millions of lines and may take a long time to draw. If it is too large, the hatch may not even be drawn inside your shape (ie, the shape may fit inside an empty area of the pattern). I've shared a tool below to scale up/down the hatch patterns themselves viewtopic.php?p=173230#p173230
Island Detection: This is how the tool decides whether it is inside or outside your shape. My implementation is not very sophisticated, so it's easily tripped up by shapes that have inside angles - see limitations below. There are three options:
- None: This draws between the outermost detected intersections of the hatch line and your selected annotation(s).
- Outer: If the hatch line crosses the annotation(s) more than twice, it only draws between the outer two intersections.
- Alternate: It alternates between intersections.
Code: Select all
const SHOW_CORNER_POINTS = false;
These are properties that can be changed if you select the hatch in PDF-XChange within the Properties toolbar. Because the hatch is just a Pencil annotation, you can also change border style, fill color, opacity, etc. from the Properties toolbar.
Color: There are some colors listed to draw the hatch - it also grabs the color of the selected items. For colors other than the basic ones, it just lists the RGB values.
Line width: Same as "border width" in the properties toolbar.
Preview
Selecting "OK" just draws the hatch.
"Preview" draws the hatch, and then asks if you want to keep it or change it.
Tool Settings
There are some settings that can be changed by editing lines 47-50 of the script.
Code: Select all
const HATCH_FILE_NAMES = ["HatchPatterns.pat"]; // names of hatch pattern files to load - will be loaded to menu in order
const ALWAYS_LOAD_PATTERNS = false; // if false the hatch patterns only load the first time the tool is used after application restart
const SHOW_CORNER_POINTS = true; // set to false to not add an annotation while picking corner points for origin
const MAX_SAVED_COLORS = 8; // maximum number of custom colors to save in the color dropdown
Limitations:
- Undo: There's a bug in PDF-XChange so if you add an annotation through javascript, it doesn't show up in the undo list. I'll report that separately. Just select and manually delete the hatch pattern if you don't want it.
- Fixed v2.0: I tried to make it load a text file with hatch patterns so I could use the AutoCAD .pat files directly, but I was stymied by the security settings.
- Pencil annotations are treated as rectangles. I didn't have the patience or ability to figure out how to interpret intersections with curving lines.
- Island detection is quite rudimentary. If someone else wants to come up with a better approach, please do! This script doesn't actually figure out if it is inside or outside a shape: It just finds intersections with each hatch line. So you can get some strange results with shapes that have inside corners. The "alternate" island detection seems to work best in most cases, so I generally just keep it on that. Depending on the hatch line angle, the None method will draw outside a shape's boundaries: Similarly, the Outer method may skip interior parts of a shape: For this shape, only the Alternate method works:
- Respond to this thread if you see other problems that I may be able to fix.