AutoCAD VBA Programming: Tools and Techniques

The Documents Collection

The majority of applications deal with the currently active document. For that reason, the shortcut to ThisDrawing is provided in VBA. If an application needs to get to another document that is open in the multiple document mode of AutoCAD 2000, the documents collection is accessed. Drawings in the documents collection are accessed by an index value (zero-based) or the name of the drawing (including the extension. DWG).

Programming for multiple document mode requires that you know which open drawing is of interest. You access open drawings in the documents collection by using an index number or the name of the drawing. The name of the drawing is the same as the one that appears in the Name property of the document object. This property contains the file name without the path name attached.

For example, if a drawing is open and in the drawings collection, the following code would access it and make it the active drawing.

  Dim DWGS As AcadDocuments  Set DWGS = ThisDrawing.Application.Documents  Dim ADWG As AcadDocument  On Error Resume Next  Err.Clear  Set ADWG = DWGS.Item(DrawingName)  If Err.Number <> 0 then     'drawing name not in collection  Else     If ADWG.Active = False Then ADWG.Activate  End If

In the code segment above, the first step is to establish a link to the AutoCAD documents collection. Variable DWGS is defined as an instance of the documents collection and then...

UNLIMITED FREE
ACCESS
TO THE WORLD'S BEST IDEAS

SUBMIT
Already a GlobalSpec user? Log in.

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.

Customize Your GlobalSpec Experience

Category: Computer-Aided Design (CAD) Services
Finish!
Privacy Policy

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.