The Documents collection and Document object provide access to the AutoCAD. file functions.
To create a new drawing, or open an existing drawing, use the methods on the Documents collection. The Add method creates a new drawing and adds that drawing to the Documents collection. The Open method opens an existing drawing. There is also a Close method on the Documents collection that closes all the drawings open in the AutoCAD session.
Use either the Save or SaveAs method to save a drawing. Occasionally you will want to check if the active drawing has any unsaved changes. It is a good idea to do this before you quit the AutoCAD session or start a new drawing. Use the Saved property to make sure that the current drawing does not contain any unsaved changes.
To import and export drawings, use the Import and Export methods on the Document object.
Dir function is used to check for the existence of the file before trying to open it. You should change the drawing file name or path to specify an existing AutoCAD drawing file on your system.This example uses the Open method to open an existing drawing. The VBA
Dim dwgName As String
dwgName = "c:\campus.dwg"
If Dir(dwgName) <> "" Then
MsgBox "File " & dwgName & " does not exist."
This example uses the Add method to create a new drawing based on the default template.
Dim docObj As AcadDocument
Set docObj = ThisDrawing.Application.Documents.Add
This example saves the active drawing under its current name and again under a new name.
' Save the active drawing under the current name
' Save the active drawing under a new name
This example checks to see if there are unsaved changes and verifies with the user that it is OK to save the drawing (if it is not OK, skip to the end). If OK, use the Save method to save the current drawing, as shown here:
If Not (ThisDrawing.Saved) Then
If MsgBox("Do you wish to save this drawing?", _
vbYesNo) = vbYes Then