Hide Table of Contents

Insert Punch Table Example (C#)

This example shows how to insert a punch table in the flat pattern view of a sheet metal part that contains one or more forming tool features.

// Preconditions:
// 1. Open a drawing that contains a flat pattern view of a sheet metal part with
//    one or more forming tool features.
// 2. Modify the x- and y-coordinates in the IModelDocExtension::SelectByID2 methods for the
//    specified VERTEX and FACE.
// 3. Replace install_dir with your SolidWorks installation path.
// Postconditions:
// 1. A punch table is inserted in the drawing.
// 2. Inspect the Immediate window for punch table feature details.
// ---------------------------------------------------------------------------
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
namespace InsertPunchTable_CSharp.csproj
partial class SolidWorksMacro

ModelDoc2 Part;
DrawingDoc Draw;
bool boolstatus;
View myView;
PunchTableAnnotation myTableAnn;
PunchTable MyTable;
Feature featRet;

object rVar;

public void Main()
            Part = (
            Draw = (
            boolstatus = Draw.ActivateView(
"Drawing View1");
            boolstatus = Part.Extension.SelectByID2(
"Drawing View1", "DRAWINGVIEW", 0, 0, 0, false, 0, null, 0);

//Select a vertex in the drawing view to be the origin of all datums in the table
            //All X LOCATION and Y LOCATION table column values will be relative to this datum origin
            boolstatus = Part.Extension.SelectByID2("", "VERTEX", 0.1344949308616, 0.0948467785893, 0, false, 1, null, 0);

//Select a face that contains the punches that will be annotated in the table
            boolstatus = Part.Extension.SelectByID2("", "FACE", 0.1562337360869, 0.1059474450873, 0, true, 2, null, 0);

            myView = ((

            myTableAnn = myView.InsertPunchTable(
false, 0.2178779310824, 0.2022819591903, 1, "A", "install_dir\\lang\\english\\punchtable-standard.sldpuntbt");

            MyTable = myTableAnn.PunchTable;
Debug.Print("Default punch table properties:");
Debug.Print("Tag style (swPunchTableTagStyle_e): " + MyTable.TagStyle);
Debug.Print("Starting tag: " + MyTable.StartingValue);
Debug.Print("Merge cells with the punch ID for a given tag? " + MyTable.CombineSameSize);
Debug.Print("Combine rows with the same punch ID? " + MyTable.CombineTags);
Debug.Print("Display dual dimensions? " + MyTable.DualDimensions);
Debug.Print("Display units for dual dimensions? " + MyTable.ShowUnits);
Debug.Print("Punch table annotation count: " + MyTable.GetTableAnnotationCount());

            rVar = MyTable.GetTableAnnotations();

            featRet = (
Debug.Print("Feature name: " + featRet.Name);

            boolstatus = Draw.ActivateSheet(

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:   Insert Punch Table 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) 2014 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.