Hide Table of Contents

Set Table Anchors in Sheet Formats Example (C#)

This example shows how to set a hole table anchor in a sheet format of a drawing.

//--------------------------------------------------------------------------
// Preconditions:
// 1. Verify that the specified drawing to open exists.
// 2. Open and Immediate window.
//
// Postconditions:
// 1. Opens the drawing.
// 2. At Stop, examine the position of the hole table in the drawing.
// 3. Press F5.
// 4. Edits the sheet format.
// 5. Creates a point.
// 6. Sets the position of the hole table's anchor at the new point.
// 7. Examine the new position of the hole table
//    and the Immediate window.
//
// NOTE: If prompted, do not save changes when closing the drawing.
//---------------------------------------------------------------------------

using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Diagnostics;

 
namespace SetTableAnchor_CSharp
{
    public partial class SolidWorksMacro
    {
        public void Main()
        {
 
            DrawingDoc swDrw = default(DrawingDoc);
            Sheet swSheet = default(Sheet);
            ModelDoc2 swModel = default(ModelDoc2);
            SketchPoint swSkPoint = default(SketchPoint);
            TableAnchor oldTableAnchor = default(TableAnchor);
            TableAnchor newTableAnchor = default(TableAnchor);
            double[] vPosition = null;
            string filename = null;
            int errors = 0;
            int warnings = 0;
 
            filename = "C:\\Users\\Public\\Documents\\SOLIDWORKS\\SOLIDWORKS 2018\\samples\\tutorial\\api\\SimpleHole.slddrw";
            swDrw = (DrawingDoc)swApp.OpenDoc6(filename, (int)swDocumentTypes_e.swDocDRAWING, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, ""ref errors, ref warnings);
 
            if (swDrw == null)
                return;
 
            System.Diagnostics.Debugger.Break();
 
            swSheet = (Sheet)swDrw.GetCurrentSheet();
            swModel = (ModelDoc2)swDrw;
 
            swModel.Extension.SelectByID2(swSheet.GetName(), "SHEET", 0, 0, 0, false, 0, null, 0);
 
            swDrw.EditTemplate();
            swModel.EditSketch();
 
            swSkPoint = swModel.SketchManager.CreatePoint(0.2, 0.07, 0);
            swSkPoint.Select4(falsenull);
 
            // If an anchor for the hole table already exists, move it to the selected sketch point
            oldTableAnchor = swSheet.get_TableAnchor((int)swTableAnnotationType_e.swTableAnnotation_HoleChart);
            newTableAnchor = (TableAnchor)swSheet.SetAsTableAnchor((int)swTableAnnotationType_e.swTableAnnotation_HoleChart);
 
 
            if ((newTableAnchor != null))
            {
                vPosition = (double[])newTableAnchor.Position;
                Debug.Print("Table Anchor at (" + vPosition[0] + ", " + vPosition[1] + ")");
            }
 
            swDrw.EditSheet();
            swModel.EditSketch();
            swModel.ForceRebuild3(true);
        }
 
        // The SldWorks swApp variable is pre-assigned for you.
        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

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Set Table Anchors in Sheet Formats Example (C#)
*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) 2018 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.