Quit the Other Application
From AutoCAD ActiveX
When you start an application programmatically it takes up memory in the computer. You should quit the application when you have finished using it so system resources can be freed up.
Although each Object Model is different, most have a Quit method from the Application object that can be used to close the application cleanly. For example, using the variable declarations from the previous section, the following line of code will quit Excel:
ExcelAppObj.Application.Quit
NoteDestroying
or going beyond the scope of the object variable does not necessarily
cause the application to terminate. You should always quit the application
using the appropriate method to assure proper memory cleanup.
List AutoCAD attributes on an Excel spreadsheet
This subroutine finds all the block references in the current drawing. It then finds the attributes attached to those block references and lists them in an Excel spreadsheet. To run this example, do the following:
- Open a drawing containing block references with attributes. (The sample drawing sample/activeX/attrib.dwg contains such block references.)
- Open the VBA IDE using the AutoCAD VBAIDE command.
- Using the Tools
References
menu option in the VBA IDE, select Microsoft Excel 8.0 Object Model. - Copy this subroutine into a VBA Code window and run it.
Sub Ch12_Extract()
Dim Excel As Excel.Application
Dim ExcelSheet As Object
Dim ExcelWorkbook As Object
Dim RowNum As IntegerDim Header As BooleanDim elem As AcadEntityDim Array1 As VariantDim Count As Integer' Launch Excel.Set Excel = New Excel.Application' Create a new workbook and find the active sheet.Set ExcelWorkbook = Excel.Workbooks.AddSet ExcelSheet = Excel.ActiveSheetExcelWorkbook.SaveAs "Attribute.xls"RowNum = 1Header = False' Iterate through model space finding' all block references.For Each elem In ThisDrawing.ModelSpaceWith elem' When a block reference has been found,' check it for attributesIf StrComp(.EntityName, "AcDbBlockReference", 1) _= 0 ThenIf .HasAttributes Then' Get the attributesArray1 = .GetAttributes' Copy the Tagstrings for the' Attributes into ExcelFor Count = LBound(Array1) To UBound(Array1)If Header = False ThenIf StrComp(Array1(Count).EntityName, _"AcDbAttribute", 1) = 0 ThenExcelSheet.Cells(RowNum, _Count + 1).value = _Array1(Count).TagStringEnd IfEnd IfNext CountRowNum = RowNum + 1For Count = LBound(Array1) To UBound(Array1)ExcelSheet.Cells(RowNum, Count + 1).value _= Array1(Count).textStringNext CountHeader = TrueEnd IfEnd IfEnd WithNext elemExcel.Application.QuitEnd Sub