Get Part's Feature Statistics Example (VBA)
This example shows how to get the statistics of all of the features
in a part document.
'-------------------------------------------
' Preconditions: Part document with features is
' open.
'
' Postconditions: None
'-------------------------------------------
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swFeatStat As SldWorks.FeatureStatistics
Dim swFeatMgr As
SldWorks.FeatureManager
Dim swModel As SldWorks.ModelDoc2
Dim featnames As Variant
Dim feattypes As Variant
Dim features As Variant
Dim featureUpdateTimes As Variant
Dim featureUpdatePercentTimes As Variant
Dim iter As Long
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swFeatMgr = swModel.FeatureManager
Set swFeatStat = swFeatMgr.FeatureStatistics
swFeatStat.Refresh
Debug.Print "Model name: "
& swFeatStat.PartName
Debug.Print " Number
of features: "
& swFeatStat.FeatureCount
Debug.Print " Number
of solid bodies: "
& swFeatStat.SolidBodiesCount
Debug.Print " Number
of surface bodies: " & swFeatStat.SurfaceBodiesCount
Debug.Print " Total
rebuild time: "
& swFeatStat.TotalRebuildTime
featnames = swFeatStat.FeatureNames
feattypes = swFeatStat.FeatureTypes
features = swFeatStat.features
featureUpdateTimes = swFeatStat.featureUpdateTimes
featureUpdatePercentTimes = swFeatStat.FeatureUpdatePercentageTimes
If Not (IsEmpty(featnames) Or IsNull(featnames)) Then
For
iter = 0 To UBound(featnames)
Debug.Print
" Feature
name: "
& featnames(iter)
Debug.Print
" Feature
type: "
& feattypes(iter)
Debug.Print
" Update
time: "
& featureUpdateTimes(iter)
Debug.Print
" Update
% time: "
& featureUpdatePercentTimes(iter)
Next
iter
End If
End Sub