Hide Table of Contents

Attach Note and Tolerance Annotations to Leaders Example (C#)

This example shows how to attach Note and Tolerance annotations to Leaders.

//-------------------------------------------------------------
// Preconditions:
// 1. Create a C# Windows console project.
// 2. Copy and paste this example into the C# IDE.
// 3. Add a reference to:
//    install_dir\APISDK\tlb\DraftSight.Interop.dsAutomation.dll
// 4. Add a reference to System.Windows.Forms.
// 5. Start DraftSight and open a document.
// 6. Click Start Debugging.
//
// Postconditions: 
// 1. A Leader is constructed with a Note.
// 2. Click within the drawing to specify the point 
//    where to attach a geometric Tolerance annotation
//    to the Leader.
// 3. The geometric Tolerance annotation is attached to
//    the Leader.
// 4. A second leader is constructed with a Note.
// 5. Click within the drawing to specify the
//    point where to attach the New Note annotation to 
//    the Leader.
// 6. The New Note annotation is attached to the Leader.
// 7. The drawing is zoomed to fit.
//------------------------------------------------------------
using System.IO;
using DraftSight.Interop.dsAutomation;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace CreateNoteToleranceLeadersCSharp
{
    static class Module1
    {
        static DraftSight.Interop.dsAutomation.Application dsApp = default(DraftSight.Interop.dsAutomation.Application);

	    public static void Main()
	    {
		    //Connect to DraftSight application
		    dsApp = (DraftSight.Interop.dsAutomation.Application)Marshal.GetActiveObject("DraftSight.Application");

                      // Abort any command currently running in DraftSight to avoid nested commands
		    dsApp.AbortRunningCommand();  

		    //Get active document
		    Document dsDoc = dsApp.GetActiveDocument();
		    if (dsDoc == null) {
			    MessageBox.Show("There are no open documents in DraftSight.");
			    return;
		    }

		    //Get model space
		    Model dsModel = dsDoc.GetModel();

		    //Get the Sketch Manager
		    SketchManager dsSketchMgr = dsModel.GetSketchManager();

		    //Add first Leader
		    double[] leaderCoordinates = new double[] {
			    6.5,
			    7.2,
			    0,
			    7.7,
			    8.6,
			    0
		    };
		    double noteWidth = 1.0;
		    string noteText = "L1 ";
		    Leader dsLeader = dsSketchMgr.InsertLeader(leaderCoordinates, noteWidth, noteText);

		    //Get command message
		    CommandMessage dsCommandMessage = dsApp.GetCommandMessage();
		
                      //Get math utility
		    MathUtility dsMathUtility = dsApp.GetMathUtility();

		    //Prompt to select the point where to insert the 
		    //Tolerance annotation to the Leader
		    double firstX = 0;
		    double firstY = 0;
		    double firstZ = 0;
		    MathPlane dsMathPlane = default(MathPlane);
		    dsMathUtility = dsApp.GetMathUtility();
		    dsMathPlane = dsMathUtility.CreateXYPlane();
		    bool status = false;
                      status = dsCommandMessage.PromptForPoint2("Click within the drawing to insert the geometric Tolerance"true, 0, 0, 0, out firstX, out firstY, out firstZ, dsMathPlane);

		    //Create the first math point
		    MathPoint dsFirstMathPoint = dsMathUtility.CreatePoint(firstX, firstY, firstZ);

                      //Attach the Tolerance annotaion
		    dsLeader.SetToleranceAnnotation("{\\Fgdt;j}%%v{\\Fgdt;n}0.7{\\Fgdt;m}", dsFirstMathPoint);

		    //Add second Leader
		    double[] leaderCoordinates2 = new double[] {
			    18,
			    29,
			    0,
			    30,
			    26,
			    0
		    };
		    double noteWidth2 = 1.0;
		    string noteText2 = "L2 ";
		    Leader dsLeader2 = dsSketchMgr.InsertLeader(leaderCoordinates2, noteWidth2, noteText2);

		    //Prompt to select the point where to insert a  
		    //Note annotation to the Leader
                      double secondX = 0;
		    double secondY = 0;
		    double secondZ = 0;
		    MathPlane dsMathPlane2 = default(MathPlane);
		    MathUtility dsMathUtility2 = dsApp.GetMathUtility();
		    dsMathPlane2 = dsMathUtility2.CreateXYPlane();
                       bool status2 = false;
		    status2 = dsCommandMessage.PromptForPoint2("Click within the drawing to specify where to insert the Note"true, 0, 0, 0, out secondX, out secondY, out secondZ, dsMathPlane2);

		    //Create the second math point
		    MathPoint dsSecondMathPoint = dsMathUtility.CreatePoint(secondX, secondY, secondZ);
                      //Attach the New Note annotation 
		    dsLeader2.SetNoteAnnotation("New Note"dsSecondMathPoint);

		    dsApp.Zoom(dsZoomRange_e.dsZoomRange_Fit, nullnull);

	    }

    }
}


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:   Attach Note and Tolerance Annotations to Leaders 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) 2023 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.