Hide Table of Contents

Get Title Block Tables Example (C#)

This example shows how to get title block tables.


// Preconditions:

// 1. Open a part.

// 2. Ensure that the following file exists on your system and, if necessary,

//     modify the path to it in the code below:

//     <SolidWorks_install_dir>\lang\english\connector-table.sldtbt.

// 3. Open an Immediate window in the IDE.


// Postconditions:

// 1. Inspect the output in the Immediate Window.

// 2. Observe the new title block table feature under Tables in the

//    FeatureManager design tree.

// 3. Observe the corresponding title block table annotation

//    in the model document.

// 4. Delete all title block table features and annotations before

//    re-running this macro on the same part.


using SolidWorks.Interop.sldworks;

using SolidWorks.Interop.swconst;

using System;

using System.Diagnostics;

namespace TitleBlockTables_C_.csproj


    partial class SolidWorksMacro



        IModelDoc2 Part;

        ITitleBlockTableAnnotation tbtAnno;

        ITitleBlockTableAnnotation anno;

        ITitleBlockTableAnnotation tabannoObject;

        ITitleBlockTableFeature feat;

        ITitleBlockTableFeature tabfeatObject;

        object[] annos;

        long I;

        ISelectionMgr selMgr;

        bool boolstatus;

        public void Main()


            Part = (IModelDoc2)swApp.ActiveDoc;

            Debug.Print("Inserting a title block table into the model using a general table template (*.sldtbt)...");


            tbtAnno = Part.Extension.InsertTitleBlockTable("C:\\Program Files\\SolidWorks Corp\\SolidWorks\\lang\\english\\connector-table.sldtbt", 500, 500);

            feat = tbtAnno.TitleBlockTableFeature;

            Debug.Print("Title block table feature: " + feat.GetFeature().Name);

            string count = null;

            count = feat.GetTableAnnotationCount().ToString();

            Debug.Print("Title block table annotation count: " + count);

            Debug.Print("Title block table annotations...");

            annos = (Object[])feat.GetTableAnnotations();

            for (I = 0; I <= annos.GetUpperBound(0); I++)


                anno = (ITitleBlockTableAnnotation)annos[I];

                Debug.Print(" Title block table feature: " + anno.TitleBlockTableFeature.GetFeature().Name);



            //See documentation for swSelectType_e.swSelTITLEBLOCKTABLEFEAT

            Debug.Print("Selecting title block table feature through SelectByID2 type, TITLEBLOCKTABLEFEAT...");

            boolstatus = Part.Extension.SelectByID2(feat.GetFeature().Name, "TITLEBLOCKTABLEFEAT", 0, 0, 0, false, 0, null, 0);


            Debug.Print("Casting selected object to ITitleBlockTableFeature...");

            selMgr = Part.ISelectionManager;

            tabfeatObject = (ITitleBlockTableFeature)selMgr.GetSelectedObject6(1, -1);

            Debug.Print(" Title block table feature: " + tabfeatObject.GetFeature().Name);


            //See documentation for swSelectType_e.swSelANNOTATIONTABLES

            Debug.Print("Selecting title block table annotation through SelectByID2 type, ANNOTATIONTABLES...");

            boolstatus = Part.Extension.SelectByID2("", "ANNOTATIONTABLES", -0.1205280774849, -0.01199819470702, 0.04087038255709, false, 0, null, 0);


            Debug.Print("Casting selected object to ITitleBlockTableAnnotation type...");

            tabannoObject = (ITitleBlockTableAnnotation)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);


            //See documentation for swTableAnnotationType_e_TitleBlock

            Debug.Print("Casting selected object to ITableAnnotation type...");

            ITableAnnotation annoObject = default(ITableAnnotation);

            annoObject = (ITableAnnotation)selMgr.GetSelectedObject6(1, -1);

            swTableAnnotationType_e annoType;

            annoType = (swTableAnnotationType_e)annoObject.Type;

            if (annoType == swTableAnnotationType_e.swTableAnnotation_TitleBlock)


                Debug.Print(" The selected table annotation is defined in swTableAnnotationType_e as TitleBlock");




                Debug.Print(" The selected table annotation is defined in swTableAnnotationType_e with value: " + annoType);




        public SldWorks swApp;



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 Title Block Tables Example (C#)
*   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) 2013 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.