Hide Table of Contents

Get and Set Table Anchor of Hole Table (VBA)

This example shows how to get and set the table anchor of a hole table in a drawing.

' Preconditions: This file exists:
' C:\Program Files\SolidWorks Corp\SolidWorks\samples\tutorial\api\SimpleHole.slddrw
' Postconditions:
' 1. At Stop, examine the position of the hole table
'    in the drawing.
' 2. Click the Continue button in the SolidWorks Microsoft Basic
'    IDE.
' 3. The position of the hole table's anchor is set
'    to the specified location. Examine the hole table
'    in the drawing to verify.
' NOTE: If prompted, do not save any changes when closing the 
' drawing document.
Option Explicit
Sub main()
    Dim swApp As SldWorks.SldWorks
    Set swApp = Application.SldWorks    
    Dim filename As String
    filename = "C:\Program Files\SolidWorks Corp\SolidWorks\samples\tutorial\api\SimpleHole.slddrw"    
    Dim model As ModelDoc2
    Dim errors As Long
    Dim warnings As Long
    Set model = swApp.OpenDoc6(filename, swDocDRAWING, swOpenDocOptions_Silent, "", errors, warnings)    
    If model Is Nothing Then Exit Sub    
    Dim swTable As TableAnnotation
    ' If document is a drawing, then continue
    Select Case model.GetType
    Case swDocDRAWING
        Dim drw As DrawingDoc
        Set drw = model
        ' Get the current sheet
        Dim drwSheet As Sheet
        Set drwSheet = drw.GetCurrentSheet        
        ' Select the Sheet2 feature
        Dim modeldocext As SldWorks.ModelDocExtension
        Dim status As Boolean
        Set modeldocext = model.Extension
        status = modeldocext.SelectByID2("Sheet2", "SHEET", 0, 0, 0, False, 0, Nothing, 0)        
        ' Get the views on Sheet2
        Dim views As Variant
        views = drwSheet.GetViews
        Dim vView As Variant
        For Each vView In views
            Dim drwView As View
            Set drwView = vView                
            Dim viewFeature As Feature
            Set viewFeature = drw.FeatureByName(drwView.Name)            
            ' Traverse the features in the view
            Dim subFeature As Feature
            Set subFeature = viewFeature.GetFirstSubFeature
            ' If the feature is HoleTableFeat, then get the table annotations
            Do Until subFeature Is Nothing
                If subFeature.GetTypeName2 = "HoleTableFeat" Then
                    Dim swHoleTable As HoleTable                    
                    Set swHoleTable = subFeature.GetSpecificFeature2
                    Dim holeTables
                    holeTables = swHoleTable.GetTableAnnotations
                    ' If the annotation is a hole table, then continue
                    If Not IsEmpty(holeTables) Then
                        Dim table As Variant
                        For Each table In holeTables
                            Set swTable = table                            
                            ' If the hole table is anchored, then continue
                            If swTable.Type = swTableAnnotation_HoleChart Then
                                If swTable.Anchored <> False Then
                                    Dim holeTableAnchor As TableAnchor
                                    Set holeTableAnchor = drwView.Sheet.TableAnchor(swTableAnnotation_HoleChart)                                    
                                    ' Get the position of the table anchor
                                    Dim anchorPosition
                                    anchorPosition = holeTableAnchor.Position
                                     ' Determine type of table anchor
                                    Dim newCorner As swBOMConfigurationAnchorType_e
                                    Dim corner As String
                                    Select Case swTable.AnchorType
                                    Case swBOMConfigurationAnchor_BottomLeft
                                        corner = "  Bottom-left "
                                        newCorner = swBOMConfigurationAnchor_TopRight
                                    Case swBOMConfigurationAnchor_BottomRight
                                        corner = "  Bottom-right "
                                        newCorner = swBOMConfigurationAnchor_TopLeft
                                    Case swBOMConfigurationAnchor_TopLeft
                                        corner = "  Top-left "
                                        newCorner = swBOMConfigurationAnchor_BottomRight
                                    Case swBOMConfigurationAnchor_TopRight
                                        corner = "  Top-right "
                                        newCorner = swBOMConfigurationAnchor_BottomLeft
                                    End Select                                    
                                    swTable.AnchorType = newCorner                                    
                                    ' Set the new position of the table anchor
                                    Dim dNewPosition(0 To 1) As Double
                                    dNewPosition(0) = 0#
                                    dNewPosition(1) = 0#                                    
                                    holeTableAnchor.Position = dNewPosition
                                End If
                            End If
                    End If
                End If                
                Set subFeature = subFeature.GetNextSubFeature
    Case swDocASSEMBLY, swDocPART
    End Select    
End Sub


Provide feedback on this topic

SOLIDWORKS welcomes your feedback concerning the presentation, accuracy, and thoroughness of the documentation. Use the form below to send your comments and suggestions about this topic directly to our documentation team. The documentation team cannot answer technical support questions. Click here for information about technical support.

* Required

Subject:   Feedback on Help Topics
Page:   Get and Set Table Anchor of Hole Table (VBA)
*   I acknowledge I have read and I hereby accept the privacy policy under which my Personal Data will be used by Dassault Systèmes

Print Topic

Select the scope of content to print:


We have detected you are using a browser version older than Internet Explorer 7. For optimized display, we suggest upgrading your browser to Internet Explorer 7 or newer.

 Never show this message again

Web Help Content Version: API Help (English only) 2012 SP05

To disable Web help from within SOLIDWORKS and use local help instead, click Help > Use SOLIDWORKS Web Help.

To report problems encountered with the Web help interface and search, contact your local support representative. To provide feedback on individual help topics, use the “Feedback on this topic” link on the individual topic page.