AfraLISP - Learn AutoLISP for AutoCAD productivity

Controlling Complex Linetypes

by Kenny Ramage

Since AutoCAD R13, text can be part of the repeating pattern in a line. Lines with repeating text are called complex linetypes. The definition of linetypes are stored in an ascii text file with a .LIN file extension. The acad.lin file contains default linetypes and this file can be edited to include complex linetypes. Linetype definitions can also be defined in a separate .LIN file with a unique name, such as ltyeshp.lin in the C:\Users\UserName\AppData\Roaming\Autodesk\AutoCAD 2010\R18.0\enu\Support\ (or similar) directory. You can use a text editor such as Windows Notepad or DOS Edit to create and modify complex linetypes.

The repeating segments for complex lines are defined in the same manner as the simple linetype. In a complex linetype, brackets are used to enclose the description of text to be repeated along the line. The position and size of the text in relation to the repeating line segments is determined with 4 controlling parameters named "transforms".

A transform will scale, rotate and offset in the X or Y direction the text in the complex linetype. The following example will add text that repeats along the line when included in a linetype definition.

["MC",NEWSTYLE,S=1,R=90,X= -0.25,Y= -0.5]

The key to creating a successful complex linetype definition is understanding how to center the text in the blank elements of the line. Each element defining the repeating text is separated by commas. The characters contained in quotes are the characters that will be displayed along the line. The next element is the text style used for the repeating text. S=? controls the size, R=? controls the rotation and X=? and Y=? adjust the placement of the repeating text in relation to the rest of the line. How to set the height of the repeating text. There are four possible combinations of settings that can affect the height of the text in a complex linetype. When a text style is defined in AutoCAD it can either be defined with a height of zero or a particular number. If the style used in the complex linetype has a height of zero, then the number in the S=? transform will define the repeating text height when the line is placed in the drawing.

If the text style used in the complex linetype has a height other than zero, then the number in the S=? transform will be the multiplier for the text style height.

If the S=? transform is not included in the linetype definition, the text height is determined by the height defined in the text style. If the text style is defined with a height of zero and the S=? transform is not included in the linetype definition, the height of the repeating text will default to 1 (one). How to center the text in a complex linetype. The X=? and Y=? transforms are used to center align the repeating text. The X value required can be determined from the width of the repeating space where the text is to appear and the width of the repeating text. The repeating space is created by the negative number preceding the text definition.

One way to determine the width for the repeating text is to place the text in a drawing and use the distance command to measure the width. The DTEXT command can be used to create the text. Use the same height for the text that you intend to use in the linetype. After the space width and the character width have been determined, subtract the width of the text from the blank space where the text is going to be placed, and divide by two. Then subtract this number from the space to determine to distance to shift the text to the left in the space. Make sure to use a minus sign (-) to make the number negative.

The formula is :
SP-((SP - W)/2)

given :
SP = repeating space and W = width of the letters (text string)

To center the repeating text in the vertical orientation, divide the S=? transform by 2 and use this value. Add a minus sign to move the text down. (Example Y= -0.25) See the previous section on how to set the height of repeating text if the S=? transform is not the only control for the text height. The number for the Y=? transform must be the negative of half the repeating text height. (It must be a negative number to shift the text down from the line segments.) Settings in the drawing that affect complex linetypes. The style used for repeating text in a complex linetype must be defined as a text style in the drawing. Therefore, if you change a text style already used by complex linetypes in a drawing, the changes will also affect the display of repeating text in the next complex linetype you create in that drawing. The affected settings include Width factor, Obliquing angle, Backwards, Upside down, and Vertical.

For example, if you add text to a drawing that uses the same style as text in a complex linetype, and you change the text style to have an oblique angle, the text will also be oblique in the next complex linetype that is created in the drawing. For this reason, it may be prudent to create unique styles for the text to be used in linetypes. Complex lines will use those style settings until another style is used.

