Loading a Linetype

Linetype definitions are stored in linetype library files, which are external to drawing files and have the extension .lin. Linetypes are loaded by name from library files into similarly named Linetype objects in the drawing. Once loaded into a drawing, a Linetype object has no more connection to the library file. I don't cover the creation and definition of linetypes here, because no methods exist for customizing linetypes programmatically, but you can take a look at the AutoCAD Customization Guide in the online help files for details on creating custom linetypes. It's interesting to note that you can create custom linetypes by writing a linetype definition file programmatically and then loading it.

You can load a Linetype object into your drawing using the Load method shown in the following code and detailed in Table 6-3.

Set LinetypeObject = LinetypesCollection.Load(LinetypeName, _ LinetypeFilename)

Table 6-3. Linetype Load Parameter Specifications

Name_Data Type_Description_

LineTypeName String The name of the linetype

LinetypeFilename String The path and file name of the linetype library file

The AutoCAD default Linetype object definition file for standard linetypes is acad.lin. You can view the contents of this via the Linetype dialog box (click Format > Linetype to bring it up) by clicking Load and browsing to the file (see Figure 6-3). You can also open a linetype definition file in any ASCII text editor such as Windows Notepad.

Hfr Load or Reload Linetypes

Available Linetypes

Available Linetypes

Linetype

| Description

-

ACAD

IS002W100

ISO dash

ACAD

IS003W100

ISO dash space

ACAD

IS004W100

ISO lona-dash dot

ACAD

IS005W100

ISO lonq-dash double-dot

ACAD.

JS006W100

ISO long-dash triple-dot_..._..._

ACAD

IS007W100

ISO dot

ACAD

IS008W100

ISO lona-dash short-dash

ACAD

IS009W100

ISO lonq-dash double-short-dash

ACAD

IS010W100

ISO dash dot

ACAD

IS011W100

ISO double-dash dot

z\

ACAD.

JS012W100

ISO dash double-dot_.._.._.._..

Cancel

Help

Cancel

Help

Figure 6-3. The Linetype dialog box

Once you determine the linetype library and the name of a specific linetype you'd like to load, you can use the following code to load it:

Public Sub LoadLinetype()

Dim strLinetypeName As String Dim objLinetype As AcadLineType strLinetypeName = InputBox("Enter a Linetype name" & _

" to load from ACAD.LIN: ") If "" = strLinetypeName Then Exit Sub ' exit if no name entered

On Error Resume Next ' handle exceptions inline

ThisDrawing.Linetypes.Load strLinetypeName, "acad.lin"

If Err Then ' check if err was thrown

MsgBox "Error loading '" & strLinetypeName & "'" & vbCr & _ Err.Description

Else

MsgBox "Loaded Linetype '" & strLinetypeName & "'" End If End Sub

■ Note Depending on the setting of the drawing's MEASUREMENT system variable, the linetype library could be acadiso.lin.

+1 0

Post a comment