This document contains VBA code to loop through all features and sub-features in a SolidWorks part document. It gets the name of each feature and sub-feature, concatenates them into a message string with newlines, and displays the message to the user. This continues looping until it reaches the last feature and sub-feature in the part.
This document contains VBA code to loop through all features and sub-features in a SolidWorks part document. It gets the name of each feature and sub-feature, concatenates them into a message string with newlines, and displays the message to the user. This continues looping until it reaches the last feature and sub-feature in the part.
This document contains VBA code to loop through all features and sub-features in a SolidWorks part document. It gets the name of each feature and sub-feature, concatenates them into a message string with newlines, and displays the message to the user. This continues looping until it reaches the last feature and sub-feature in the part.
Dim swPartDoc As SldWorks.ModelDoc2 Dim swFeature As SldWorks.feature Dim swSubFeature As SldWorks.feature Dim featureName As String Dim subFeatureName As String Dim message As String Sub main() Set swApp = Application.SldWorks Set swPartDoc = swApp.ActiveDoc ' Get the first feature in part Set swFeature = swPartDoc.FirstFeature ' While we have a valid feature While Not swFeature Is Nothing ' Get the name of the feature featureName = swFeature.Name message = "Feature: " & featureName & Chr(10) & " SubFeatures:" Set swSubFeature = swFeature.GetFirstSubFeature ' While we have a valid sub-feature While Not swSubFeature Is Nothing ' Get the name of the sub-feature subFeatureName = swSubFeature.Name message = message & Chr(10) & " " & subFeatureName Set swSubFeature = swSubFeature.GetNextSubFeature ' Continue until the last sub-feature is found Wend ' Display the sub-features swApp.SendMsgToUser message ' Get the next feature Set swFeature = swFeature.GetNextFeature() ' Continue until the last feature is found Wend End Sub