Note: You may need to perform a regen in order to see the changes display. LTSCALE or CELTSCALE commands change the repeating text and the lengths of the repeating patterns to a new size. The LTSCALE variable scales the repeating text and line segments in every line in a drawing. This variable scales all complex linetypes proportionally in the drawing. The CELTSCALE is not a global variable and only scales lines created after it is set. The CELTSCALE variable also scales complex lines proportionally.

Exercise - Centering text in a complex linetype

Create a new text style

  1. Start a new drawing in AutoCAD.
  2. Issue the style command.
  3. Enter TEST for the style name.
  4. Select txt.shx on the select font file dialog box.
  5. Press Enter repeatedly to accept the default settings for the text style. (Make sure the height is set to zero.)

Determine the width of the repeating text

  1. Use the DTEXT command and create the text OO, (capital o) set the height to 0.5.
  2. Use the DIST command to measure the width of the text. It should be around 0.83. This width is used to determine the value needed to center the text in the complex line.

Define the linetype

  1. Open up a text editor like Windows Notepad and enter the following 2 lines :
    *MYLINE,----OO----
    A,1,-2,["OO",TEST,S=0.5,R=0,X= -1.42,Y= -0.25],1
    
  2. Save this file with the arbitrary name of lt-test.lin

Load the linetype in AutoCAD

  1. Issue the linetype command.
  2. Select the load option.
  3. Enter MYLINE font the linetype to load.
  4. Select the lt-test.lin in the Select Linetype File dialog box.

Use the linetype

  1. Bring up the layer control dialog box.
  2. Select layer zero.
  3. Choose Set LTYPE.
  4. Select MYLINE.
  5. Press OK.
  6. Make sure linetype is set to MYLINE and layer zero is current, and press OK.
  7. Draw lines and notice that the text is now centered in the repeating space.

Discussion of the exercise

Open the lt-test.lin in a text editor (such as Notepad). The following 2 lines should be in the file :

*MYLINE,----OO----
A,1,-2,["OO",test1,S=0.5,R=0,X= -1.42,Y= -0.25],1

The X value is used to move the text parallel to the repeating line segments. In this linetype the letters OO need to be centered in a space of 2. The width of the text at height of 0.5 is 0.83. The number 1.42 was derived by the following formula :

2-((2-0.83)/2)=1.42

The number is negative to move the repeating text back towards the start of the line into the blank space.

The Y value is used to move the text perpendicular to the repeating line segments. In this linetype the -0.25 is used to center the letters OO. This number is derived by dividing the S=0.5 value by two. The number is negative to move it down in relationship to the repeating line segments.

Helpful tips

If a text style that will be used in the linetype is not defined, the error "Bad definition of (linetype name) at line (line#) of file filename.lin" will appear when you attempt to load the linetype.

Use a text editor to create the complex linetype. If you try to create a complex linetype from the AutoCAD command line, you will get the error: "INVALID number or bad continuation". The linetype definition will not be saved.

Text objects in complex linetypes are displayed completely and never trimmed.

The Description of the linetype (first line) has a 47 character limit.

There is a 12 Dash - length specifications limit per linetype, and a limit of 80 characters for a line.

The first line segment cannot be negative.

Put half of the repeating segment after the text definition. Adding a line segment after the repeating text will ensure that a line segment will not cross the last text object in the line when it is placed in a drawing. AutoCAD adjusts the line segments to force the line to start and end with a dash.

The scale command adjusts the length of the complex linetype and not the size of the repeating text or repeating line segments.

The complex linetype can only have one color in standard AutoCAD. It can be set to color by layer or to any color using entity creation mode.

The text in a complex line is not a separate entity. The complex line cannot be exploded.

Compiled shape files (.SHX files) can be used in complex linetypes. These .SHX files must be created in AutoCAD. The location of the .SHX file must be set in the support path under Preferences/ File System. Use the instructions in the AutoCAD Customization Guide under Linetype Definition Files. An AutoCAD drawing that contains such a linetype must be accompanied by the compiled shape file or .SHX file where the shape is defined, as well as the .LIN file where the linetype is defined.