Hide Table of Contents

Get Title Block Tables Example (VBA)

This example shows how to get title block tables.

'-------------------------------------------------
' Preconditions:
' 1. Open a part that does not contain any annotations.
' 2. Verify that the specified table template exists.
' 3. Open the Immediate window.
'
' Postconditions:
' 1. Inspect the output in the Immediate window.
' 2. Observe the new title block table feature under Tables
'    in the FeatureManager design tree (if necessary, right-click the
'    part in the FeatureManager design tree, click Hidden Tree
'    Items > Hide/Show Tree Items > Show in the Tables drop-down list).
' 3. Observe the corresponding title block table annotation
'    in the graphics area.
'--------------------------------------------------
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim Part As SldWorks.ModelDoc2
Dim tbtAnno As SldWorks.TitleBlockTableAnnotation
Dim anno As SldWorks.TitleBlockTableAnnotation
Dim tabannoObject As SldWorks.TitleBlockTableAnnotation
Dim feat As SldWorks.TitleBlockTableFeature
Dim tabfeatObject As SldWorks.TitleBlockTableFeature
Dim annos As Variant
Dim I As Long
Dim selMgr As SldWorks.SelectionMgr
Dim boolstatus As Boolean

Sub main()
    Set swApp = Application.SldWorks
    Set Part = swApp.ActiveDoc
    Debug.Print "Inserting a title block table into the model using a general table template (*.sldtbt)"
    Debug.Print ""    
    Set tbtAnno = Part.Extension.InsertTitleBlockTable("C:\Program Files\SOLIDWORKS Corp\SOLIDWORKS\lang\english\connector-table.sldtbt", 500, 500)
    Set feat = tbtAnno.TitleBlockTableFeature
    Debug.Print "Title block table feature: " + feat.GetFeature.Name
    Dim count As String
    count = feat.GetTableAnnotationCount
    Debug.Print "Title block table annotation count: " + count
    Debug.Print "Title block table annotations"
    annos = feat.GetTableAnnotations
    For I = 0 To UBound(annos)
        Set anno = annos(I)
        Debug.Print "   Title block table feature: " + anno.TitleBlockTableFeature.GetFeature.Name
    Next
    Debug.Print ""    
    Debug.Print "Selecting title block table feature through IModelDocExtension::SelectByID2 type, TITLEBLOCKTABLEFEAT"
    boolstatus = Part.Extension.SelectByID2(feat.GetFeature.Name, "TITLEBLOCKTABLEFEAT", 0, 0, 0, False, 0, Nothing, 0)
    Debug.Print "  Casting selected object to ITitleBlockTableFeature"
    Set selMgr = Part.SelectionManager
    Set tabfeatObject = selMgr.GetSelectedObject6(1, -1)
    Debug.Print "     Title block table feature: " + tabfeatObject.GetFeature.Name
    Debug.Print ""    
    Debug.Print "Selecting title block table annotation through IModelDocExtension::SelectByID2 type, ANNOTATIONTABLES"
    boolstatus = Part.Extension.SelectByID2("DetailItem1@Annotations", "ANNOTATIONTABLES", -0.1205280774849, -0.01199819470702, 0.04087038255709, False, 0, Nothing, 0)
    Debug.Print "  Casting selected object to ITitleBlockTableAnnotation type"
    Set tabannoObject = selMgr.GetSelectedObject6(1, -1)
    Debug.Print "    Getting title block table feature from the title block table annotation"
    Debug.Print "      Title block table feature: " + tabannoObject.TitleBlockTableFeature.GetFeature.Name
    Debug.Print ""    
    Debug.Print "  Casting selected object to ITableAnnotation type"
    Dim annoObject As ITableAnnotation
    Set annoObject = selMgr.GetSelectedObject6(1, -1)
    Dim annoType As String
    annoType = annoObject.Type
    If annoType = swTableAnnotationType_e.swTableAnnotation_TitleBlock Then
        Debug.Print "     The selected table annotation is defined in swTableAnnotationType_e as TitleBlock"
    Else
        Debug.Print "     The selected table annotation is defined in swTableAnnotationType_e with value:   " + annoType
    End If
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

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Get Title Block Tables Example (VBA)
*Comment:  
*   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:

x

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
x

Web Help Content Version: API Help (English only) 2016 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.