Hide Table of Contents

Unlink Dimensions Example (VBA)

This example shows how to unlink dimensions in a part.




' Preconditions: Part is open.


' Postconditions: All links from all dimensions are removed.


' NOTE: This macro picks up all dimensions in the

'       part, including those that are not associated

'       with a feature.  These types of dimensions

'       usually appear under the Annotations feature.



Option Explicit

Public Enum swLinkDimensionError_e

    swLinkDimensionError_ErrorUknown = 0

    swLinkDimensionError_NoError = 1

    swLinkDimensionError_LinkAcrossDocs = 2

    swLinkDimensionError_IncompatibleDimTypes = 3

    swLinkDimensionError_AlreadyLinked = 4

    swLinkDimensionError_ReadOnlyOrDriven = 5

    swLinkDimensionError_IncompatibleValues = 6

    swLinkDimensionError_DrivenByEquation = 7

    swLinkDimensionError_CannotLink = 8

    swLinkDimensionError_UnableToCreateSharedParam = 9

    swLinkDimensionError_UnlinkFailure = 10

    swLinkDimensionError_EmptyString = 11

    swLinkDimensionError_InvalidString = 12

End Enum

Sub main()

    Dim swApp                   As SldWorks.SldWorks

    Dim swModel                 As SldWorks.ModelDoc2

    Dim swFeat                  As SldWorks.feature

    Dim swDimen                 As SldWorks.Dimension

    Dim swDispDim               As SldWorks.DisplayDimension

    Dim swDispDimAnn            As SldWorks.Annotation

    Dim nRetval                 As Long

    Dim bRet                    As Boolean


    Set swApp = Application.SldWorks

    Set swModel = swApp.ActiveDoc

    Set swFeat = swModel.FirstFeature


    Debug.Print "File = " & swModel.GetPathName


    Do While Not swFeat Is Nothing

        Set swDispDim = swFeat.GetFirstDisplayDimension

        If Not swDispDim Is Nothing Then

            Debug.Print "  " & swFeat.Name

        End If

        Do While Not swDispDim Is Nothing

            Set swDispDimAnn = swDispDim.GetAnnotation

            Set swDimen = swDispDim.GetDimension


            If swDispDim.IsLinked Then

                Debug.Print "    " & swDispDimAnn.GetName & " [" & swDimen.FullName & "] -- > " & swDispDim.GetLinkedText

                nRetval = swDispDim.Unlink: Debug.Assert swLinkDimensionError_NoError = nRetval

            End If


            Set swDispDim = swFeat.GetNextDisplayDimension(swDispDim)



        Set swFeat = swFeat.GetNextFeature


End Sub


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:   Unlink Dimensions Example (VBA)
*   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) 2010 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.