I've created a basic access database to open Solidworks Drawings and save the BOM to a table. It works well except that it takes on average 12 seconds per drawing (.SLDDRW) to run.
I'm using opendoc7 and the following options:
swDocSpecification.DocumentType = swDocDRAWING
swDocSpecification.ReadOnly = True
swDocSpecification.Silent = False
swApp.UserControlBackground = True
swApp.Visible = False
It's worth noting that when I set swApp.UserControlBackground = False my programme takes 4 seconds longer per drawing, so I set it to True.
I have used swDocSpecification.ViewOnly = True which loads the files very quickly, but leaves me unable to traverse the tables. The BOM is always on the first page of our drawings but the title is not always the same so I need to traverse the tables until I find the BOM.
My code is below. I would appreciate any ideas to speed this up.
Option Compare Database Private Sub Command0_Click() ' Code adapted from author below ' Author: Luke Malpass ' Website: http://www.angelsix.com ' Date: 01/04/08 ' ' Prerequisits: Have a drawing open, and for it to export anything, have at least one table created (such as a BOM) ' ' Dim start_time, end_time Dim swApp As SldWorks.SldWorks Dim swDocSpecification As SldWorks.DocumentSpecification Dim swModel As SldWorks.ModelDoc2 Dim swDraw As SldWorks.DrawingDoc Dim swView As SldWorks.View Dim swTable As SldWorks.TableAnnotation Dim swAnn As SldWorks.Annotation Dim sName As String Dim vSheetNames As Variant Dim nNumCol As Long Dim nNumRow As Long Dim sRowStr As String Dim i As Long Dim x As Long Dim j As Long Dim longstatus As Long, longwarnings As Long Dim bRet As Boolean For x = 0 To Me.Lst_Dwg.ListCount - 1 Set swApp = CreateObject("SldWorks.Application") Set swDocSpecification = swApp.GetOpenDocSpec("C:\SWX\" & Lst_Dwg.Column(1, x) & "\" & Lst_Dwg.Column(1, x) & ".slddrw") sName = swDocSpecification.FileName swDocSpecification.DocumentType = swDocDRAWING swDocSpecification.ReadOnly = True swDocSpecification.Silent = False 'swDocSpecification.ViewOnly = True Set swModel = swApp.OpenDoc7(swDocSpecification) longstatus = swDocSpecification.Error longwarnings = swDocSpecification.Warning swApp.UserControlBackground = True swApp.Visible = False Set swModel = swApp.ActiveDoc Set swDraw = swModel vSheetNames = swModel.GetSheetNames swDraw.ActivateSheet (vSheetNames(0)) Set swView = swDraw.GetFirstView Set swTable = swView.GetFirstTableAnnotation Do While Not swTable Is Nothing Set swAnn = swTable.GetAnnotation nNumCol = swTable.ColumnCount nNumRow = swTable.RowCount If swTable.Type = SwConst.swTableAnnotationType_e.swTableAnnotation_BillOfMaterials Then For i = 0 To nNumRow - 1 For j = 0 To nNumCol - 1 Debug.Print swTable.DisplayedText(i, j) Next j Next i End If Set swTable = swTable.GetNext Loop swApp.CloseDoc swApp.ActiveDoc.GetTitle Next x swApp.ExitApp Set swApp = Nothing End Sub