patWriter is a Python script that converts any lines drawn in AutoCAD into a hatch pattern file (.pat) for use in AutoCAD.
Although AutoCAD includes a standard library of hatch patterns, custom hatches allow you to create and use your own patterns to suit your needs. The advantage of hatch patterns over AutoCAD's SuperHatch tool is that hatches support annotative scaling which automatically resizes the pattern based on the current viewport or annotation scale while SuperHatch does not.
The examples in this repository are designed for mapping applications in the legend style of Tailte Éireann (formerly Ordnance Survey Ireland).
- In AutoCAD, draw one unit cell of the pattern you want to use as hatch pattern. Polylines, Arcs, Splines, etc. should be exploded and divided into individual line objects.
- Using AutoCAD's Data Extraction wizard, export information related to the unit cell line objects:
- The first time you extract data, you are prompted to save the data extraction settings in a data extraction (.dxex) file. This file can also be used again as a template to perform the same type of extraction in a different drawing.
- Select the line objects in the current drawing using the selection tool.
- On the next page, ensure only line objects are selected in the table.
- In the properties table, include
Angle,End X,End Y,Length,Start XandStart Yfrom the Geometry category. - Refine the data table if required.
- Output the data to an external
.txtfile. - Create the file by clicking Finish.
- After downloading the patWriter.py script, run it using:
replacing
python3 patWriter.py -f <path_to_txt_data_extraction> -b bbx bby -w <hatch_name><path_to_txt_data_extraction>to the location of the .txt file exported from AutoCAD's Data Extraction wizard in the previous step,bbx bbywith bounding box length and width of the unit cell and<hatch_name>with the name for writing the .pat file. - To make the hatch pattern available for use in AutoCAD, add its location as a custom folder to the application support files search paths in Options > Files > Support File Search Path > Add.
| Name | Pattern |
|---|---|
| Woodland Coniferous | ![]() |
| Woodland Deciduous | ![]() |
| Woodland Mixed | ![]() |
| Outcrop | ![]() |
| Marsh | ![]() |
| Bog | ![]() |
| Flatrock | ![]() |
| Sand | ![]() |
| Sand and Shingle | ![]() |
This code is based on the pat_writer repository by Justin-Yeung which is mainly intended for Rhino 8.








