Insert Hole Table Example (VBA)
This example shows how to insert a hole table into a drawing.
'--------------------------------------
'
' Preconditions:
' (1)
Drawing is open.
' (2)
A view in the open drawing is selected.
'
' Postconditions: A hole table is inserted in the drawing
at the point where the
' view
was selected.
'
'--------------------------------------
Option Explicit
Public Enum swBOMConfigurationAnchorType_e
swBOMConfigurationAnchor_TopLeft
= 1
swBOMConfigurationAnchor_TopRight
= 2
swBOMConfigurationAnchor_BottomLeft
= 3
swBOMConfigurationAnchor_BottomRight
= 4
End Enum
Sub main()
Dim
swApp As
SldWorks.SldWorks
Dim
swModel As
SldWorks.ModelDoc2
Dim
swSelMgr As
SldWorks.SelectionMgr
Dim
swView As
SldWorks.View
Dim
swHoleTable As
SldWorks.HoleTableAnnotation
Dim
swTable As
SldWorks.TableAnnotation
Dim
swAnn As
SldWorks.Annotation
Dim
vPickPt As
Variant
Dim
nNumCol As
Long
Dim
nNumRow As
Long
Dim
sRowStr As
String
Dim
i As
Long
Dim
j As
Long
Dim
bRet As
Boolean
Set
swApp = Application.SldWorks
Set
swModel = swApp.ActiveDoc
Set
swSelMgr = swModel.SelectionManager
Set
swView = swSelMgr.GetSelectedObject5(1)
vPickPt
= swSelMgr.GetSelectionPoint(1)
'
View::InsertHoleTable
'
datum
-->
1
'
X
axis -->
4
'
Y
axis -->
8
'
hole
-->
2
Set
swHoleTable = swView.InsertHoleTable(
_
False,
_
vPickPt(0),
vPickPt(1), _
swBOMConfigurationAnchor_TopLeft,
_
""):
Debug.Assert Not swHoleTable Is Nothing
Set
swTable = swHoleTable
Set
swAnn = swTable.GetAnnotation
nNumCol
= swTable.ColumnCount
nNumRow
= swTable.RowCount
'
List table contents
For
i = 0 To nNumRow - 1
sRowStr
= ""
For
j = 0 To nNumCol - 1
sRowStr
= sRowStr & swTable.text(i,
j) & ","
Next
j
Debug.Print
Left(sRowStr, Len(sRowStr) - 1)
Next
i
End Sub
'--------------------------------------