Hide Table of Contents

Get Labels of Datum Origin Example (C#)

This example shows how to get the labels of a datum origin.

//--------------------------------------------------------------
// Preconditions:
// 1. Verify that the specified files exist:
//    * part document
//    * drawing document template
//    * hole table template
// 2. Open the Immediate window.
//
// Postconditions:
// 1. Opens the specified part document.
// 2. Creates a drawing of the part document.
// 3. Inserts a hole table annotation at the specified vertex.
// 4. Gets the hole table and its datum origin.
// 5. Prints the datum origin's x and y labels to the Immediate
//    window.
// 6. Examine the Immediate window and drawing.
//---------------------------------------------------------------
 
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
using System;
using System.Diagnostics;
 
namespace DatumOriginCSharp.csproj
{
    public partial class SolidWorksMacro
    {
 
 
        public void Main()
        {
 
            ModelDoc2 swModel;
            DrawingDoc swDrawingDoc;
            View swView;
            ModelView swModelView;
            ModelDocExtension swModelDocExt;
            SelectionMgr swSelectionMgr;
            HoleTableAnnotation swHoleTableAnnotation;
            HoleTable swHoleTable;
            DatumOrigin swDatumOrigin;
            string fileName;
            string drawingDocTemplate;
            string holeTableTemplate;
            bool status;
            int errors = 0;
            int warnings = 0;
 
            //Open part document and create drawing document
            fileName = "C:\\Program Files\\SolidWorks Corp\\SolidWorks\\samples\\tutorial\\tolanalyst\\minimum_clearance\\top_plate.sldprt";
            swModel = (ModelDoc2)swApp.OpenDoc6(fileName, (int)swDocumentTypes_e.swDocPART, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, ""ref errors, ref warnings);
            drawingDocTemplate = "C:\\ProgramData\\SolidWorks\\SolidWorks 2015\\templates\\Drawing.drwdot";
            swDrawingDoc = (DrawingDoc)swApp.NewDocument(drawingDocTemplate, (int)swDwgPaperSizes_e.swDwgPaperBsize, 0.2794, 0.4318);
            swView = (View)swDrawingDoc.CreateDrawViewFromModelView3(fileName, "*Front", 0.193046827497194, 0.155595183164983, 0);
 
            //Insert hole table annotation
            swModel = (ModelDoc2)swApp.ActiveDoc;
            swDrawingDoc = (DrawingDoc)swModel;
            swModelView = (ModelView)swModel.ActiveView;
            swModelDocExt = (ModelDocExtension)swModel.Extension;
            status = swDrawingDoc.ActivateView("Drawing View1");
            status = swModelDocExt.SelectByID2("""VERTEX", 0.216278249046016, 0.198389907070707, 0.0080000000000382, false, 0, null, 0);
            status = swModelDocExt.SelectByID2("""FACE", 0.228097744219978, 0.151927063973064, 0.0040000000000191, false, 0, null, 0);
            swModel.ClearSelection2(true);
            status = swModelDocExt.SelectByID2("""VERTEX", 0.216278249046016, 0.198389907070707, 0.0080000000000382, true, 1, null, 0);
            status = swModelDocExt.SelectByID2("""FACE", 0.228097744219978, 0.151927063973064, 0.0040000000000191, true, 2, null, 0);
            swSelectionMgr = (SelectionMgr)swModel.SelectionManager;
            swView = (View)swSelectionMgr.GetSelectedObjectsDrawingView2(1, -1);
            holeTableTemplate = "C:\\Program Files\\SolidWorks Corp\\SolidWorks\\lang\\english\\standard hole table--letters.sldholtbt";
            swHoleTableAnnotation = (HoleTableAnnotation)swView.InsertHoleTable2(false, 0.0540658670033671, 0.253819263748597, 1, "A", holeTableTemplate);
            swModel.ClearSelection2(true);
 
            //Get hole table and its datum origin
            swHoleTable = (HoleTable)swHoleTableAnnotation.HoleTable;
            swDatumOrigin = (DatumOrigin)swHoleTable.DatumOrigin;
 
            //Get datum origin's x and y labels
            Debug.Print("Datum origin:");
            Debug.Print("  X label: " + swDatumOrigin.XLabel);
            Debug.Print("  Y label: " + swDatumOrigin.YLabel);
 
        }
 
        /// <summary>
        ///  The SldWorks swApp variable is pre-assigned for you.
        /// </summary>
        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:   Get Labels of Datum Origin 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) 2015 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.