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)
Loop
Set
swFeat = swFeat.GetNextFeature
Loop
End Sub
'---------------------------------------------