Hide Table of Contents

Attach Block Definition Annotation to Leader Example (C#)

This example shows how to attach a Block definition annotation to a Leader.

//--------------------------------------------------------------
// 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 message box pops up when the Block definition,
//    named MyBlockAnnotation, is created.
// 2. Click OK to close the message box.
// 3. A Leader is created and MyBlockAnnotation is
//    is attached to the Leader.
// 4. The drawing zooms to fit.
// 5. Examine the drawing.
//----------------------------------------------------------------
using DraftSight.Interop.dsAutomation;
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
 
static class Module1
{
    static void Main(string[] args)
        {
            DraftSight.Interop.dsAutomation.Application dsApp;
            Document dsDoc = default(Document);
            Model dsModel = default(Model);
            SketchManager dsSketchManager = default(SketchManager);
 
            //Connect to DraftSight
            dsApp = (DraftSight.Interop.dsAutomation.Application)Marshal.GetActiveObject("DraftSight.Application");
            //Get active document
            dsDoc = dsApp.GetActiveDocument();
            if ((dsDoc != null))
            {
                //Get model space
                dsModel = dsDoc.GetModel();
 
                //Get Sketch Manager
                dsSketchManager = dsModel.GetSketchManager();
 
                //First Line's parameters        
                double startX = 1.0;
                double startY = 1.0;
                double startZ = 0.0;
                double endX = 6.0;
                double endY = 1.0;
                double endZ = 0.0;

                //Construct a Line
                Line dsLine = (dsSketchManager.InsertLine(startX, startY, startZ, endX, endY, endZ));
 
                //Second Line's parameters
                double start2X = 2.0;
                double start2Y = 2.0;
                double start2Z = 0.0;
                double end2X = 2.0;
                double end2Y = 20.0;
                double end2Z = 0.0;

                //Construct another Line
                Line dsLine2 = (dsSketchManager.InsertLine(start2X, start2Y, start2Z, end2X, end2Y, end2Z));
 
                int[] typesArray = new int[] {21, 21};
                Line[] linesArray = new Line[] {dsLine, dsLine2};            
 
                BlockDefinition dsBlockDef = dsDoc.CreateBlockDefinition ("MyBlockAnnotation""Block annotation to attach to Leader", 0, 0, 0, typesArray, linesArray, dsBlockDefinitionEntities_e.dsBlockDefinitionEntities_ConvertToBlock);
                MessageBox.Show("Name of Block definition: " + dsBlockDef.GetName());
 
                //Add Leader
                double[] leaderCoordinates = new double[] { 6.5, 7.2, 0, 7.7, 8.6, 0 };
                double noteWidth = 1.0;
                string noteText = "L1 ";
                Leader dsLeader = dsSketchManager.InsertLeader(leaderCoordinates, noteWidth, noteText);
 
                //Attach Block definition to Leader,
                //which creates a Block instance
                MathUtility dsMathUtility = dsApp.GetMathUtility();
                MathPoint dsMathPoint = dsMathUtility.CreatePoint(20,20,25);
                dsLeader.SetBlockAnnotation("MyBlockAnnotation", dsMathPoint);
 
                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 Block Definition Annotation to Leader 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) 2019 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.