Hide Table of Contents

Insert Chain Dimensions Example (C#)

This example shows how to insert chain dimensions in a drawing.

//=========================================================================

// Preconditions:

// 1. Open install_dir\samples\tutorial\advdrawings\foodprocessor.slddrw.

// 2. Select the Sheet2 tab at the bottom.

// 3. Open the Immediate window.

//

// Postconditions:

// 1. Observe the chained dimensions in Drawing View3.

// 2. Inspect the display dimension values in the Immediate window.

//

// NOTE: Because the sample is used elsewhere, do not save changes.

//=========================================================================

 

using System;

using System.Diagnostics;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows;

using System.Windows.Forms;

 

using SolidWorks.Interop.sldworks;

using SolidWorks.Interop.swconst;

 

 

namespace InsertChainDimensions_CSharp

{

    public partial class SolidWorksMacro

    {

        public void Main()

        {

 

            ModelDocExtension modDocExt;

            ModelDoc2 Part;

            SelectionMgr selectMgr;

            object[] dimArray = new object[4];

            object dimObject;

            object[] entityArray = new object[4];

            object varArray;

            DisplayDimension myDisplayDim;

            Dimension swDim;

            string dimText;

            int k;

            bool boolstatus;

 

            Part = (ModelDoc2)swApp.ActiveDoc;

            selectMgr = (SelectionMgr)Part.SelectionManager;

            modDocExt = Part.Extension;

 

            Part.ClearSelection2(true);

            boolstatus = ((DrawingDoc)Part).ActivateView("Drawing View3");

            boolstatus = Part.Extension.SelectByRay(0.107406727925462, 0.259964392021715, 375.00575, 0, 0, -1, 0.00193314752083778, 1, false, 0, 0);

            entityArray[0] = selectMgr.GetSelectedObject6(1, -1);

 

            boolstatus = Part.Extension.SelectByRay(0.135835367937783, 0.281001585630832, 375.00575, 0, 0, -1, 0.00193314752083778, 1, false, 0, 0);

            entityArray[1] = selectMgr.GetSelectedObject6(2, -1);

 

            boolstatus = Part.Extension.SelectByRay(0.140383950339754, 0.25598438241999, 375.00575, 0, 0, -1, 0.00193314752083778, 1, false, 0, 0);

            entityArray[2] = selectMgr.GetSelectedObject6(3, -1);

 

            boolstatus = Part.Extension.SelectByRay(0.176772609555524, 0.221301441604959, 375.00275, 0, 0, -1, 0.00193314752083778, 1, false, 0, 0);

            entityArray[3] = selectMgr.GetSelectedObject6(4, -1);

 

            varArray = entityArray;

 

            dimObject = modDocExt.InsertChainDimensions(varArray);

 

            dimArray = (object[])dimObject;

 

            if (dimArray.Length > 0)

            {

                for (k = 0; k <= dimArray.GetUpperBound(0); k++)

                {

                    myDisplayDim = (DisplayDimension)dimArray[k];

                    swDim = myDisplayDim.GetDimension2(0);

                    dimText = swDim.Value.ToString();

                    Debug.Print(dimText);

                }

            }

        }

 

 

    // The SldWorks swApp variable is pre-assigned for you.

    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:   Insert Chain Dimensions 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.