
Last lesson, we began looking at how linetype patterns are constructed in AutoCAD. We saw that there are many commands and system variables that let you load and modify linetypes. We learned how to write a new linetype definition within AutoCAD using the -Linetype Create command, as follows:
Command: -linetype ?/Create/Load/Set: C Name of linetype to create: dit-dah Wait, checking if linetype already defined .... Descriptive text: . __ . __ . __ . __ Enter pattern (on next line): A, .25,-.1,0,-.1 Command:
Unlike hatch patterns, AutoCAD stores your new linetype in the Acad.Lin file, ready for future use. (By the way, new linetypes are added to the end of the Acad.Lin file.) This lesson, we test the new linetype, learn to edit the LIN file directly, and go on to find out about complex (2D) linetypes.
As we learned back in the AutoLISP tutorials, it is important to test a new programming creation. As simple as they are, linetypes are no exception. I test the Dit-Dah pattern, as follows:
1. Use the -Linetype Load command to load the pattern into drawing:
Command: -linetype
?/Create/Load/Set: L
Linetype(s) to load: dit-dah
2. Up pops the Select Linetype File dialog box. Select Acad.Lin and click Open. AutoCAD confirms:
Linetype DIT-DAH loaded.
3. Use the -Linetype Set command to set the linetype, as follows:
?/Create/Load/Set: S
New entity linetype (or ?) <BYLAYER>:
4. Here I can type either the name of a loaded linetype (such as "dit-dah") or type "?" to see which linetypes are already loaded. For fun, I'll type ? and AutoCAD tells me what I can type:
BYLAYER, BYBLOCK, or one of these loaded linetypes:
Name Description
------------------ -------------------------------
CONTINUOUS Solid
line
DIT-DAH .
__ . __ . __
5. This time, I get serious and set the current linetype to "dit-dah":
?/Create/Load/Set: S
New entity linetype (or ?) <BYLAYER>: dit-dah
?/Create/Load/Set: [press Enter]
6. Now I draw a line and appreciate the linetype it is drawn with. My debugging session is over.
Just as with the hatch pattern's Acad.Pat file, I can directly edit the Acad.Lin linetype file to create a custom linetype. Here's how:
1. Start a text editor (not a word processor), such as NotePad.
2. Load the Acad.Lin file from the \Support subdirectory.
3. When I scroll down to the end of the file, I see the Dit-Dah pattern we defined last lesson.
4. I can modify an existing linetype or add a new linetype. The process is exactly the same as when I did it within AutoCAD, with two exceptions: (1) AutoCAD isn't there to prompt me; and (2) I don't need to use the "A" prefix.
To recap, the linetype definition consists of two lines of text:
Line 1 is the header, such as "*DIT-DAH, . __ . __ . __" , where:
* (Asterisk)
Indicates the start of a new linetype definition. DIT-DAH Name
of the linetype.
, (Comma)
Separates the name from the description.
. __ . __
Describes the linetype (to a maximum of 47 characters), which
is displayed by the Linetype ? command.
Line 2 is the data, such as "A, .25,-.1,0,-.1", where:
A
The optional alignment flag, which forces AutoCAD to start and
end the linetype with a line.
.25
Length of a dash when LtScale = 1.0; every linetype data
line must begin with a dash.
-.1
Length of a gap when LtScale = 1.0; every linetype data
line must follow the initial dash with a gap.
0
A dot.
I can use ; (semi-colon) to prefix any line as a comment line. Anything after the semi-colon is ignored by AutoCAD.
5. Save the LIN file with the same name (Acad.Lin) or a new name, then test it within AutoCAD.
Introduced with AutoCAD Release 13 (and LT Release 3), "complex" linetypes are 2D: they can wiggle back and forth (within limits) and include text characters. Truth be told, that's all they are: text -- or, more accurately, shapes.
The complex linetype can consist entirely of 2D shapes, or can be mixture of 2D shapes and the 1D linetype codes -- the dash, gap, and dot we learned of earlier. The 2D shapes can be a combination of: (1) text characters from an SHX font file; and/or (2) shapes from an SHX shape file. AutoCAD comes with seven complex linetypes. Two of them -- the gas line and the hot water supply -- simply combine a dash and gap with the letters GAS and HW from the Standard text style (as defined by the Txt.Shx font file). Here is what the code looks like, as found in the LtypeShp.Lin 2D linetype definition file:
*HOT_WATER_SUPPLY,---- HW ---- HW ---- HW ---- HW ----
HW ----
A,.5,-.2,["HW",STANDARD,S=.1,R=0.0,X=-0.1,Y=-.05],-.2
Much of this looks familiar to me, with the exception of the stuff between the square brackets. That allows the embedding of text in a linetype. Here's what it means:
"HW"
Print these letters between the dashes.
STANDARD
Apply this text style to the text. This is optional; when missing,
AutoCAD uses the current text style, stored in system variable
TextStyle.
S=.1
This is the text scale factor. It means one of two things: (1)
when the text style's height is 0 (as is so often the case),
then S defines the height; in this case, 0.1 units; or
(2) when the text style height parameter is not 0, then multiple
the text style's height by this number; in this case, the linetype
would place the text at 10% of the height defined in the text
style.
R=0.0
Rotates the text relative to the direction of the line; in this
case, 0.0 means there is no rotation. The default measurement
is degrees; use r to specify radians, g for grads, or d for degrees,
such as R=150g. This parameter is optional and can be
left out. In that case, AutoCAD assumes zero degrees.
A=0.0
Rotates the text relative to the x-axis (the "A" is
short for Absolute); this ensures the text is always oriented
in the same direction, no matter the direction of the line. By
the way, the rotation is always performed within the text baseline
and capital height. That's so that I don't get text rotated way
off near the orbit of Pluto.
X=-0.1
This parameter shifts text in the x-direction from the linetype
definition vertex, which helps center the text in the line.
Y=-0.05
Once again, shifts the text but in the y-direction from the linetype
definition vertex. In both cases, the units are in linetype scale
factor, which is stored in system variable LtScale.
Summing up, I can create a text-based linetype with a single parameter, such as ["HW"] or I can execute fine control over the font, size, rotation, and position with six parameters. Only problem is that Autodesk didn't include a "linetype editor" to let me visually tweak the parameters until they look right (MicroStation, for example, has a built-in linetype editor). Instead, it's a tedious back and forth between editing the LTypeShp.Lin file, then loading it into AutoCAD, and testing the linetype.
But embedding text is not the last word in complex linetypes. Not at all. The other thing I can embed is a shape from an SHX file. AutoCAD old timers will remember a time -- say, about 15 years ago -- when shapes were the preferred substitute for blocks. Shapes were faster and more compact, a serious consideration when an 8MHz 8086 CPU was considered a hot machine and math chips were too pricey to afford. The use of shapes pretty much faded away as CPUs grew faster and the math chips became free. With the complex linetype, Autodesk found a new use for the languishing shape file: Release 13 and LT Release 3 introduced a new SHP file named LTypeShp.Shx. The file has the five shapes used by the other five complex linetypes. To use one of these takes three parameters:
*BATTING,SSSSSSSSSSSSSSSSSSSSSSSS
A,.0001,[BAT,ltypeshp.shx,s=.1],-.4
BAT
This is the name of shape; when AutoCAD cannot find the shape,
the linetype is merely drawn without it. ltypeshp.shx Name of
compiled shape file; I can add my own shapes to this file but
coding shapes is hard work. Here's what the coding for this batting
symbol looks like in the source code LTypeShp.Shp file:
*134,10,BAT 025,10,2,-044,04B,10,2,044,025,0
s=.1
The scale factor for the size of the shape, as above.
Just kidding. There is no such thing as a 3D linetype in AutoCAD. If there were, I guess it might look like a bottle brush or the ribs on an electrical cord's strain relief.
Comments on this tutorial series? Tell me about it.