MACRO LIBRARY

Get or set dimension value in a part while in drawing or assembly

Free public access. No account or subscription required.

Files

Get or set dimension value in a part while in drawing or assembly

Code

'Demonstrates a way to get or set the value of a part's dimension while in an assembly or drawing.
    
'Preconditions: drawing or assembly is open and DIMENSION_NAME is set equal to the fully _
    qualified dimension name.
'Result: dimension value is printed to immediate window
    
'Written by Keith Rice
'CADSharp LLC
'www.cadsharp.com
    
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swDim As SldWorks.Dimension
Dim vVal As Variant
Const DIMENSION_NAME As String = "FirstSketch@Sketch1@testing_pin.Part"
    
Sub main()
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    Set swDim = swModel.Parameter(DIMENSION_NAME)
    vVal = swDim.GetSystemValue3(swThisConfiguration, Empty)
    Debug.Print "Current dimension value: " & vVal(0)
    'un-comment the following line if you wish to change the dimension value
    'swDim.SetSystemValue3 0.01, swThisConfiguration, Empty
End Sub