AfraLISP - Learn AutoLISP for AutoCAD productivity

Creating Hatch Patterns

by Kenny Ramage

You want to what?! Create a hatch pattern? Crikey, you're brave. Honestly, though, simple hatch patterns are quite easy to create. It's the complicated ones that take time, effort, a good understanding of how to create hatches and linetypes, some knowledge of geometry and quite a bit of imagination.

Before proceeding with this tutorial, I would strongly recommend that you read my tutorial on creating custom linetypes. Linetypes are used extensively throughout hatch patterns and a good understanding is a pre-requisite.

Let's take a look at a simple hatch pattern first. The same principal applies to even the most complicated hatch pattern so, as my Mum often says, "Pay attention!"

A hatch pattern definition is stored in a simple ASCII text file with an extension of PAT. You can append a hatch pattern to an existing file if you wish, or you can store it in it's own file. If you store it in it's own file, the file name must match the name of the hatch pattern. We are going to create our own hatch definition or pattern file. O.K. Open Notepad and add this line :

*Dashdot, Dashes and dots

This is the name of our hatch pattern followed by a description of the pattern, separated by a comma (,). Now add this on the next line :

0, 0,0, 0,0.5, 0.5,-0.25,0,-0.25,0,-0.25

This line describes a single drawing pass over the hatch pattern. In this example we are only using a single pass so we will only get one line. Save your file as "Dashdot.pat". If you loaded this hatch pattern and added it to your drawing, it would look like this :

simple custom hatch

The syntax of each drawing line is as follows :

Angle, X,Y Origin, Offset-x,Offset-y, Pen Command Pattern

Let's look a bit closer at each field :

0, 0,0, 0,0.5, 0.5,-0.25,0,-0.25,0,-0.25

The first field, Angle, which in our case is "0", determines the angle at which the line is to be drawn. In our case it will be drawn horizontally. Don't confuse this with the angle of the hatch pattern which is controlled by the AutoCAD Hatch command. Look at a hatch pattern as a successive series of lines that are drawn from left to right, then from down to up.

0,  0,0, 0,0.5, 0.5,-0.25,0,-0.25,0,-0.25

The second field is the X,Y Origin. This controls the starting point of the line segment. This is not an AutoCAD co-ordinate, but rather a relative distance from the current Snap base point of the drawing. All hatch patterns have a point of origin. Since this point of origin is the same throughout, you're assured that the patterns will line up.

0, 0,0, 0,0.5, 0.5,-0.25,0,-0.25,0,-0.25

The third field is the X-Offset and Y-offset values. 0 is the X-Offset and 0.5 is the Y-Offset. The hatch pattern will begin at an arbitrary origin and proceed to draw a group from left to right, then advance upward in the Y direction. 0,0.5 means that each successive line in the pattern will move to the right 0 units and up by 0.5 units. This results in the 0.5 spacing between the lines. The offset is relative to the initial angle given in the line, so that angle forms the X axis for the offset. The Y value Offset is quite easy to understand - it gives you the spacing between the lines. But why would you want to offset the X value, and what effect does that have? Think of a brick wall. Each successive line of bricks is offset to the right a little to create a pattern. So, 0.5,1 would space the bricks upward by 1 unit, and every other line would be offset by 0.5 to the right of the origin, creating a "stepladder" effect.

0, 0,0, 0,0.5, 0.5,-0.25,0,-0.25,0,-0.25

The fourth and final group is the linetype definition or the dash dot pattern. In words, this pattern is saying:
"Draw a line 0.5 units long, lift the pen for 0.25 units, draw a dot, lift the pen for 0.25 units, draw another dot, lift the pen for 0.25 units, draw a third dot, lift the pen for 0.25 units and then repeat the process".

The dashdot pattern was drawn using only one definition line, let's try one with two. Open a new file with Notepad and add this :

*VASTRAP, Vastrap Checkered Plate
0, 0,0.09375, 0.25,0.25, 0.25,-0.25
90, 0.125,0.21875, 0.25,0.25, 0.25,-0.25

Close the file and save it as "Vastrap.pat". This hatch will produce a pattern like this :

a more complex custom hatch

Even though I defined the pattern with 0 and 90 degree lines, you can rotate the pattern to get the desired effect. I made the pattern at 0 and 90 degrees to avoid having to calculate the angles. (Chicken hey!)

As I said at the beginning, simple hatch patterns are quite easy to create, but the complicated one's? Well, that's another story. Would you like a couple of hundred hatch patterns to play around with and analyze? Some simple, some "very" complicated! You would? Then just place your mouse here and click.