Hide Table of Contents

Change DimensionStyle Options of Leader Example (C#)

This example shows how to change the DimensionStyle arrow and text options of a specific Leader. The DimensionStyle arrow and text options of all other existing and new Leaders use the DimensionStyle options of the drawing. 

//--------------------------------------------------------------
// 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 and System.Windows.Forms.
// 5. Start DraftSight and open a document.
// 6. Start debugging the project.
//
// Postconditions: 
// 1.  Draws two Leaders, DSUserData and DS.
// 2.  Gets DimensionStyleUserData for DSUserData Leader.
// 3.  Gets arrow options for DSUserData Leader.
// 4.  Modifies DSUserData Leader's arrow options only.
// 5.  Zooms to fit the drawing and execution stops.
// 6.  Examine the drawing to verify that only DSUserData Leader's
//     arrow changed.
// 7.  Press F10 to step through the rest of the project
//     and examine the drawing after each call.
// 8.  Gets text options for DSUserData Leader.
// 9.  Modifies DSUserData Leader's text options only.
// 10. Inserts third Leader, DS2.
// 11. Examine the drawing to verify that DS and DS2 Leaders
//     have the same arrow and text options.
//----------------------------------------------------------------
 
using System;
using DraftSight.Interop.dsAutomation;
using System.Runtime.InteropServices;
using System.Windows.Forms;
 
 
namespace DimensionStyleUserDataTest
{
    class Program
    {
 
        static void Main()
        {
            DraftSight.Interop.dsAutomation.Application dsApp;
 
            //Connect to DraftSight application
            dsApp = (DraftSight.Interop.dsAutomation.Application)Marshal.GetActiveObject("DraftSight.Application");
 
            if (null == dsApp)
            {
                return;
            }
 
            //Get active document
            Document dsDoc = dsApp.GetActiveDocument();
            if (null == dsDoc)
            {
                MessageBox.Show("There are no open documents in DraftSight.");
                return;
            }
 
            //Get Sketch Manager
            Model dsModel;
            SketchManager dsSketchMgr;
            dsModel = dsDoc.GetModel();
            dsSketchMgr= dsModel.GetSketchManager();
 
            //Insert first Leader
            double[] Coordinates = new double[] { 0, 0, 0, 4, 4, 0, 10, 4, 0 };
            double Width = 5.0;
            string myNote = "DSUserData";
            Leader dsLeader;
            dsLeader = dsSketchMgr.InsertLeader(Coordinates, Width, myNote);
 
            //Insert second Leader
            double[] Coordinates2 = new double[] { 8, 8, 8, 8, 8, 8, 20, 8, 8 };
            string myNote2 = "DS";
            Leader dsLeader2;
            dsLeader2 = dsSketchMgr.InsertLeader(Coordinates2, Width, myNote2);
 
            //Get DimensionStyleUserData for DSUserData Leader
            DimensionStyleUserData dsDimStyleUserData;
            dsDimStyleUserData = dsLeader.GetDimensionStyleUserData();
 
            //Zoom to fit
            dsApp.Zoom(dsZoomRange_e.dsZoomRange_Fit, nullnull);
 
            //Examine the drawing
            //Press F10 to step through project
            System.Diagnostics.Debugger.Break();
 
            //Get DimensionStyleArrowsOptions for DSUserData Leader
            DimensionStyleArrowsOptions dsArrowsOptions;
            dsArrowsOptions = dsDimStyleUserData.GetDimensionStyleArrowsOptions();
 
            //Set arrow size for DSUserData Leader
            dsArrowsOptions.Size = 1.0;
 
            //set arrow type for DSUserData Leader
            dsArrowsOptions.SetLeaderArrow(dsDimensionArrowType_e.dsDimensionArrowType_Dot, "");
 
            //Get DimensionStyleTextOptions for DSUserData Leader
            DimensionStyleTextOptions dsTextOptions;
            dsTextOptions = dsDimStyleUserData.GetDimensionStyleTextOptions();
 
            //Set text vertical position for DSUserData Leader
            dsTextOptions.VerticalPositiondsDimensionTextVerticalPosition_e.dsDimensionTextVerticalPosition_Centered;
 
            //Insert third Leader
            double[] Coordinates3 = new double[] { 16, 16, 16, 16, 16, 16, 40, 16, 16 };
            string myNote3 = "DS2";
            Leader dsLeader3;
            dsLeader3 = dsSketchMgr.InsertLeader(Coordinates3, Width, myNote3);
 
            //Zoom to fit
            dsApp.Zoom(dsZoomRange_e.dsZoomRange_Fit, nullnull);
            
            //Examine the drawing to verify that DS and DS2 Leaders
            //have the same arrow and text options
 
        }
    }
}

 



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:   Change DimensionStyle Options of 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.