MACRO LIBRARY

Print values of all sketch dimensions

Free public access. No account or subscription required.

Files

Print values of all sketch dimensions

Code

Module: mMain

'Demonstrates how to print the values of all dimensions in a sketch.
    
'Precondition: Part with a sketch named SKETCH_NAME is open.
'Result: See immediate window.
    
'Written by Keith Rice
'CADSharp LLC
'www.cadsharp.com
    
Const SKETCH_NAME As String = "Sketch1"
    
Sub main()
    Dim swApp As SldWorks.SldWorks
    Dim swModel As ModelDoc2
    Dim swPart As PartDoc
    Dim swFeat As Feature
    Dim swDispDim As DisplayDimension
    Dim swDim As Dimension
    Dim vDimVals As Variant
    
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    Set swPart = swModel
    Set swFeat = swPart.FeatureByName(SKETCH_NAME)
    Set swDispDim = swFeat.GetFirstDisplayDimension
    
    Do While Not swDispDim Is Nothing
        Set swDim = swDispDim.GetDimension2(Empty)
        vDimVals = swDim.GetValue3(swThisConfiguration, Empty)
        Debug.Print swDim.Name & "@" & SKETCH_NAME & ": " & Round(vDimVals(0), 6)
        Set swDispDim = swFeat.GetNextDisplayDimension(swDispDim)
    Loop
End Sub