Hello,everyone.
I want use SW API to get table information.
The code I fined was:
But ,how do i use it.? Because I need get General table and hole table information.
SolidworksApi/macros
Hello,everyone.
I want use SW API to get table information.
The code I fined was:
But ,how do i use it.? Because I need get General table and hole table information.
SolidworksApi/macros
Try this example: Read Table Content Into Array
Thank you !!
Thank you !!
Thank you !!
Dim swRevTable As SldWorks.RevisionTableAnnotation
Dim swTable As SldWorks.TableAnnotation
Dim currentsheet As SldWorks.Sheet
Dim sCount As Integer
Dim tableData() As String
Dim sName As String
Dim Part As Object
Dim boolstatus As Boolean
Dim i As Long
Dim j As Long
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swDraw = swModel
Set swSheet = swDraw.GetCurrentSheet
Set swRevTable = swSheet.RevisionTable
Set swTable = swRevTable
' Count rows in current revision table
sCount = swTable.RowCount
'This will collect table data into an array
ReDim tableData(swTable.RowCount, swTable.ColumnCount)
' collects text from table
For i = 0 To sCount - 2
For j = 0 To swTable.ColumnCount - 1
tableData(i, j) = swTable.Text(i, j)
Next j
Next i
'Captures the item name of the table
sName = swTable.GetAnnotation.GetName & "@Sheet1"
'Deletes the table
Set Part = swApp.ActiveDoc
boolstatus = Part.Extension.SelectByID2(sName, "REVISIONTABLE", 0, 0, 0, False, 0, Nothing, 0)
Part.EditDelete
'Inserts new table
Dim revTableAnno As SldWorks.RevisionTableAnnotation
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swDraw = swModel
Set currentsheet = swDraw.GetCurrentSheet
swDraw.ActivateSheet (currentsheet.GetName)
' Insert a revision table and add a revision row
Set revTableAnno = currentsheet.InsertRevisionTable2(True, 0#, 0#, swBOMConfigurationAnchor_BottomLeft, "C:\abc_Prod\abc Templates\SW_Properties_Tables\REVISION.sldrevtbt", swRevisionTable_CircleSymbol, True)
Dim swRevTable2 As SldWorks.RevisionTableAnnotation
Dim swTable2 As SldWorks.TableAnnotation
Set swRevTable2 = swSheet.RevisionTable
Set swTable2 = swRevTable2
revTableAnno.AddRevision ("")
' this adds the array data into new table
For i = 0 To sCount - 2
For j = 0 To swTable2.ColumnCount
revTableAnno.Text(i, j) = tableData(i, j)
Next j
Next i
See example below on how to get any table information from Drawing using IView::GetTableAnnotations Method
Option Explicit
'Preconditions
'1. Open Drawing Model
'2. Results will be printed in Immediate Window
Sub Main()
Dim SwApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swDrawDoc As SldWorks.DrawingDoc
Dim swAnnot As SldWorks.Annotation
Dim SwView As SldWorks.View
Dim vViews As Variant
Dim vTableAnnots As Variant
Dim swTableAnnot As SldWorks.TableAnnotation
Dim intTableAnnotCount As Integer
Dim i As Integer
Dim intCol As Integer
Dim intRow As Integer
Set SwApp = Application.SldWorks
Set swModel = SwApp.ActiveDoc
If swModel.GetType = swDocumentTypes_e.swDocASSEMBLY Or swModel.GetType = swDocumentTypes_e.swDocPART Then
MsgBox "Please open drawing and try again."
Exit Sub
End If
Set swDrawDoc = swModel
Set SwView = swDrawDoc.GetFirstView
vTableAnnots = SwView.GetTableAnnotations
intTableAnnotCount = SwView.GetTableAnnotationCount
If intTableAnnotCount > 0 Then
For i = 0 To UBound(vTableAnnots)
Set swTableAnnot = vTableAnnots(i)
'Use table types below depending on what table you want to get information from:
'swTableAnnotation_HoleChart swTableAnnotation_BillOfMaterials etc...
If swTableAnnot.Type = swTableAnnotationType_e.swTableAnnotation_General Then
For intCol = 0 To swTableAnnot.ColumnCount - 1
For intRow = 0 To swTableAnnot.RowCount
Debug.Print swTableAnnot.Text(intRow, intCol)
Next intRow
Next intCol
End If
Next i
End If
End Sub