Hide Table of Contents

Insert SimpleNote Example (C#)

This example shows how to insert and change a SimpleNote in a drawing document.

// 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 references to System, System.Runtime.InteropServices,
//    and System.Windows.Forms.
// 5. Start DraftSight and open a document.
// 6. Start debugging the project.
// Postconditions: 
// 1. A message box pops up when a SimpleNote is
//    inserted in the drawing.
// 2. The selection filter is set to select SimpleNotes only and
//    is activated.
// 3. The SimpleNote is selected and its text changed. Examine 
//    the drawing to verify.
using DraftSight.Interop.dsAutomation;
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
static class Module1
    public static void Main()
	DraftSight.Interop.dsAutomation.Application dsApp;
	Document dsDoc = default(Document);
	Model dsModel = default(Model);
	SketchManager dsSketchManager = default(SketchManager);
	SimpleNote dsSimpleNote = default(SimpleNote);
	double startX = 0;
	double startY = 0;
	double startZ = 0;
        string noteValue;
        double angle = 0;
        double height;
	//Connect to DraftSight
        dsApp = (DraftSight.Interop.dsAutomation.Application)Marshal.GetActiveObject("DraftSight.Application");
	dsApp.AbortRunningCommand(); // abort any command currently running in DraftSight to avoid nested commands

	//Get active document
	dsDoc = dsApp.GetActiveDocument();
	if ((dsDoc != null)) {
		//Get model space
		dsModel = dsDoc.GetModel();
		//Get Sketch Manager
		dsSketchManager = dsModel.GetSketchManager();
        	//SimpleNote parameters (angle value should be passed in radians)
        	startX = 0.0;
        	startY = 0.0;
        	startZ = 0.0;
        	noteValue = "Sample text";
        	height = 1.0;
        	angle = Math.PI / 4; //45 degrees in radians
        	//Add a SimpleNote
        	dsSimpleNote = dsSketchManager.InsertSimpleNote(startX, startY, startZ, height, angle, noteValue);
		if ((dsSimpleNote != null)) {
			MessageBox.Show("A SimpleNote was inserted in the drawing.");
			} else {
				MessageBox.Show("There are no open documents in DraftSight.");
        	//Change SimpleNote text
       	 	ChangeSimpleNotesText(dsDoc, dsSketchManager);
    private static void ChangeSimpleNotesText(Document dsDoc, SketchManager dsSketchManager)
            //Get Selection Manager
            SelectionManager dsSelectionMgr = dsDoc.GetSelectionManager();
            //Get selection filter
            SelectionFilter dsSelectioFilter = dsSelectionMgr.GetSelectionFilter();
            //Clear selection filter
            //Add filter to get only SimpleNotes
            //Activate selection filter
            dsSelectioFilter.Active = true;
            //Get all Layers in drawing
            string[] layerNames = GetLayerNames(dsDoc);
            //Get SimpleNote entities
            object entityObjects;
            object entityTypes;
            dsSketchManager.GetEntities(dsSelectioFilter, layerNames, out entityTypes, out entityObjects);
            if (null != entityObjects && null != entityTypes)
                object[] dsEntityArray = (object[])entityObjects;
                const string newNoteValue = "New sample text";
                //Iterate through all SimpleNote entities
                for (int index = 0; index < dsEntityArray.Length; ++index)
                    //Cast the selected object to SimpleNote
                    SimpleNote dsSimpleNote = dsEntityArray[index] as SimpleNote;
                    //Get SimpleNote text
                    string noteValue = dsSimpleNote.Contents;
                    //Set new text for SimpleNote
                    dsSimpleNote.Contents = newNoteValue;
    private static string[] GetLayerNames(Document dsDoc)
            string[] layerNames = null;
            LayerManager dsLayerManager = dsDoc.GetLayerManager();
            object[] dsLayers = (object[])dsLayerManager.GetLayers();
            if (null != dsLayers)
                layerNames = new string[dsLayers.Length];
                for (int index = 0; index < dsLayers.Length; ++index)
                    Layer dsLayer = dsLayers[index] as Layer;
                    layerNames[index] = dsLayer.Name;
            return layerNames;


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 SimpleNote 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) 2024 SP02

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.